flat assembler
Message board for the users of flat assembler.
Index
> Main > how implement local values ? |
Author |
|
AsmGuru62 11 Dec 2020, 19:00
local A:DWORD
|
|||
11 Dec 2020, 19:00 |
|
Roman 11 Dec 2020, 20:13
You mean it:
Code: proc Az local A:DWORD mov eax,[A] ret endp |
|||
11 Dec 2020, 20:13 |
|
Roman 12 Dec 2020, 05:13
i look in IDA PRO and not see big difference.
Code: proc Az A:DWORD mov eax,[A] ret endp var_10 = dword ptr -10h ;IDA Pro code proc Az push rbp mov rbp, rsp sub rsp, 10h mov eax, [rbp+var_10] leave retn proc Az1 local A:DWORD mov eax,[A] ret endp arg_0 = dword ptr 10h ;IDA Pro code proc Az1 push rbp mov rbp, rsp mov eax, [rbp+arg_0] leave retn |
|||
12 Dec 2020, 05:13 |
|
Roman 12 Dec 2020, 05:16
When i say local A:DWORD in proc.
I mean value not from stak ! I mean this: Code: proc Az1 local A:DWORD mov eax,A ret endp I want get this code: proc Az1 local A:DWORD mov [A],122 mov eax,A ret local A dd 0 ;put hear 122. Its might be struct or big data 128 bytes endp Because i want use from eax address A(proc Az1) in all my code program ! If we using rsp we lost local A address, its not good |
|||
12 Dec 2020, 05:16 |
|
Roman 12 Dec 2020, 05:27
Work code like i want.
Code: proc Az mov eax,[.Az] ret .Az dd 0 endp Last edited by Roman on 13 Dec 2020, 12:36; edited 1 time in total |
|||
12 Dec 2020, 05:27 |
|
revolution 12 Dec 2020, 05:43
If you want data mixed with your code then don't use local. Local is for stack variables.
But the AVs will likely flag it and complain, because writing to a code section is apparently something only malware does to make mutated code. |
|||
12 Dec 2020, 05:43 |
|
ProMiNick 12 Dec 2020, 10:24
It is bad practice to mix code & data for windows,linux, mac on x86.
less serios OS like Menuet, looks normal on such mixes. On ARM architecture programmer limited to encode in instruction imm data with 2 bytes in size, so absolute adresing from eip there limited with $FFF bytes range, so there two types of locals: one eip related(+/-$FFF), one stack related. 1. So to code not for x86. 2. To code not for big OSes (windows,linux, mac). 3. Or don`t use code data mixing. The choise is thours. |
|||
12 Dec 2020, 10:24 |
|
bitRAKE 13 Dec 2020, 09:52
Non-stack variables are called "static" variables in C/C++. They have an initial state and keep state through successive function calls. Whereas stack variables require initialization every time function is called and state is lost on function return. Both have their uses.
[x86 specific:] In terms of performance, the stack memory is likely in the cache. Static variables can benefit from data locality - where function variables coalesce into minimal cachelines. In terms of size, stack variables can be initialized and allocated in one operation (i.e. PUSH 0). It's smaller to access stack variables through RBP than using RSP - impactful if there are many stack variables. Stack variables are typically costly in terms of instruction bytes unless a common base register is used. Yeah, writing to code sections is just Bad™ in the modern climate of software fear. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
13 Dec 2020, 09:52 |
|
ProMiNick 13 Dec 2020, 11:11
"static" variables is a mith like private members of class.
In assembly there is no unaccessible things. Honestly, "static" variables is global variables. But C/C++ liked to cheating programmers and hide this vars from programmer, but they remain global vars. |
|||
13 Dec 2020, 11:11 |
|
bitRAKE 13 Dec 2020, 13:04
fasm hides local variable names.
Of course, you could argue one is build-time and the other is runtime. But, abstractions have their utility. One shouldn't feel cheated - babied/coddled or protected from themselves, lol. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
13 Dec 2020, 13:04 |
|
Furs 13 Dec 2020, 15:30
ProMiNick wrote: "static" variables is a mith like private members of class. |
|||
13 Dec 2020, 15:30 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.