Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:multiasm:papc:chapter_6_8 [2026/02/13 13:33] – [Procedures, Functions and Calls in Windows and Linux] ktokarzen:multiasm:papc:chapter_6_8 [2026/02/27 01:48] (current) – [Callig Windows system functions] jtokarz
Line 14: Line 14:
 Procedures can have parameters. In general, parameters can be passed through the stack, registers, common memory or a combination of these. In different operating systems, the rules of passing parameters differ.  Procedures can have parameters. In general, parameters can be passed through the stack, registers, common memory or a combination of these. In different operating systems, the rules of passing parameters differ. 
  
-**Windows Application Binary Interface**+**Windows Application Binary Interface.**\\
 In 64-bit Windows, the fast call calling convention is used. In this convention, the first four parameters are passed through registers, and each subsequent parameter is passed through the stack. If the parameters are integers, they are passed through general-purpose registers. If parameters are floating-point numbers, they are passed through XMM registers as scalars. If the procedure plays the role of a function, it returns the resulting value. Integers are returned through the accumulator (RAX), and floating-point values are returned through XMM0. Parameters passing in Windows x64 ABI is summarised in a table {{ref>masmparampass}}. In 64-bit Windows, the fast call calling convention is used. In this convention, the first four parameters are passed through registers, and each subsequent parameter is passed through the stack. If the parameters are integers, they are passed through general-purpose registers. If parameters are floating-point numbers, they are passed through XMM registers as scalars. If the procedure plays the role of a function, it returns the resulting value. Integers are returned through the accumulator (RAX), and floating-point values are returned through XMM0. Parameters passing in Windows x64 ABI is summarised in a table {{ref>masmparampass}}.
 <table masmparampass> <table masmparampass>
Line 65: Line 65:
 Certainly, these rules are to be used if there is a need to call a system function or to maintain compatibility with a high-level compiler. If the procedure is written in pure assembly and called from an assembly program, it is the programmer's decision whether they want to follow these rules.\\ Certainly, these rules are to be used if there is a need to call a system function or to maintain compatibility with a high-level compiler. If the procedure is written in pure assembly and called from an assembly program, it is the programmer's decision whether they want to follow these rules.\\
 The rules of passing parameters, stack and registers use, and data storage layout in 64-bit Microsoft Windows are described in the document about x64 Application Binary Interface (ABI)((https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions?view=msvc-170)).\\ The rules of passing parameters, stack and registers use, and data storage layout in 64-bit Microsoft Windows are described in the document about x64 Application Binary Interface (ABI)((https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions?view=msvc-170)).\\
-**Linux System V Application Binary Interface**+**Linux System V Application Binary Interface.**\\
 In the Linux x64 Calling Convention, the first six arguments of type integer/pointers are passed in registers and subsequent arguments through the stack. For the floating point arguments, the first eight are passed in XMM registers, and the subsequent ones through the stack. Parameters passing in Linux is summarised in a table {{ref>linuxparampass}}. In the Linux x64 Calling Convention, the first six arguments of type integer/pointers are passed in registers and subsequent arguments through the stack. For the floating point arguments, the first eight are passed in XMM registers, and the subsequent ones through the stack. Parameters passing in Linux is summarised in a table {{ref>linuxparampass}}.
 <table linuxparampass> <table linuxparampass>
Line 80: Line 80:
 | subsequent | stack | stack |  | subsequent | stack | stack | 
 </table> </table>
 +The non-volatile registers are RBX, RBP, R12, R13, R14, and R15. They should be saved and restored by a function that uses them.
  
 ===== Calling the system functions ===== ===== Calling the system functions =====
Line 116: Line 117:
     push  rbp        ; push rpb to the stack     push  rbp        ; push rpb to the stack
     mov   rbp, rsp   ; store rsp to rbp     mov   rbp, rsp   ; store rsp to rbp
-    sub   rsp, 48    ; shadow space (32 bytes) and stack alignment (additional 8 bytes)+    sub   rsp, 48    ; shadow space (32 bytes) and stack alignment (additional  
 +                     ; 8 bytes)
  
 ; we need the handle of the console window ; we need the handle of the console window
en/multiasm/papc/chapter_6_8.1770982415.txt.gz · Last modified: by ktokarz
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0