1 # Print out a (global variable) string to stdout. 2 # 3 # To run (from the subx directory): 4 # $ ./subx translate examples/ex6.subx -o examples/ex6 5 # $ ./subx run examples/ex6 6 # Hello, world! 7 8 == code 0x09000000 9 # instruction effective address register displacement immediate 10 # . op subop mod rm32 base index scale r32 11 # . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes 12 13 Entry: 14 # syscall(write, stdout, X, Size) 15 # . fd = 1 (stdout) 16 bb/copy-to-EBX 1/imm32 17 # . initialize X (location to write result to) 18 b9/copy-to-ECX X/imm32 19 # . initialize Size 20 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 2/r32/EDX Size/disp32 . # copy *Size to EDX 21 # . syscall 22 b8/copy-to-EAX 4/imm32/write 23 cd/syscall 0x80/imm8 24 25 # syscall(exit, EBX) 26 b8/copy-to-EAX 1/imm32/exit 27 cd/syscall 0x80/imm8 28 29 == data 0x0a000000 30 31 Size: # size of string 32 0x0e/imm32 # 14 33 X: # string to print 34 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 0a 00 35 # H e l l o , ␣ w o r l d ! newline null 36 37 # . . vim:nowrap:textwidth=0