flat assembler
Message board for the users of flat assembler.

Index > Main > how implement local values ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 989
Roman
I know about proc
Code:

proc A1 p1:qword, p2:qword
ret
endp
    

And know in macro local.

But sometimes differents codes using the same name.
But how do this:
Code:
A dd 2
proc A
ret
loacal A dd 0
endp
proc B
ret
loacal A dd 0
endp
    
Post 11 Dec 2020, 16:56
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1422
Location: Toronto, Canada
AsmGuru62
local A:DWORD
Post 11 Dec 2020, 19:00
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 989
Roman
You mean it:
Code:
proc Az
        local A:DWORD
        mov eax,[A]
        ret
endp 
    
Post 11 Dec 2020, 20:13
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 989
Roman
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
    
Post 12 Dec 2020, 05:13
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 989
Roman
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
Post 12 Dec 2020, 05:16
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 989
Roman
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
Post 12 Dec 2020, 05:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17876
Location: In your JS exploiting you and your system
revolution
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.
Post 12 Dec 2020, 05:43
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 615
Location: Russian Federation, Sochi
ProMiNick
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.
Post 12 Dec 2020, 10:24
View user's profile Send private message Send e-mail Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3067
Location: vpcmipstrm
bitRAKE
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)/¯ unlicense.org
Post 13 Dec 2020, 09:52
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 615
Location: Russian Federation, Sochi
ProMiNick
"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.
Post 13 Dec 2020, 11:11
View user's profile Send private message Send e-mail Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3067
Location: vpcmipstrm
bitRAKE
fasm hides local variable names. Rolling Eyes
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)/¯ unlicense.org
Post 13 Dec 2020, 13:04
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1564
Furs
ProMiNick wrote:
"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.
Pretty much this. And they have the same pitfalls as global variables: thread unsafety.
Post 13 Dec 2020, 15:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.