flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > Confused about generated code

Author
Thread Post new topic Reply to topic
Jerry



Joined: 24 Dec 2016
Posts: 18
Location: Zeist, Netherlands

Confused about generated code

Hello,

I've encountered something i do not understand in fasmg (hll54).
What i am attempting is to write a proc macro that takes some parameters.
An example would be


Code:

proc dlgproc84HWNDMSGWPARAMLPARAMLOCAL1 .......
        ...
end proc



One can then access them by [HWND] or [LOCAL1] etc.

The first parameter is how many qwords to reserve for the stack unconditionally (room for api calls).
The second is the amount of actual arguments (a dlgproc has 4), and also allocate stack for that to back them up
for more than 4 arguments one needs to look beyond the returnaddress of the caller and it's shadow space and find the other ( > 4) arguments stored right to left (that part is't working yet but doesn't matter for this question)
Any additional argument names after the formal ones will be made local variables.

Attached is procdemo.zip that consist of procdemo.asm and procdemo.png (a screenshot from x64dbg that shows the generated code)

The line 'mov rax,qword ptr ss:[ ... ]' is repeated 4 times, the following
'mov qword ptr ss:[rsp+60], rax' only once (which is correct and even the correct offset)
But they are generated within the same 'if', that's the part i don't understand, what am i missing ?

Thanks in advance


Description: Example code
Download
Filename: procdemo.zip
Filesize: 71.42 KB
Downloaded: 49 Time(s)

Post 31 Dec 2016, 12:26
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6685
Location: Kraków, Poland

The MOV instructions you refer to are generated by this fragment of source:

Code:
        mov rax, [HWND]
        mov rax, [MSG]
        mov rax, [WPARAM]
        mov rax, [LPARAM]
        mov [LOCAL1], rax  

while the IF block you mention is not processed at all. This is because the "count > argcount" condition is fulfilled and causes a BREAK.
Post 31 Dec 2016, 12:54
View user's profile Send private message Visit poster's website Reply with quote
Jerry



Joined: 24 Dec 2016
Posts: 18
Location: Zeist, Netherlands

Thanks,

I still have a lot to learn (then again, who doesn't).
Will be reading the documentation again.

Regards
Post 31 Dec 2016, 13:24
View user's profile Send private message Reply with quote
Jerry



Joined: 24 Dec 2016
Posts: 18
Location: Zeist, Netherlands

Looked again ....

It actually works, i was looking for the (my) handling of any (not local)) parameter beyond 4.
The example proc usage i sent was 4 parameters and 1 local so there was no 5 parameters whatsoever to begin with.
Second post, second time overlooking something ...

Sorry for taking up unnecessary time.
Post 31 Dec 2016, 13:51
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6685
Location: Kraków, Poland

By the way, IRP/ITERATE allows to use % and %% parameters to access the number of current iteration and total count, so instead of:

Code:
irp argargs
                      
        count = count + 1
                        
        if count > argcount

you can simply use:

Code:
irp argargs
                        
        if % > argcount

Post 31 Dec 2016, 15:01
View user's profile Send private message Visit poster's website 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2017, Tomasz Grysztar.