From 68df24fa778f7f5a2651a4623681f38dc920c490 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 7 Sep 2020 16:38:14 -0700 Subject: 6746 --- html/112read-byte.subx.html | 170 ++++++++++++++++++++++++++++---------------- 1 file changed, 107 insertions(+), 63 deletions(-) (limited to 'html/112read-byte.subx.html') diff --git a/html/112read-byte.subx.html b/html/112read-byte.subx.html index 751cd196..e101e460 100644 --- a/html/112read-byte.subx.html +++ b/html/112read-byte.subx.html @@ -95,7 +95,7 @@ if ('onhashchange' in window) { 33 # . op subop mod rm32 base index scale r32 34 # . 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 35 - 36 # return next byte value in eax, with top 3 bytes cleared. + 36 # Return next byte value in eax, with top 3 bytes cleared. 37 # On reaching end of file, return 0xffffffff (Eof). 38 read-byte-buffered: # f: (addr buffered-file) -> byte-or-Eof/eax: byte 39 # . prologue @@ -178,7 +178,7 @@ if ('onhashchange' in window) { 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 +119 68/push _test-buffered-file/imm32 120 # . . call 121 e8/call read-byte-buffered/disp32 122 # . . discard args @@ -222,14 +222,14 @@ if ('onhashchange' in window) { 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 +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 +170 68/push _test-buffered-file/imm32 171 # . . call 172 e8/call read-byte-buffered/disp32 173 # . . discard args @@ -265,7 +265,7 @@ if ('onhashchange' in window) { 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 +206 68/push _test-buffered-file/imm32 207 # . . call 208 e8/call read-byte-buffered/disp32 209 # . . discard args @@ -309,11 +309,11 @@ if ('onhashchange' in window) { 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->size -250 b8/copy-to-eax _test-buffered-file/imm32 +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 +254 68/push _test-buffered-file/imm32 255 # . . call 256 e8/call read-byte-buffered/disp32 257 # . . discard args @@ -330,62 +330,106 @@ if ('onhashchange' in window) { 268 # . end 269 c3/return 270 -271 == data -272 -273 # a test buffered file for _test-stream -274 _test-buffered-file: # buffered-file -275 # file descriptor or (addr 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 # size -283 6/imm32 -284 # data -285 00 00 00 00 00 00 # 6 bytes -286 -287 _test-input-stream: # (stream byte) -288 # current write index -289 0/imm32 -290 # current read index -291 0/imm32 -292 # size -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 -299 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -300 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -301 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -302 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -303 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -304 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -305 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -306 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -307 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -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 -312 # a test buffered file for _test-input-stream -313 _test-input-buffered-file: # buffered-file -314 # file descriptor or (addr 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 # size -322 6/imm32 -323 # data -324 00 00 00 00 00 00 # 6 bytes -325 -326 # . . vim:nowrap:textwidth=0 +271 # Return next byte value in eax, with top 3 bytes cleared. +272 # Abort on reaching end of file. +273 read-byte: # s: (addr stream byte) -> result/eax: byte +274 # . prologue +275 55/push-ebp +276 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp +277 # . save registers +278 51/push-ecx +279 56/push-esi +280 # esi = s +281 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi +282 # ecx = s->read +283 8b/copy 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 4/disp8 . # copy *(esi+4) to ecx +284 # if (f->read >= f->write) abort +285 3b/compare 0/mod/indirect 6/rm32/esi . . . 1/r32/ecx . . # compare ecx with *esi +286 0f 8d/jump-if->= $read-byte:abort/disp32 +287 # result = f->data[f->read] +288 31/xor 3/mod/direct 0/rm32/eax . . . 0/r32/eax . . # clear eax +289 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/esi 1/index/ecx . 0/r32/AL 0xc/disp8 . # copy byte at *(esi+ecx+12) to AL +290 # ++f->read +291 ff 0/subop/increment 1/mod/*+disp8 6/rm32/esi . . . . 4/disp8 . # increment *(esi+4) +292 $read-byte:end: +293 # . restore registers +294 5e/pop-to-esi +295 59/pop-to-ecx +296 # . epilogue +297 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp +298 5d/pop-to-ebp +299 c3/return +300 +301 $read-byte:abort: +302 # . _write(2/stderr, error) +303 # . . push args +304 68/push "read-byte: empty stream\n"/imm32 +305 68/push 2/imm32/stderr +306 # . . call +307 e8/call _write/disp32 +308 # . . discard args +309 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp +310 # . syscall(exit, 1) +311 bb/copy-to-ebx 1/imm32 +312 e8/call syscall_exit/disp32 +313 # never gets here +314 +315 == data +316 +317 # a test buffered file for _test-stream +318 _test-buffered-file: # buffered-file +319 # file descriptor or (addr stream byte) +320 _test-stream/imm32 +321 $_test-buffered-file->buffer: +322 # current write index +323 0/imm32 +324 # current read index +325 0/imm32 +326 # size +327 6/imm32 +328 # data +329 00 00 00 00 00 00 # 6 bytes +330 +331 _test-input-stream: # (stream byte) +332 # current write index +333 0/imm32 +334 # current read index +335 0/imm32 +336 # size +337 0x100/imm32 # 256 bytes +338 # data (16 lines x 16 bytes/line) +339 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +340 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +341 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +342 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +343 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +344 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +345 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +346 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +347 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +348 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +349 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +350 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +351 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +352 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +353 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +354 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +355 +356 # a test buffered file for _test-input-stream +357 _test-input-buffered-file: # buffered-file +358 # file descriptor or (addr stream byte) +359 _test-input-stream/imm32 +360 $_test-input-buffered-file->buffer: +361 # current write index +362 0/imm32 +363 # current read index +364 0/imm32 +365 # size +366 6/imm32 +367 # data +368 00 00 00 00 00 00 # 6 bytes +369 +370 # . . vim:nowrap:textwidth=0 -- cgit 1.4.1-2-gfad0