diff options
Diffstat (limited to 'subx/061read-byte.subx')
-rw-r--r-- | subx/061read-byte.subx | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/subx/061read-byte.subx b/subx/061read-byte.subx index 7503818f..81080393 100644 --- a/subx/061read-byte.subx +++ b/subx/061read-byte.subx @@ -1,4 +1,4 @@ -# read-byte: one higher-level abstraction atop 'read'. +# read-byte-buffered: one higher-level abstraction atop 'read'. # # There are many situations where 'read' is a lot to manage, and we need # to abstract some details away. One of them is when we want to read a file @@ -32,8 +32,8 @@ Stdin: # . 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 #? Entry: # run a single test, while debugging -#? e8/call test-read-byte-multiple/disp32 -#? e8/call test-read-byte-refills-buffer/disp32 +#? e8/call test-read-byte-buffered-multiple/disp32 +#? e8/call test-read-byte-buffered-refills-buffer/disp32 #? # syscall(exit, Num-test-failures) #? 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32 # copy *Num-test-failures to EBX #? b8/copy-to-EAX 1/imm32/exit @@ -41,7 +41,7 @@ Stdin: # return next byte value in EAX, with top 3 bytes cleared. # On reaching end of file, return 0xffffffff (Eof). -read-byte: # f : (address buffered-file) -> byte-or-Eof/EAX +read-byte-buffered: # f : (address buffered-file) -> byte-or-Eof/EAX # . prolog 55/push-EBP 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -54,7 +54,7 @@ read-byte: # f : (address buffered-file) -> byte-or-Eof/EAX 8b/copy 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 8/disp8 . # copy *(ESI+8) to ECX # if (f->read >= f->write) populate stream from file 3b/compare 1/mod/*+disp8 6/rm32/ESI . . . 1/r32/ECX 4/disp8 . # compare ECX with *(ESI+4) - 7c/jump-if-lesser $read-byte:from-stream/disp8 + 7c/jump-if-lesser $read-byte-buffered:from-stream/disp8 # . clear-stream(stream = f+4) # . . push args 8d/copy-address 1/mod/*+disp8 6/rm32/ESI . . . 0/r32/EAX 4/disp8 . # copy ESI+4 to EAX @@ -75,17 +75,17 @@ read-byte: # f : (address buffered-file) -> byte-or-Eof/EAX 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP # if (EAX == 0) return 0xffffffff 3d/compare-EAX-and 0/imm32 - 75/jump-if-not-equal $read-byte:from-stream/disp8 + 75/jump-if-not-equal $read-byte-buffered:from-stream/disp8 b8/copy-to-EAX 0xffffffff/imm32/Eof - eb/jump $read-byte:end/disp8 -$read-byte:from-stream: + eb/jump $read-byte-buffered:end/disp8 +$read-byte-buffered:from-stream: # read byte from stream # AL = f->data[f->read] 31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . . # clear EAX 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX . 0/r32/AL 0x10/disp8 . # copy byte at *(ESI+ECX+16) to AL # ++f->read ff 0/subop/increment 1/mod/*+disp8 6/rm32/ESI . . . . 8/disp8 . # increment *(ESI+8) -$read-byte:end: +$read-byte-buffered:end: # . restore registers 5e/pop-to-ESI 59/pop-to-ECX @@ -96,8 +96,8 @@ $read-byte:end: # - tests -test-read-byte-single: - # - check that read-byte returns first byte of 'file' +test-read-byte-buffered-single: + # - check that read-byte-buffered returns first byte of 'file' # setup # . clear-stream(_test-stream) # . . push args @@ -123,16 +123,16 @@ test-read-byte-single: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # read-byte(_test-buffered-file) + # read-byte-buffered(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-ints-equal(EAX, 'A', msg) # . . push args - 68/push "F - test-read-byte-single"/imm32 + 68/push "F - test-read-byte-buffered-single"/imm32 68/push 0x41/imm32 50/push-EAX # . . call @@ -142,8 +142,8 @@ test-read-byte-single: # . end c3/return -test-read-byte-multiple: - # - call read-byte twice, check that second call returns second byte +test-read-byte-buffered-multiple: + # - call read-byte-buffered twice, check that second call returns second byte # setup # . clear-stream(_test-stream) # . . push args @@ -169,23 +169,23 @@ test-read-byte-multiple: e8/call write/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP - # read-byte(_test-buffered-file) + # read-byte-buffered(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP - # read-byte(_test-buffered-file) + # read-byte-buffered(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-ints-equal(EAX, 'b', msg) # . . push args - 68/push "F - test-read-byte-multiple"/imm32 + 68/push "F - test-read-byte-buffered-multiple"/imm32 68/push 0x62/imm32 50/push-EAX # . . call @@ -195,8 +195,8 @@ test-read-byte-multiple: # . end c3/return -test-read-byte-end-of-file: - # - call read-byte on an empty 'file', check that it returns Eof +test-read-byte-buffered-end-of-file: + # - call read-byte-buffered on an empty 'file', check that it returns Eof # setup # . clear-stream(_test-stream) # . . push args @@ -214,16 +214,16 @@ test-read-byte-end-of-file: e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP - # read-byte(_test-buffered-file) + # read-byte-buffered(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-ints-equal(EAX, 0xffffffff, msg) # . . push args - 68/push "F - test-read-byte-end-of-file"/imm32 + 68/push "F - test-read-byte-buffered-end-of-file"/imm32 68/push 0xffffffff/imm32/Eof 50/push-EAX # . . call @@ -233,8 +233,8 @@ test-read-byte-end-of-file: # . end c3/return -test-read-byte-refills-buffer: - # - consume buffered-file's buffer, check that next read-byte still works +test-read-byte-buffered-refills-buffer: + # - consume buffered-file's buffer, check that next read-byte-buffered still works # setup # . clear-stream(_test-stream) # . . push args @@ -264,16 +264,16 @@ test-read-byte-refills-buffer: # . _test-buffered-file->read = 6 # >= _test-buffered-file->length b8/copy-to-EAX _test-buffered-file/imm32 c7 0/subop/copy 1/mod/*+disp8 0/rm32/EAX . . . . 8/disp8 6/imm32 # copy to *(EAX+8) - # read-byte(_test-buffered-file) + # read-byte-buffered(_test-buffered-file) # . . push args 68/push _test-buffered-file/imm32 # . . call - e8/call read-byte/disp32 + e8/call read-byte-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP # check-ints-equal(EAX, 'A', msg) # . . push args - 68/push "F - test-read-byte-refills-buffer"/imm32 + 68/push "F - test-read-byte-buffered-refills-buffer"/imm32 68/push 0x41/imm32 50/push-EAX # . . call |