This commit is contained in:
Kartik Agaram 2018-10-01 15:18:00 -07:00
parent 4224ec8188
commit f872f7c726
2 changed files with 11 additions and 11 deletions

View File

@ -4,8 +4,8 @@
# the character read.
#
# To run (from the subx directory):
# $ subx translate examples/ex8.subx -o examples/ex8
# $ subx run examples/ex8
# $ subx translate examples/ex7.subx -o examples/ex7
# $ subx run examples/ex7
# Expected result:
# $ echo $?
# 97

View File

@ -26,28 +26,28 @@
# call
e8/call ascii_length/disp32
# discard args
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add 4 to ESP
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add 4 to ESP
# exit(EAX)
89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # copy EAX to EBX
b8/copy . . . . . . . 1/imm32/exit # copy 1 to EAX
89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # copy EAX to EBX
b8/copy . . . . . . . 1/imm32/exit # copy 1 to EAX
cd/syscall 0x80/imm8
ascii_length: # (s)
# initialize s (EDX)
8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 2/r32/EDX 4/disp8 # copy *(ESP+4) to EDX
8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 2/r32/EDX 4/disp8 # copy *(ESP+4) to EDX
# var result = 0 (EAX)
b8/copy . . . . . . . 0/imm32 # copy 0 to EAX
b8/copy . . . . . . . 0/imm32 # copy 0 to EAX
$ascii_length_loop:
# var c = *s (ECX)
8a/copy 0/mod/* 2/rm32/EDX . . . 1/r32/ECX . . # copy byte at *EDX to lower byte of ECX
8a/copy 0/mod/* 2/rm32/EDX . . . 1/r32/ECX . . # copy byte at *EDX to lower byte of ECX
# if c == '\0' break
81 7/subop/compare 3/mod/direct 1/rm32/ECX . . . . . 0/imm32 # compare ECX with 0
81 7/subop/compare 3/mod/direct 1/rm32/ECX . . . . . 0/imm32 # compare ECX with 0
74/jump-if-equal $ascii_length_ret/disp8
# ++s
81 0/subop/add 3/mod/direct 2/rm32/EDX . . . . . 1/imm32 # add 1 to EDX
81 0/subop/add 3/mod/direct 2/rm32/EDX . . . . . 1/imm32 # add 1 to EDX
# ++result
81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 1/imm32 # add 1 to EAX
81 0/subop/add 3/mod/direct 0/rm32/EAX . . . . . 1/imm32 # add 1 to EAX
# loop
eb/jump $ascii_length_loop/disp8
$ascii_length_ret: