From 37243a782b0fe4828e7b2480ea600b126d9c512a Mon Sep 17 00:00:00 2001 From: Malfurious Date: Sun, 15 Jan 2023 01:07:25 -0500 Subject: Remove unnecessary stack allocations Subtracting esp to allocate space on the stack is only necessary to preserve data that is already lower on the stack. By the time we use either the sockaddr struct or the temporary io buffer, we are finished accessing older stack values, so they can be overwritten. This saves 2 unnecessary instructions from the program. Signed-off-by: Malfurious --- lace_x86.asm | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lace_x86.asm b/lace_x86.asm index 687b8e0..12fc1b0 100644 --- a/lace_x86.asm +++ b/lace_x86.asm @@ -80,8 +80,6 @@ _start: mov bl, 1 jl exit - sub esp, 16 ; alloc struct sockaddr_in - mov dl, 16 ; read(argv[1], sockaddr, sizeof(sockaddr)) mov ecx, esp mov ebx, eax @@ -113,10 +111,8 @@ _start: mov bl, 3 jne exit - pop edi ; recover socket fd - sub esp, 0xff ; alloc data buffer - xor esi, esi ; pipe(sock_fd, stdin) + pop edi call pipe inc esi ; pipe(stdout, sock_fd) -- cgit v1.2.3