From 6030d7e2e56d445ca67c6a0e8c9cf33e46bc673c Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 30 Nov 2018 10:54:42 -0800 Subject: 4801 Reindent all SubX code to make some room for the new comment style. --- subx/examples/ex10.subx | 74 ++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'subx/examples/ex10.subx') diff --git a/subx/examples/ex10.subx b/subx/examples/ex10.subx index b179369f..4da713ae 100644 --- a/subx/examples/ex10.subx +++ b/subx/examples/ex10.subx @@ -8,9 +8,9 @@ # 0 # false == code -# instruction effective address operand displacement immediate -# op subop mod rm32 base index scale r32 -# 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 +# instruction effective address operand displacement immediate +# op subop mod rm32 base index scale r32 +# 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 # main: return argv-equal(argv[1], argv[2]) # At the start of a SubX program: @@ -18,55 +18,55 @@ # argv[0]: *(ESP+4) # argv[1]: *(ESP+8) # ... - # prolog - 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # call argv-equal(argv[1], argv[2]) + # prolog + 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP + # call argv-equal(argv[1], argv[2]) # push argv[2] - ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0xc/disp8 . # push *(EBP+12) + ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0xc/disp8 . # push *(EBP+12) # push argv[1] - ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0x8/disp8 . # push *(EBP+8) + ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0x8/disp8 . # push *(EBP+8) # call - e8/call argv-equal/disp32 - # exit(EAX) + e8/call argv-equal/disp32 + # exit(EAX) $exit: - 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # copy EAX to EBX - b8/copy-to-EAX 1/imm32 - cd/syscall 0x80/imm8 + 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # copy EAX to EBX + b8/copy-to-EAX 1/imm32 + cd/syscall 0x80/imm8 # compare two null-terminated ascii strings # reason for the name: the only place we should have null-terminated ascii strings is from commandline args argv-equal: # (s1, s2) : null-terminated ascii strings -> EAX : boolean - # initialize s1 (ECX) and s2 (EDX) - 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none . 1/r32/ECX 4/disp8 . # copy *(ESP+4) to ECX - 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none . 2/r32/EDX 8/disp8 . # copy *(ESP+8) to EDX - # while (true) + # initialize s1 (ECX) and s2 (EDX) + 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none . 1/r32/ECX 4/disp8 . # copy *(ESP+4) to ECX + 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none . 2/r32/EDX 8/disp8 . # copy *(ESP+8) to EDX + # while (true) $argv-equal:loop: # c1/EAX, c2/EBX = *s1, *s2 - b8/copy-to-EAX 0/imm32 - 8a/copy 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . . # copy byte at *ECX to lower byte of EAX - bb/copy-to-EBX 0/imm32 - 8a/copy 0/mod/indirect 2/rm32/EDX . . . 3/r32/EBX . . # copy byte at *EDX to lower byte of EBX + b8/copy-to-EAX 0/imm32 + 8a/copy 0/mod/indirect 1/rm32/ECX . . . 0/r32/EAX . . # copy byte at *ECX to lower byte of EAX + bb/copy-to-EBX 0/imm32 + 8a/copy 0/mod/indirect 2/rm32/EDX . . . 3/r32/EBX . . # copy byte at *EDX to lower byte of EBX # if (c1 == 0) break - 3d/compare-EAX 0/imm32 - 74/jump-if-equal $argv-equal:break/disp8 + 3d/compare-EAX 0/imm32 + 74/jump-if-equal $argv-equal:break/disp8 # if (c1 != c2) return false - 39/compare 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . . # compare EAX with EBX - 75/jump-if-not-equal $argv-equal:false/disp8 + 39/compare 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . . # compare EAX with EBX + 75/jump-if-not-equal $argv-equal:false/disp8 # ++s1, ++s2 - 41/inc-ECX - 42/inc-EDX - # end while - eb/jump $argv-equal:loop/disp8 + 41/inc-ECX + 42/inc-EDX + # end while + eb/jump $argv-equal:loop/disp8 $argv-equal:break: - # if (c2 == 0) return true - 81 7/subop/compare 3/mod/direct 3/rm32/EBX . . . . . 0/imm32 # compare EBX - 75/jump-if-not-equal $argv-equal:false/disp8 + # if (c2 == 0) return true + 81 7/subop/compare 3/mod/direct 3/rm32/EBX . . . . . 0/imm32 # compare EBX + 75/jump-if-not-equal $argv-equal:false/disp8 $argv-equal:success: - b8/copy-to-EAX 1/imm32 - c3/return - # return false + b8/copy-to-EAX 1/imm32 + c3/return + # return false $argv-equal:false: - b8/copy-to-EAX 0/imm32 - c3/return + b8/copy-to-EAX 0/imm32 + c3/return # vim:nowrap:textwidth=0 -- cgit 1.4.1-2-gfad0