This commit is contained in:
Kartik Agaram 2018-12-02 11:08:30 -08:00
parent e4ac3c9e6e
commit f44c595267
4 changed files with 1426 additions and 1406 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,10 @@
# . 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
#? # for debugging: run a single test; don't bother setting status code
#? e8/call test-get-num-reads-single-digit/disp32
#? eb/jump $main:end/disp8
# main: run tests if necessary, call 'compile' if not
# . prolog
89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP
@ -50,7 +54,6 @@
75/jump-if-not-equal $run-main/disp8
# . run-tests()
e8/call run-tests/disp32
#? e8/call test-get-num-reads-multiple-digits/disp32
8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32 # copy *Num-test-failures to EBX
eb/jump $main:end/disp8
$run-main:
@ -94,13 +97,14 @@ compile: # in : (address buffered-file), out : fd or (address stream), err : fd
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP
# var num/ECX : (address stream) on the stack
# Numbers can be 32 bits or 8 hex bytes long. One of them will be in 'Look', so we need space for 7 bytes.
# We won't add more, so that we can get overflow-handling for free.
# Sizing the stream just right buys us overflow-handling for free inside 'get-num'.
# Add 12 bytes for 'read', 'write' and 'length' fields, for a total of 19 bytes, or 0x13 in hex.
# The stack pointer is no longer aligned, so dump_stack() can be misleading past this point.
81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 0x13/imm32 # subtract from ESP
8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none . 1/r32/ECX . . # copy ESP to ECX
# num->length = 7
# initialize the stream
# . num->length = 7
c7/copy 1/mod/*+disp8 1/rm32/ECX . . . . 8/disp8 7/imm32 # copy to *(ECX+8)
# read a digit from 'in' into 'num'
# . clear-stream(num)
# . . push args
51/push-ECX
@ -108,6 +112,7 @@ compile: # in : (address buffered-file), out : fd or (address stream), err : fd
e8/call clear-stream/disp32
# . . discard args
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP
# read a digit from 'in' into 'num'
# . get-num(in, num, err, ed)
# . . push args
ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0x14/disp8 . # push *(EBP+20)

View File

@ -30,6 +30,10 @@
# . 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
#? # for debugging: run a single test; don't bother setting status code
#? e8/call test-get-num-reads-single-digit/disp32
#? eb/jump $main:end/disp8
# main: run tests if necessary, call 'compile' if not
# . prolog
89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP
@ -50,7 +54,6 @@
75/jump-if-not-equal $run-main/disp8
# . run-tests()
e8/call run-tests/disp32
#? e8/call test-get-num-reads-multiple-digits/disp32
8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32 # copy *Num-test-failures to EBX
eb/jump $main:end/disp8
$run-main:
@ -95,13 +98,14 @@ compile: # in : (address buffered-file), out : fd or (address stream), err : fd
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP
# var num/ECX : (address stream) on the stack
# Numbers can be 32 bits or 8 hex bytes long. One of them will be in 'Look', so we need space for 7 bytes.
# We won't add more, so that we can get overflow-handling for free.
# Sizing the stream just right buys us overflow-handling for free inside 'get-num'.
# Add 12 bytes for 'read', 'write' and 'length' fields, for a total of 19 bytes, or 0x13 in hex.
# The stack pointer is no longer aligned, so dump_stack() can be misleading past this point.
81 5/subop/subtract 3/mod/direct 4/rm32/ESP . . . . . 0x13/imm32 # subtract from ESP
8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none . 1/r32/ECX . . # copy ESP to ECX
# num->length = 7
# initialize the stream
# . num->length = 7
c7/copy 1/mod/*+disp8 1/rm32/ECX . . . . 8/disp8 7/imm32 # copy to *(ECX+8)
# read a digit from 'in' into 'num'
# . clear-stream(num)
# . . push args
51/push-ECX
@ -109,6 +113,7 @@ compile: # in : (address buffered-file), out : fd or (address stream), err : fd
e8/call clear-stream/disp32
# . . discard args
81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP
# read a digit from 'in' into 'num'
# . get-num(in, num, err, ed)
# . . push args
ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0x14/disp8 . # push *(EBP+20)