This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:exercisebook:pc:sut:scenarios_standalone [2026/05/20 15:38] – [Implementation of calculation functions] ktokarz | en:multiasm:exercisebook:pc:sut:scenarios_standalone [2026/05/20 15:57] (current) – [Implementation of calculation functions] ktokarz | ||
|---|---|---|---|
| Line 195: | Line 195: | ||
| Please note the order of arguments. It is assumed that they are placed onto the stack in reverse order. The last argument is placed on the stack first. That's why the 6th argument is at the higher address, next is the 5th argument and next there is a shadow space for arguments 1 - 4. From the perspective of a function, the first argument (or rather its shadow) is just after the return address. As the return address consumes 8 bytes, the shadow space for the first argument is at address SP+8. | Please note the order of arguments. It is assumed that they are placed onto the stack in reverse order. The last argument is placed on the stack first. That's why the 6th argument is at the higher address, next is the 5th argument and next there is a shadow space for arguments 1 - 4. From the perspective of a function, the first argument (or rather its shadow) is just after the return address. As the return address consumes 8 bytes, the shadow space for the first argument is at address SP+8. | ||
| - | How to call such a function? Putting parameters into registers is quite simple. To place arguments onto the stack, it is possible to use the **push** instruction. | + | How to call such a function? Putting |
| <code asm> | <code asm> | ||
| ;call sum of 6 integers function | ;call sum of 6 integers function | ||
| Line 203: | Line 203: | ||
| mov r8, 3 ; 3rd argmument | mov r8, 3 ; 3rd argmument | ||
| mov r9, 4 ; 4th argmument | mov r9, 4 ; 4th argmument | ||
| - | mov r10, 6 | + | mov r11, 6 |
| - | push r10 ; 6th argument | + | push r11 ; 6th argument |
| mov r10, 5 | mov r10, 5 | ||
| push r10 ; 5th argument | push r10 ; 5th argument | ||
| | | ||
| - | sub rsp, 20h ; shadow space | + | sub rsp, 20h ; |
| | | ||
| call sum_6_int ; function call | call sum_6_int ; function call | ||
| Line 215: | Line 215: | ||
| mov rcx, rax ; result in rax | mov rcx, rax ; result in rax | ||
| </ | </ | ||
| + | |||
| + | The figure {{ref> | ||
| + | <figure ex_stack_caller_push> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||