flat assembler
Message board for the users of flat assembler.
Index
> Windows > enter and leave |
Author |
|
Tyler 11 Oct 2010, 01:40
Code: locals p dd 2 i dd 0 List dd 0 ;pointer to dynamicly allocated memroy endl ; ... endp == Code: push ebp mov ebp,esp sub esp,12 ; 12 bytes b/c each of the three dds are 4 bytes ; FYI, label is built in directive, not macro. label upto dword at ebp + 4 ; Makes any reference to upto the same thing as ebp + 4, ie upto == ebp + 4 label p dword at ebp - 4 label i dword at ebp - 8 label List dword at ebp - 12 ; ... ret 12 ; Free stack space allocated above |
|||
11 Oct 2010, 01:40 |
|
revolution 11 Oct 2010, 04:47
And remember the initialisation values also:
Code: ;... mov [p],2 mov [i],0 mov [List],0 ;... |
|||
11 Oct 2010, 04:47 |
|
baldr 11 Oct 2010, 06:01
ishkabible,
When most of your locals are initialized, you may use push initial_value for them instead of sub esp, X / mov [local_var], initial_value (uninitialized locals can be skipped with sub esp or push). add esp, 4 removes argument for malloc() from stack: malloc() uses cdecl calling conventions; same for printf(), free() and system() (after which you've forgot to do it). |
|||
11 Oct 2010, 06:01 |
|
ishkabible 11 Oct 2010, 17:28
@Tyler, thanks that will get me started
@baldr, thank you for helping but that was a comment that was explained earlier in another thread, i should have revomved after i understood why it was there |
|||
11 Oct 2010, 17:28 |
|
Tyler 11 Oct 2010, 23:07
vid's example of using Fasm with MSVC has a good example of a procs and their hand written alternatives.
Code: ;----------------------------------------------------------------------------- ; declare "fasm_ccall_avg" using pure assembly ; this computes average value of two unsigned numbers fasm_ccall_avg: ;same as fasm_stdcall_avg push ebp mov ebp, esp label .num1 dword at ebp+8 ;num1 argument is now located at ebp+8 label .num2 dword at ebp+12 ;num2 argument is now is located at ebp+12 sub esp, 2*4 label .loc1 dword at ebp-4 label .loc2 dword at ebp-8 push ebx esi edi mov eax, [.num1] add eax, [.num2] rcr eax, 1 pop edi esi ebx mov esp, ebp pop ebp ;this is only difference. In ccall, we leave arguments on stack retn 0 ;----------------------------------------------------------------------------- ; declare "fasm_ccall_avg2" using FASM macros ; this is same as "fasm_ccall_avg", just done with macros proc fasm_ccall_avg2 c num1, num2 ;note the "c" declaration modifier local loc1 dd ? local loc2 dd ? mov eax, [num1] add eax, [num2] rcr eax, 1 ret endp |
|||
11 Oct 2010, 23:07 |
|
bitRAKE 12 Oct 2010, 20:03
ENTER is one of those instructions that does more than anyone really needs. Not only does it setup the frame, but it also copies data into the new frame. LEAVE on the other hand is a single byte, and usually does exactly what is needed to clean-up the frame. Volume 1, Chapter 6, of the Intel manuals explains the details.
|
|||
12 Oct 2010, 20:03 |
|
Kenneth Zheng 13 Oct 2010, 06:42
Enter instuction is one very slowly instruction. So most of complier don't use it to create stack frame. They used below instrctions to do it:
Code: 1. 16Bit Code: push bp mov bp, sp sub bp, xxx 1. 32Bit Code: push ebp mov ebp, esp sub ebp, xxx 1. 64Bit Code: (fastcall) push rbp mov rbp, rsp sub rsp, xxx Kenneth Zheng October 13th, 2010 _________________ Pure Assembly Language Funs |
|||
13 Oct 2010, 06:42 |
|
baldr 13 Oct 2010, 07:06
bitRAKE,
enter looks bizarre only for those who isn't familiar with block-structured languages. Nested procedure can access arguments/locals of all outer procedures, how you'll implement this without display (which enter creates)? |
|||
13 Oct 2010, 07:06 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.