From 5985e0b7b190857942edb4a0ad3cefc24df3accd Mon Sep 17 00:00:00 2001 From: 0x3bb <0x3bb@3bb.io> Date: Sat, 27 Jul 2024 19:55:07 +0000 Subject: [PATCH] Update 2024-07-27-sys-write-string.md --- 2024-07-27-sys-write-string.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/2024-07-27-sys-write-string.md b/2024-07-27-sys-write-string.md index b73811b..3b62839 100644 --- a/2024-07-27-sys-write-string.md +++ b/2024-07-27-sys-write-string.md @@ -26,7 +26,7 @@ The syntax looks like this: `0xa` is just the ASCII hex representation of a new line. -```asm +``` ; sys_write_string.asm section .data s1 db "s1", 0x0a, 0; terminated string with NL @@ -38,7 +38,7 @@ Many standard libraries add the `NULL` terminator to initialized strings. This i Although, since `sys_write` does not expect a terminated string, this should be stripped. By taking the address of `s1` minus the terminated character (1 byte/8 bits). -```asm +``` s1Len equ $-s1-1; offset of s1 - terminator ``` @@ -46,7 +46,7 @@ s1Len equ $-s1-1; offset of s1 - terminator - `.bss` stands for _Block Started by Symbol_, and contains uninitialized variables that assign memory at runtime. For this example, it makes sense to define the value in the `.data` block above instead. -```asm +``` section .bss ``` @@ -57,7 +57,7 @@ The final section required is to define the entrypoint of the program - `.text` refers to the code segment: the program's virtual address space that contains executable instructions. - `main` is our program's entrypoint. -```asm +``` section .text global main ``` @@ -66,7 +66,7 @@ global main If the `global` keyword was omitted, then the linker (`ld`) will not see it, since `main` is scoped to the object file: -```asm +``` [0x3bb@heimat 2]$ make nasm -f elf64 -g -F dwarf sys_write_string.asm -l sys_write_string.lst sys_write_string.asm:9: warning: label alone on a line without a colon might be in error [-w+label-orphan] @@ -89,7 +89,7 @@ With the `global` directive set correctly, the [symbol type identifier](https:// ## label The `main` label serves as an alias to the block of instructions defined below -```asm +``` main: push rbp; push base address of stack frame to restore later mov rbp, rsp; copy address of current stack frame