flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
MazeGen 31 Jul 2006, 07:39
Hi Chewy, this is how GoAsm works in win64. I'm implementing the same in MASM and I haven't found any better way.
(the numbers in the left column mean the order of instruction execution) Code: Stack layouts for even and odd number of stack parameters: A. Total 6 integer parameters -> 2 stack parameters (uses AND method): a) a layout for inital 8-byte alignment (e.g., RSP = 88dec) | xyz | 88 1. PUSH RSP | 88 | 80 2. PUSH [RSP] | 88 | 72 (used by POP RSP) 3. AND RSP, NOT (16t-1) | hole | 64 5. MOV [RSP + 2*8 + 4*8], arg6 | arg6 | 56 6. MOV [RSP + 1*8 + 4*8], arg5 | arg5 | 48 | R9 home | | R8 home | | RDX home | 4. SUB RSP, 4*8 + 2*8 | RCX home | 16 7. CALL func | RETURN LINK | (8 at the entry of the function) 8. ADD RSP, 4*8 + 2*8 + 8 | 88 | 72 9. POP RSP | xyz | 88 b) a layout for inital 16-byte alignment (e.g., RSP = 80dec) | xyz | 80 1. PUSH RSP | 80 | 72 (used by POP RSP) 2. PUSH [RSP] | 80 | 64 3. AND RSP, NOT (16t-1) - no change - 64 5. MOV [RSP + 2*8 + 4*8], arg6 | arg6 | 56 6. MOV [RSP + 1*8 + 4*8], arg5 | arg5 | 48 | R9 home | | R8 home | | RDX home | 4. SUB RSP, 4*8 + 2*8 | RCX home | 16 7. CALL func | RETURN LINK | (8 at the entry of the function) 8. ADD RSP, 4*8 + 2*8 + 8 | 80 | 72 9. POP RSP | xyz | 80 B. Total 7 integer parameters -> 3 stack parameters (uses OR method): a) a layout for inital 8-byte alignment (e.g., RSP = 88dec) | xyz | 88 1. PUSH RSP | 88 | 80 2. PUSH [RSP] | 88 | 72 (used by POP RSP) 3. OR RSP, 16t/2 - no change - 72 5. MOV [RSP + 3*8 + 4*8], arg7 | arg7 | 64 6. MOV [RSP + 2*8 + 4*8], arg6 | arg6 | 56 7. MOV [RSP + 1*8 + 4*8], arg5 | arg5 | 48 | R9 home | | R8 home | | RDX home | 4. SUB RSP, 4*8 + 3*8 | RCX home | 16 8. CALL func | RETURN LINK | (8 at the entry of the function) 9. ADD RSP, 4*8 + 3*8 | 88 | 72 10. POP RSP | xyz | 88 b) a layout for inital 16-byte alignment (e.g., RSP = 80dec) | xyz | 80 1. PUSH RSP | 80 | 72 (used by POP RSP) 2. PUSH [RSP] | 80 | 64 3. OR RSP, 16t/2 - removes prev one - 72 5. MOV [RSP + 3*8 + 4*8], arg7 | arg6 | 64 6. MOV [RSP + 2*8 + 4*8], arg6 | arg6 | 56 7. MOV [RSP + 1*8 + 4*8], arg5 | arg5 | 48 | R9 home | | R8 home | | RDX home | 4. SUB RSP, 4*8 + 3*8 | RCX home | 16 8. CALL func | RETURN LINK | (8 at the entry of the function) 9. ADD RSP, 4*8 + 3*8 | 80 | 72 10. POP RSP | xyz | 80 |
|||
![]() |
|
Chewy509 01 Aug 2006, 02:44
Thanks. Still wondering why MS came up with such a monsterousity...
|
|||
![]() |
|
MazeGen 01 Aug 2006, 12:04
Me too. There was interesting discussion about it:
http://board.flatassembler.net/topic.php?t=4155#30448 |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.