flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Confused about generated code

Author
Thread Post new topic Reply to topic
Jerry



Joined: 24 Dec 2016
Posts: 18
Location: Zeist, Netherlands
Jerry 31 Dec 2016, 12:26
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 dlgproc, 8, 4, HWND, MSG, WPARAM, LPARAM, LOCAL1 .......
        ...
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: 512 Time(s)

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



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 31 Dec 2016, 12:54
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
Jerry 31 Dec 2016, 13:24
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
Jerry 31 Dec 2016, 13:51
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



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 31 Dec 2016, 15:01
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 arg, args
                      
        count = count + 1
                        
        if count > argcount    
you can simply use:
Code:
irp arg, args
                        
        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


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

Website powered by rwasa.