From ee9a9237d6324f1de1bb7150083eacf7b9af5f70 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 30 Nov 2018 11:10:44 -0800 Subject: 4802 Some automated commenting cleanup. Still needs more careful manual scanning. sed -i 's/^# 1-3/# . 1-3/' *.subx */*.subx sed -i 's/^# op/# . op/' *.subx */*.subx sed -i 's/# vim/# . . vim/' *.subx */*.subx sed -i 's/^ # push args/ # . . push args/' *.subx */*.subx sed -i 's/^ # discard args/ # . . discard args/' *.subx */*.subx sed -i 's/^ # call/ # . . call/' *.subx */*.subx sed -i 's/^ # prolog/ # . prolog/' *.subx */*.subx sed -i 's/^ # epilog/ # . epilog/' *.subx */*.subx sed -i 's/^ # save registers/ # . save registers/' *.subx */*.subx sed -i 's/^ # restore registers/ # . restore registers/' *.subx */*.subx sed -i 's/ operand / register /' *.subx */*.subx --- subx/examples/ex1.subx | 2 +- subx/examples/ex10.subx | 14 ++--- subx/examples/ex11.subx | 142 ++++++++++++++++++++++++------------------------ subx/examples/ex12.subx | 8 +-- subx/examples/ex2.subx | 2 +- subx/examples/ex3.subx | 8 +-- subx/examples/ex4.subx | 2 +- subx/examples/ex5.subx | 8 +-- subx/examples/ex6.subx | 8 +-- subx/examples/ex7.subx | 8 +-- subx/examples/ex8.subx | 18 +++--- subx/examples/ex9.subx | 16 +++--- 12 files changed, 118 insertions(+), 118 deletions(-) (limited to 'subx/examples') diff --git a/subx/examples/ex1.subx b/subx/examples/ex1.subx index 8bef59e7..3371cd75 100644 --- a/subx/examples/ex1.subx +++ b/subx/examples/ex1.subx @@ -15,4 +15,4 @@ bb/copy-to-EBX 2a/imm32 # 42 in hex b8/copy-to-EAX 1/imm32/exit cd/syscall 0x80/imm8 -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex10.subx b/subx/examples/ex10.subx index 4da713ae..936edb08 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 register 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,14 +18,14 @@ # argv[0]: *(ESP+4) # argv[1]: *(ESP+8) # ... - # prolog + # . prolog 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # call argv-equal(argv[1], argv[2]) + # . . 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) # push argv[1] ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0x8/disp8 . # push *(EBP+8) - # call + # . . call e8/call argv-equal/disp32 # exit(EAX) $exit: @@ -69,4 +69,4 @@ $argv-equal:false: b8/copy-to-EAX 0/imm32 c3/return -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex11.subx b/subx/examples/ex11.subx index 247a0076..253b91ab 100644 --- a/subx/examples/ex11.subx +++ b/subx/examples/ex11.subx @@ -15,9 +15,9 @@ # would cause tests to not run, rather than to fail as we'd like.) == 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 register 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: e8/call run-tests/disp32 # 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'. @@ -29,10 +29,10 @@ # compare a null-terminated ascii string with a more idiomatic length-prefixed byte array # reason for the name: the only place we should have null-terminated ascii strings is from commandline args kernel-string-equal: # s : null-terminated ascii string, benchmark : length-prefixed ascii string -> EAX : boolean - # prolog + # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # save registers + # . save registers 51/push-ECX 52/push-EDX 53/push-EBX @@ -97,7 +97,7 @@ $kernel-string-equal:false: b8/copy-to-EAX 0/imm32 $kernel-string-equal:end: - # restore registers + # . restore registers 5f/pop-to-EDI 5e/pop-to-ESI 5b/pop-to-EBX @@ -112,141 +112,141 @@ $kernel-string-equal:end: test-compare-null-kernel-string-with-empty-array: # EAX = kernel-string-equal(Null-kernel-string, "") - # push args + # . . push args 68/push ""/imm32 68/push Null-kernel-string/imm32 - # call + # . . call e8/call kernel-string-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # call check-ints-equal(EAX, 1, msg) - # push args + # . . call check-ints-equal(EAX, 1, msg) + # . . push args 68/push "F - test-compare-null-kernel-string-with-empty-array"/imm32 68/push 1/imm32/true 50/push-EAX - # call + # . . call e8/call check-ints-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP c3/return test-compare-null-kernel-string-with-non-empty-array: # EAX = kernel-string-equal(Null-kernel-string, "Abc") - # push args + # . . push args 68/push "Abc"/imm32 68/push Null-kernel-string/imm32 - # call + # . . call e8/call kernel-string-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # call check-ints-equal(EAX, 0, msg) - # push args + # . . call check-ints-equal(EAX, 0, msg) + # . . push args 68/push "F - test-compare-null-kernel-string-with-non-empty-array"/imm32 68/push 0/imm32/false 50/push-EAX - # call + # . . call e8/call check-ints-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP c3/return test-compare-kernel-string-with-equal-array: # EAX = kernel-string-equal(Abc-kernel-string, "Abc") - # push args + # . . push args 68/push "Abc"/imm32 68/push Abc-kernel-string/imm32 - # call + # . . call e8/call kernel-string-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # call check-ints-equal(EAX, 1, msg) - # push args + # . . call check-ints-equal(EAX, 1, msg) + # . . push args 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 68/push 1/imm32/true 50/push-EAX - # call + # . . call e8/call check-ints-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP c3/return test-compare-kernel-string-with-inequal-array: # EAX = kernel-string-equal(Abc-kernel-string, "Adc") - # push args + # . . push args 68/push "Adc"/imm32 68/push Abc-kernel-string/imm32 - # call + # . . call e8/call kernel-string-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # call check-ints-equal(EAX, 0, msg) - # push args + # . . call check-ints-equal(EAX, 0, msg) + # . . push args 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 68/push 0/imm32/false 50/push-EAX - # call + # . . call e8/call check-ints-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP c3/return test-compare-kernel-string-with-empty-array: # EAX = kernel-string-equal(Abc-kernel-string, "") - # push args + # . . push args 68/push ""/imm32 68/push Abc-kernel-string/imm32 - # call + # . . call e8/call kernel-string-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # call check-ints-equal(EAX, 0) - # push args + # . . call check-ints-equal(EAX, 0) + # . . push args 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 68/push 0/imm32/false 50/push-EAX - # call + # . . call e8/call check-ints-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP c3/return test-compare-kernel-string-with-shorter-array: # EAX = kernel-string-equal(Abc-kernel-string, "Ab") - # push args + # . . push args 68/push "Ab"/imm32 68/push Abc-kernel-string/imm32 - # call + # . . call e8/call kernel-string-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # call check-ints-equal(EAX, 0) - # push args + # . . call check-ints-equal(EAX, 0) + # . . push args 68/push "F - test-compare-kernel-string-with-shorter-array"/imm32 68/push 0/imm32/false 50/push-EAX - # call + # . . call e8/call check-ints-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP c3/return test-compare-kernel-string-with-longer-array: # EAX = kernel-string-equal(Abc-kernel-string, "Abcd") - # push args + # . . push args 68/push "Abcd"/imm32 68/push Abc-kernel-string/imm32 - # call + # . . call e8/call kernel-string-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # call check-ints-equal(EAX, 0) - # push args + # . . call check-ints-equal(EAX, 0) + # . . push args 68/push "F - test-compare-kernel-string-with-longer-array"/imm32 68/push 0/imm32/false 50/push-EAX - # call + # . . call e8/call check-ints-equal/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP c3/return @@ -254,10 +254,10 @@ test-compare-kernel-string-with-longer-array: # print msg to stderr if a != b, otherwise print "." check-ints-equal: # (a : int, b : int, msg : (address array byte)) -> boolean - # prolog + # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # save registers + # . save registers 51/push-ECX 53/push-EBX # load args into EAX, EBX and ECX @@ -267,11 +267,11 @@ check-ints-equal: # (a : int, b : int, msg : (address array byte)) -> boolean 39/compare 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . . # compare EAX and EBX 75/jump-if-unequal $check-ints-equal:else/disp8 # print('.') - # push args + # . . push args 68/push "."/imm32 - # call + # . . call e8/call write-stderr/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # return eb/jump $check-ints-equal:end/disp8 @@ -280,21 +280,21 @@ $check-ints-equal:else: # copy msg into ECX 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 1/r32/ECX 0x10/disp8 . # copy *(EBP+16) to ECX # print(ECX) - # push args + # . . push args 51/push-ECX - # call + # . . call e8/call write-stderr/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # print newline - # push args + # . . push args 68/push Newline/imm32 - # call + # . . call e8/call write-stderr/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP $check-ints-equal:end: - # restore registers + # . restore registers 5b/pop-to-EBX 59/pop-to-ECX # end @@ -303,10 +303,10 @@ $check-ints-equal:end: c3/return write-stderr: # s : (address array byte) -> - # prolog + # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # save registers + # . save registers 50/push-EAX 51/push-ECX 52/push-EDX @@ -323,7 +323,7 @@ write-stderr: # s : (address array byte) -> # syscall b8/copy-to-EAX 4/imm32/write cd/syscall 0x80/imm8 - # restore registers + # . restore registers 5b/pop-to-EBX 5a/pop-to-EDX 59/pop-to-ECX @@ -347,4 +347,4 @@ Null-kernel-string: Abc-kernel-string: 41/A 62/b 63/c 00/null -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex12.subx b/subx/examples/ex12.subx index 73d78d96..565c8d50 100644 --- a/subx/examples/ex12.subx +++ b/subx/examples/ex12.subx @@ -7,9 +7,9 @@ # You shouldn't get a segmentation fault. == 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 register 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 # syscall(mmap, 0x1000) bb/copy-to-EBX Mmap-new-segment/imm32 @@ -41,4 +41,4 @@ Mmap-new-segment: # type mmap_arg_struct # offset 00 00 00 00 # 0 since MAP_ANONYMOUS is specified -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex2.subx b/subx/examples/ex2.subx index 09fe4414..f7be9b65 100644 --- a/subx/examples/ex2.subx +++ b/subx/examples/ex2.subx @@ -15,4 +15,4 @@ bb/copy-to-EBX 1/imm32 b8/copy-to-EAX 1/imm32 cd/syscall 0x80/imm8 -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex3.subx b/subx/examples/ex3.subx index b3f7d6fe..b6e21698 100644 --- a/subx/examples/ex3.subx +++ b/subx/examples/ex3.subx @@ -8,9 +8,9 @@ # 55 == 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 register 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 # result: EBX = 0 bb/copy-to-EBX 0/imm32 @@ -33,4 +33,4 @@ $exit: b8/copy-to-EAX 1/imm32 cd/syscall 0x80/imm8 -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex4.subx b/subx/examples/ex4.subx index 445f7d1b..2fd15cd7 100644 --- a/subx/examples/ex4.subx +++ b/subx/examples/ex4.subx @@ -37,4 +37,4 @@ cd/syscall 0x80/imm8 X: 00 00 00 00 # space for read() to write to -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex5.subx b/subx/examples/ex5.subx index 44291b35..136c177b 100644 --- a/subx/examples/ex5.subx +++ b/subx/examples/ex5.subx @@ -5,9 +5,9 @@ # $ subx run examples/ex5 == 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 register 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: # allocate x on the stack @@ -39,4 +39,4 @@ b8/copy-to-EAX 1/imm32/exit cd/syscall 0x80/imm8 -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex6.subx b/subx/examples/ex6.subx index 10331808..fc266a3a 100644 --- a/subx/examples/ex6.subx +++ b/subx/examples/ex6.subx @@ -6,9 +6,9 @@ # Hello, world! == 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 register 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 # syscall(write, stdout, X, size) # fd = 1 (stdout) @@ -33,4 +33,4 @@ X: # string to print 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 0a 00 # H e l l o , ␣ w o r l d ! newline null -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex7.subx b/subx/examples/ex7.subx index 93b568f9..3650817d 100644 --- a/subx/examples/ex7.subx +++ b/subx/examples/ex7.subx @@ -11,9 +11,9 @@ # 97 == 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 register 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 # syscall(creat, Filename) bb/copy-to-EBX Filename/imm32 @@ -101,4 +101,4 @@ B: Filename: 2e 66 6f 6f 00 00 00 00 -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex8.subx b/subx/examples/ex8.subx index fd7929f4..410dfe08 100644 --- a/subx/examples/ex8.subx +++ b/subx/examples/ex8.subx @@ -15,18 +15,18 @@ # Locals start from ESP-4 downwards. == 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 register 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 - # prolog + # . prolog 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # call ascii-length(argv[1]) - # push args + # . . call ascii-length(argv[1]) + # . . push args ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0x8/disp8 . # push *(EBP+8) - # call + # . . call e8/call ascii-length/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # exit(EAX) @@ -55,4 +55,4 @@ $ascii-length-ret: # return (result in EAX) c3/return -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 diff --git a/subx/examples/ex9.subx b/subx/examples/ex9.subx index 00f2d661..964151a2 100644 --- a/subx/examples/ex9.subx +++ b/subx/examples/ex9.subx @@ -17,20 +17,20 @@ # Locals start from ESP-4 downwards. == 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 register 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 - # prolog + # . prolog 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP - # call ascii-difference(argv[1], argv[2]) + # . . call ascii-difference(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) # push argv[1] ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0x8/disp8 . # push *(EBP+8) - # call + # . . call e8/call ascii-difference/disp32 - # discard args + # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # exit(EAX) 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # copy EAX to EBX @@ -48,4 +48,4 @@ ascii-difference: # (s1, s2) : null-terminated ascii strings 29/subtract 3/mod/direct 0/rm32/EAX . . . 1/r32/ECX . . # subtract ECX from EAX c3/return -# vim:nowrap:textwidth=0 +# . . vim:nowrap:textwidth=0 -- cgit 1.4.1-2-gfad0