wswan:guide:c_assembly
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| wswan:guide:c_assembly [2024/02/17 10:55] – created asie | wswan:guide:c_assembly [2025/08/15 14:43] (current) – [Useful macros] asie | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Writing assembly ====== | ====== Writing assembly ====== | ||
| - | For writing entire functions in ASM, as well as more complex projects, it can be preferable to write external | + | In the Wonderful toolchain, assembly files use the '' |
| - | In the Wonderful toolchain, these files use the '' | + | ===== Creating an assembly file ===== |
| It is recommended to start with a preamble similar to the following: | It is recommended to start with a preamble similar to the following: | ||
| Line 17: | Line 17: | ||
| - Include the Wonderful toolchain' | - Include the Wonderful toolchain' | ||
| - | - Include the libws library' | + | - Include the libws library' |
| - Tell the assembler to emit 16-bit code; this is useful as the GNU assembler supports all kinds of x86 code, including 32-bit and 64-bit. | - Tell the assembler to emit 16-bit code; this is useful as the GNU assembler supports all kinds of x86 code, including 32-bit and 64-bit. | ||
| - | - Tell the assembler to emit 80186 code; this unlocks some additional 80186-exclusive opcodes supported on the NEC V30MZ | + | - Tell the assembler to emit 80186 code; this unlocks some additional 80186-exclusive opcodes supported on the NEC V30MZ. |
| - | - Tell the assembler to emit Intel-syntax assembly; this is entirely optional, but the examples for external assembly files in this guide all make use of the Intel syntax, as opposed to the AT&T syntax used in inline assembly. | + | - Tell the assembler to emit Intel-syntax assembly; this is entirely optional, but the examples for external assembly files in this guide all make use of the Intel syntax, as opposed to the default |
| + | Note that to export a symbol (make it visible outside of the specific file, or translation unit), you need to use '' | ||
| + | |||
| + | <code C> | ||
| + | .global strlen | ||
| + | strlen: | ||
| + | </ | ||
| + | |||
| + | ===== Useful macros ===== | ||
| + | |||
| + | '' | ||
| + | |||
| + | * **IA16_CALL** - for portability between code models, you can use this macro in place of the '' | ||
| + | * **IA16_JMP** - for portability between code models, you can use this macro in place of the '' | ||
| + | * **IA16_RET** - for portability between code models, you can use this macro in place of the '' | ||
| + | * **IA16_CALL_STACK_OFFSET(x)** - for portability between code models, you can use this macro to get a stack offset with the function return address accounted for. For exapmle, in a " | ||
wswan/guide/c_assembly.1708167324.txt.gz · Last modified: by asie
