flat assembler
Message board for the users of flat assembler.
  
|  Index
      > Main > Global/local scope and functions | 
| Author | 
 | 
| revolution 02 Feb 2020, 16:24 Local variables are stored on the stack.     Code: my_function: sub esp,4 ;make space for one dword ;... mov dword[esp],my_value ;local variable stored on the stack ;... add esp,4 ;release the stack variable ret Code: my_function: sub esp,4 ;make space for one dword mov ebp,esp ;... mov dword[ebp],my_value ;local variable stored on the stack ;... add esp,4 ;release the stack variable ret | |||
|  02 Feb 2020, 16:24 | 
 | 
| rc 04 Feb 2020, 19:36 Thank you for the help.
 So i translated the above C code into fasm code and came up with the following: Code: format PE entry main include 'win32a.inc' section '.data' data readable writeable var1 dd 1 section '.text' code readable executable main: call func add eax, [var1] push eax call [ExitProcess] func: push ebp mov ebp, esp mov eax, 2 mov esp, ebp pop ebp ret section '.idata' import data readable writeable library kernel,'KERNEL32.DLL' import kernel,\ ExitProcess,'ExitProcess' Another question that i have is: how would i store floats in fasm? | |||
|  04 Feb 2020, 19:36 | 
 | 
| revolution 04 Feb 2020, 19:42 You can simplify func to this:     Code: func: mov eax,2 ret Code: mov eax,1.6180339887 mov rax,3.1415926535897932384 mov dword[edx],2.718281828459 | |||
|  04 Feb 2020, 19:42 | 
 | 
| rc 05 Feb 2020, 20:33 Ah ok, didn't know it was that simple. Thanks! | |||
|  05 Feb 2020, 20:33 | 
 | 
| < Last Thread | Next Thread > | 
| Forum Rules: 
 | 
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.