From 8aeb85f04ee68b960a6d326aca1a17dec2f6d019 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 9 Dec 2019 01:26:58 -0800 Subject: 5806 --- html/061read-byte.subx.html | 485 ++++++++++++++++++++++---------------------- 1 file changed, 242 insertions(+), 243 deletions(-) (limited to 'html/061read-byte.subx.html') diff --git a/html/061read-byte.subx.html b/html/061read-byte.subx.html index 6b6603bc..9e5f62a6 100644 --- a/html/061read-byte.subx.html +++ b/html/061read-byte.subx.html @@ -18,12 +18,12 @@ a { color:inherit; } .subxFunction { color: #af5f00; text-decoration: underline; } .LineNr { } .subxS1Comment { color: #0000af; } -.Constant { color: #008787; } +.subxTest { color: #5f8700; } .SpecialChar { color: #d70000; } -.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } +.Constant { color: #008787; } .subxMinorFunction { color: #875f5f; } +.Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } .subxS2Comment { color: #8a8a8a; } -.subxTest { color: #5f8700; } .subxH1Comment { color: #005faf; text-decoration: underline; } --> @@ -73,10 +73,10 @@ if ('onhashchange' in window) { 11 12 # The buffered file for standard input. Also illustrates the layout for 13 # buffered-file: a pointer to the backing store, followed by a 'buffer' stream - 14 Stdin: - 15 # file descriptor or (address stream) + 14 Stdin: # (ref buffered-file) + 15 # file descriptor or (address stream byte) 16 0/imm32 # standard input - 17 Stdin->buffer: + 17 $Stdin->buffer: 18 # inlined fields for a stream 19 # current write index 20 0/imm32 @@ -135,226 +135,226 @@ if ('onhashchange' in window) { 73 b8/copy-to-eax 0xffffffff/imm32/Eof 74 eb/jump $read-byte-buffered:end/disp8 75 $read-byte-buffered:from-stream: - 76 # read byte from stream - 77 # AL = f->data[f->read] - 78 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . . # clear eax - 79 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 - 80 # ++f->read - 81 ff 0/subop/increment 1/mod/*+disp8 6/rm32/esi . . . . 8/disp8 . # increment *(esi+8) - 82 $read-byte-buffered:end: - 83 # . restore registers - 84 5e/pop-to-esi - 85 59/pop-to-ecx - 86 # . epilogue - 87 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp - 88 5d/pop-to-ebp - 89 c3/return - 90 - 91 # - tests - 92 - 93 test-read-byte-buffered-single: - 94 # - check that read-byte-buffered returns first byte of 'file' - 95 # setup - 96 # . clear-stream(_test-stream) - 97 # . . push args - 98 68/push _test-stream/imm32 - 99 # . . call -100 e8/call clear-stream/disp32 -101 # . . discard args -102 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -103 # . clear-stream(_test-buffered-file->buffer) -104 # . . push args -105 68/push _test-buffered-file->buffer/imm32 -106 # . . call -107 e8/call clear-stream/disp32 -108 # . . discard args -109 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -110 # . write(_test-stream, "Ab") -111 # . . push args -112 68/push "Ab"/imm32 -113 68/push _test-stream/imm32 -114 # . . call -115 e8/call write/disp32 -116 # . . discard args -117 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp -118 # read-byte-buffered(_test-buffered-file) -119 # . . push args -120 68/push _test-buffered-file/imm32 -121 # . . call -122 e8/call read-byte-buffered/disp32 -123 # . . discard args -124 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -125 # check-ints-equal(eax, 'A', msg) -126 # . . push args -127 68/push "F - test-read-byte-buffered-single"/imm32 -128 68/push 0x41/imm32 -129 50/push-eax -130 # . . call -131 e8/call check-ints-equal/disp32 -132 # . . discard args -133 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp -134 # . end -135 c3/return -136 -137 test-read-byte-buffered-multiple: -138 # - call read-byte-buffered twice, check that second call returns second byte -139 # setup -140 # . clear-stream(_test-stream) -141 # . . push args -142 68/push _test-stream/imm32 -143 # . . call -144 e8/call clear-stream/disp32 -145 # . . discard args -146 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -147 # . clear-stream(_test-buffered-file->buffer) -148 # . . push args -149 68/push _test-buffered-file->buffer/imm32 -150 # . . call -151 e8/call clear-stream/disp32 -152 # . . discard args -153 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -154 # . write(_test-stream, "Ab") -155 # . . push args -156 68/push "Ab"/imm32 -157 68/push _test-stream/imm32 -158 # . . call -159 e8/call write/disp32 -160 # . . discard args -161 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp -162 # read-byte-buffered(_test-buffered-file) -163 # . . push args -164 68/push _test-buffered-file/imm32 -165 # . . call -166 e8/call read-byte-buffered/disp32 -167 # . . discard args -168 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -169 # read-byte-buffered(_test-buffered-file) -170 # . . push args -171 68/push _test-buffered-file/imm32 -172 # . . call -173 e8/call read-byte-buffered/disp32 -174 # . . discard args -175 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -176 # check-ints-equal(eax, 'b', msg) -177 # . . push args -178 68/push "F - test-read-byte-buffered-multiple"/imm32 -179 68/push 0x62/imm32 -180 50/push-eax -181 # . . call -182 e8/call check-ints-equal/disp32 -183 # . . discard args -184 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp -185 # . end -186 c3/return -187 -188 test-read-byte-buffered-end-of-file: -189 # - call read-byte-buffered on an empty 'file', check that it returns Eof -190 # setup -191 # . clear-stream(_test-stream) -192 # . . push args -193 68/push _test-stream/imm32 -194 # . . call -195 e8/call clear-stream/disp32 -196 # . . discard args -197 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -198 # . clear-stream(_test-buffered-file->buffer) -199 # . . push args -200 68/push _test-buffered-file->buffer/imm32 -201 # . . call -202 e8/call clear-stream/disp32 -203 # . . discard args -204 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -205 # read-byte-buffered(_test-buffered-file) -206 # . . push args -207 68/push _test-buffered-file/imm32 -208 # . . call -209 e8/call read-byte-buffered/disp32 -210 # . . discard args -211 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -212 # check-ints-equal(eax, 0xffffffff, msg) -213 # . . push args -214 68/push "F - test-read-byte-buffered-end-of-file"/imm32 -215 68/push 0xffffffff/imm32/Eof -216 50/push-eax -217 # . . call -218 e8/call check-ints-equal/disp32 -219 # . . discard args -220 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp -221 # . end -222 c3/return -223 -224 test-read-byte-buffered-refills-buffer: -225 # - consume buffered-file's buffer, check that next read-byte-buffered still works -226 # setup -227 # . clear-stream(_test-stream) -228 # . . push args -229 68/push _test-stream/imm32 -230 # . . call -231 e8/call clear-stream/disp32 -232 # . . discard args -233 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -234 # . clear-stream(_test-buffered-file->buffer) -235 # . . push args -236 68/push _test-buffered-file->buffer/imm32 -237 # . . call -238 e8/call clear-stream/disp32 -239 # . . discard args -240 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -241 # . write(_test-stream, "Abcdefgh") -242 # . . push args -243 68/push "Abcdefgh"/imm32 -244 68/push _test-stream/imm32 -245 # . . call -246 e8/call write/disp32 -247 # . . discard args -248 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp -249 # pretend buffer is full -250 # . _test-buffered-file->read = 6 # >= _test-buffered-file->length -251 b8/copy-to-eax _test-buffered-file/imm32 -252 c7 0/subop/copy 1/mod/*+disp8 0/rm32/eax . . . . 8/disp8 6/imm32 # copy to *(eax+8) -253 # read-byte-buffered(_test-buffered-file) -254 # . . push args -255 68/push _test-buffered-file/imm32 -256 # . . call -257 e8/call read-byte-buffered/disp32 -258 # . . discard args -259 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -260 # check-ints-equal(eax, 'A', msg) -261 # . . push args -262 68/push "F - test-read-byte-buffered-refills-buffer"/imm32 -263 68/push 0x41/imm32 -264 50/push-eax -265 # . . call -266 e8/call check-ints-equal/disp32 -267 # . . discard args -268 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp -269 # . end -270 c3/return -271 -272 == data -273 -274 # a test buffered file for _test-stream -275 _test-buffered-file: -276 # file descriptor or (address stream) -277 _test-stream/imm32 -278 _test-buffered-file->buffer: -279 # current write index -280 0/imm32 -281 # current read index -282 0/imm32 -283 # length -284 6/imm32 -285 # data -286 00 00 00 00 00 00 # 6 bytes -287 -288 _test-input-stream: -289 # current write index -290 0/imm32 -291 # current read index -292 0/imm32 -293 # length -294 0x100/imm32 # 256 bytes -295 # data (16 lines x 16 bytes/line) + 76 # byte-or-Eof = f->data[f->read] + 77 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . . # clear eax + 78 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 + 79 # ++f->read + 80 ff 0/subop/increment 1/mod/*+disp8 6/rm32/esi . . . . 8/disp8 . # increment *(esi+8) + 81 $read-byte-buffered:end: + 82 # . restore registers + 83 5e/pop-to-esi + 84 59/pop-to-ecx + 85 # . epilogue + 86 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp + 87 5d/pop-to-ebp + 88 c3/return + 89 + 90 # - tests + 91 + 92 test-read-byte-buffered-single: + 93 # - check that read-byte-buffered returns first byte of 'file' + 94 # setup + 95 # . clear-stream(_test-stream) + 96 # . . push args + 97 68/push _test-stream/imm32 + 98 # . . call + 99 e8/call clear-stream/disp32 +100 # . . discard args +101 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +102 # . clear-stream(_test-buffered-file->buffer) +103 # . . push args +104 68/push $_test-buffered-file->buffer/imm32 +105 # . . call +106 e8/call clear-stream/disp32 +107 # . . discard args +108 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +109 # . write(_test-stream, "Ab") +110 # . . push args +111 68/push "Ab"/imm32 +112 68/push _test-stream/imm32 +113 # . . call +114 e8/call write/disp32 +115 # . . discard args +116 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +117 # read-byte-buffered(_test-buffered-file) +118 # . . push args +119 68/push _test-buffered-file/imm32 +120 # . . call +121 e8/call read-byte-buffered/disp32 +122 # . . discard args +123 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +124 # check-ints-equal(eax, 'A', msg) +125 # . . push args +126 68/push "F - test-read-byte-buffered-single"/imm32 +127 68/push 0x41/imm32 +128 50/push-eax +129 # . . call +130 e8/call check-ints-equal/disp32 +131 # . . discard args +132 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp +133 # . end +134 c3/return +135 +136 test-read-byte-buffered-multiple: +137 # - call read-byte-buffered twice, check that second call returns second byte +138 # setup +139 # . clear-stream(_test-stream) +140 # . . push args +141 68/push _test-stream/imm32 +142 # . . call +143 e8/call clear-stream/disp32 +144 # . . discard args +145 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +146 # . clear-stream($_test-buffered-file->buffer) +147 # . . push args +148 68/push $_test-buffered-file->buffer/imm32 +149 # . . call +150 e8/call clear-stream/disp32 +151 # . . discard args +152 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +153 # . write(_test-stream, "Ab") +154 # . . push args +155 68/push "Ab"/imm32 +156 68/push _test-stream/imm32 +157 # . . call +158 e8/call write/disp32 +159 # . . discard args +160 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +161 # read-byte-buffered(_test-buffered-file) +162 # . . push args +163 68/push _test-buffered-file/imm32 +164 # . . call +165 e8/call read-byte-buffered/disp32 +166 # . . discard args +167 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +168 # read-byte-buffered(_test-buffered-file) +169 # . . push args +170 68/push _test-buffered-file/imm32 +171 # . . call +172 e8/call read-byte-buffered/disp32 +173 # . . discard args +174 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +175 # check-ints-equal(eax, 'b', msg) +176 # . . push args +177 68/push "F - test-read-byte-buffered-multiple"/imm32 +178 68/push 0x62/imm32 +179 50/push-eax +180 # . . call +181 e8/call check-ints-equal/disp32 +182 # . . discard args +183 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp +184 # . end +185 c3/return +186 +187 test-read-byte-buffered-end-of-file: +188 # - call read-byte-buffered on an empty 'file', check that it returns Eof +189 # setup +190 # . clear-stream(_test-stream) +191 # . . push args +192 68/push _test-stream/imm32 +193 # . . call +194 e8/call clear-stream/disp32 +195 # . . discard args +196 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +197 # . clear-stream($_test-buffered-file->buffer) +198 # . . push args +199 68/push $_test-buffered-file->buffer/imm32 +200 # . . call +201 e8/call clear-stream/disp32 +202 # . . discard args +203 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +204 # read-byte-buffered(_test-buffered-file) +205 # . . push args +206 68/push _test-buffered-file/imm32 +207 # . . call +208 e8/call read-byte-buffered/disp32 +209 # . . discard args +210 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +211 # check-ints-equal(eax, 0xffffffff, msg) +212 # . . push args +213 68/push "F - test-read-byte-buffered-end-of-file"/imm32 +214 68/push 0xffffffff/imm32/Eof +215 50/push-eax +216 # . . call +217 e8/call check-ints-equal/disp32 +218 # . . discard args +219 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp +220 # . end +221 c3/return +222 +223 test-read-byte-buffered-refills-buffer: +224 # - consume buffered-file's buffer, check that next read-byte-buffered still works +225 # setup +226 # . clear-stream(_test-stream) +227 # . . push args +228 68/push _test-stream/imm32 +229 # . . call +230 e8/call clear-stream/disp32 +231 # . . discard args +232 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +233 # . clear-stream($_test-buffered-file->buffer) +234 # . . push args +235 68/push $_test-buffered-file->buffer/imm32 +236 # . . call +237 e8/call clear-stream/disp32 +238 # . . discard args +239 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +240 # . write(_test-stream, "Abcdefgh") +241 # . . push args +242 68/push "Abcdefgh"/imm32 +243 68/push _test-stream/imm32 +244 # . . call +245 e8/call write/disp32 +246 # . . discard args +247 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +248 # pretend buffer is full +249 # . _test-buffered-file->read = 6 # >= _test-buffered-file->length +250 b8/copy-to-eax _test-buffered-file/imm32 +251 c7 0/subop/copy 1/mod/*+disp8 0/rm32/eax . . . . 8/disp8 6/imm32 # copy to *(eax+8) +252 # read-byte-buffered(_test-buffered-file) +253 # . . push args +254 68/push _test-buffered-file/imm32 +255 # . . call +256 e8/call read-byte-buffered/disp32 +257 # . . discard args +258 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +259 # check-ints-equal(eax, 'A', msg) +260 # . . push args +261 68/push "F - test-read-byte-buffered-refills-buffer"/imm32 +262 68/push 0x41/imm32 +263 50/push-eax +264 # . . call +265 e8/call check-ints-equal/disp32 +266 # . . discard args +267 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp +268 # . end +269 c3/return +270 +271 == data +272 +273 # a test buffered file for _test-stream +274 _test-buffered-file: # (ref buffered-file) +275 # file descriptor or (address stream byte) +276 _test-stream/imm32 +277 $_test-buffered-file->buffer: +278 # current write index +279 0/imm32 +280 # current read index +281 0/imm32 +282 # length +283 6/imm32 +284 # data +285 00 00 00 00 00 00 # 6 bytes +286 +287 _test-input-stream: # (ref stream byte) +288 # current write index +289 0/imm32 +290 # current read index +291 0/imm32 +292 # length +293 0x100/imm32 # 256 bytes +294 # data (16 lines x 16 bytes/line) +295 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 296 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 297 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 298 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 @@ -370,23 +370,22 @@ if ('onhashchange' in window) { 308 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 309 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 310 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -311 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -312 -313 # a test buffered file for _test-input-stream -314 _test-input-buffered-file: -315 # file descriptor or (address stream) -316 _test-input-stream/imm32 -317 _test-input-buffered-file->buffer: -318 # current write index -319 0/imm32 -320 # current read index -321 0/imm32 -322 # length -323 6/imm32 -324 # data -325 00 00 00 00 00 00 # 6 bytes -326 -327 # . . vim:nowrap:textwidth=0 +311 +312 # a test buffered file for _test-input-stream +313 _test-input-buffered-file: # (ref buffered-file) +314 # file descriptor or (address stream byte) +315 _test-input-stream/imm32 +316 $_test-input-buffered-file->buffer: +317 # current write index +318 0/imm32 +319 # current read index +320 0/imm32 +321 # length +322 6/imm32 +323 # data +324 00 00 00 00 00 00 # 6 bytes +325 +326 # . . vim:nowrap:textwidth=0 -- cgit 1.4.1-2-gfad0