about summary refs log blame commit diff stats
path: root/103kernel-string-equal.subx
blob: 7e1b9d6f6834aa5b4b32a14b625bc5989ea43ee9 (plain) (tree)
6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x1c/disp8 . # push *(ebp+28) # . . call e8/call stop/disp32 # never gets here $get-or-stop:terminus: # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # syscall(exit, 1) bb/copy-to-ebx 1/imm32 e8/call syscall_exit/disp32 test-get-or-stop: # This test uses exit-descriptors. Use ebp for setting up local variables. # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # setup # . clear-stream(_test-error-stream) # . . push args 68/push _test-error-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . clear-stream($_test-error-buffered-file->buffer) # . . push args 68/push $_test-error-buffered-file->buffer/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # var table/ecx: (stream {string, number} 24) # 2 rows * 12 bytes/row 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0x18/imm32 # subtract from esp 68/push 0x18/imm32/size 68/push 0/imm32/read 68/push 0/imm32/write 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx # var ed/edx: exit-descriptor 68/push 0/imm32 68/push 0/imm32 89/copy 3/mod/direct 2/rm32/edx . . . 4/r32/esp . . # copy esp to edx # size 'ed' for the calls to 'get-or-stop' # . tailor-exit-descriptor(ed, 24) # . . push args 68/push 0x18/imm32/nbytes-of-args-for-get-or-stop 52/push-edx # . . call e8/call tailor-exit-descriptor/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # insert(table, "code", 12 bytes/row, Heap) # . . push args 68/push Heap/imm32 68/push 0xc/imm32/row-size 68/push "code"/imm32 51/push-ecx # . . call e8/call get-or-insert/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp $test-get-or-stop:success: # eax = get-or-stop(table, "code", row-size=12, msg, _test-error-buffered-file, ed) # . . push args 52/push-edx/ed 68/push _test-error-buffered-file/imm32 68/push "foo"/imm32/abort-prefix 68/push 0xc/imm32/row-size 68/push "code"/imm32 51/push-ecx # . . call e8/call get-or-stop/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x18/imm32 # add to esp $test-get-or-stop:success-assertion: # check-ints-equal(eax - table->data, 8, msg) # . check-ints-equal(eax - table, 20, msg) # . . push args 68/push "F - test-get-or-stop/0"/imm32 68/push 0x14/imm32 29/subtract 3/mod/direct 0/rm32/eax . . . 1/r32/ecx . . # subtract ecx from eax 50/push-eax # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp $test-get-or-stop:failure: # eax = get-or-stop(table, "data", row-size=12, msg, _test-error-buffered-file, ed) # . . push args 52/push-edx/ed 68/push _test-error-buffered-file/imm32 68/push "foo"/imm32/abort-prefix 68/push 0xc/imm32/row-size 68/push "data"/imm32 51/push-ecx # . . call e8/call get-or-stop/disp32 # registers except esp may be clobbered at this point # restore register args, discard others 59/pop-to-ecx 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp 5a/pop-to-edx $test-get-or-stop:failure-assertion: # check that get-or-stop tried to call stop(1) # . check-ints-equal(ed->value, 2, msg) # . . push args 68/push "F - test-get-or-stop/1"/imm32 68/push 2/imm32 # . . push ed->value ff 6/subop/push 1/mod/*+disp8 2/rm32/edx . . . . 4/disp8 . # push *(edx+4) # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp $test-get-or-stop:end: # . epilogue # don't restore esp from ebp; manually reclaim locals 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x2c/imm32 # add to esp 5d/pop-to-ebp c3/return # if no row is found, stop(ed) get-slice-or-stop: # table: (addr stream {(handle array byte), _}), key: (addr slice), row-size: int, # abort-message-prefix: (addr string), err: (addr buffered-file), ed: (addr exit-descriptor) # -> result/eax: (addr _) # pseudocode: # curr = table->data # max = &table->data[table->write] # while curr < max # var c: (addr array byte) = lookup(*curr) # if slice-equal?(key, c) # return curr+8 # curr += row-size # write-buffered(err, msg) # stop(ed) # # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 51/push-ecx 52/push-edx 56/push-esi # esi = table 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi # var curr/ecx: (addr handle array byte) = table->data 8d/copy-address 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 0xc/disp8 . # copy esi+12 to ecx # var max/edx: (addr byte) = &table->data[table->write] 8b/copy 0/mod/indirect 6/rm32/esi . . . 2/r32/edx . . # copy *esi to edx 8d/copy-address 0/mod/indirect 4/rm32/sib 1/base/ecx 2/index/edx . 2/r32/edx . . # copy ecx+edx to edx $get-slice-or-stop:search-loop: # if (curr >= max) stop(ed) 39/compare 3/mod/direct 1/rm32/ecx . . . 2/r32/edx . . # compare ecx with edx 73/jump-if-addr>= $get-slice-or-stop:stop/disp8 # var c/eax: (addr array byte) = lookup(*curr) # . . push args ff 6/subop/push 1/mod/*+disp8 1/rm32/ecx . . . . 4/disp8 . # push *(ecx+4) ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . . # push *ecx # . . call e8/call lookup/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # if (slice-equal?(key, c)) return curr+4 # . eax = slice-equal?(key, c) # . . push args 50/push-eax ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call slice-equal?/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . if (eax != false) return eax = curr+8 3d/compare-eax-and 0/imm32/false 74/jump-if-= $get-slice-or-stop:mismatch/disp8 8d/copy-address 1/mod/*+disp8 1/rm32/ecx . . . 0/r32/eax 8/disp8 . # copy ecx+8 to eax eb/jump $get-slice-or-stop:end/disp8 $get-slice-or-stop:mismatch: # curr += row-size 03/add 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0x10/disp8 . # add *(ebp+16) to ecx # loop eb/jump $get-slice-or-stop:search-loop/disp8 $get-slice-or-stop:end: # . restore registers 5e/pop-to-esi 5a/pop-to-edx 59/pop-to-ecx # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return $get-slice-or-stop:stop: # . write-buffered(err, abort-message-prefix) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x14/disp8 . # push *(ebp+20) ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x18/disp8 . # push *(ebp+24) # . . call e8/call write-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write-buffered(err, error) # . . push args 68/push ": get-slice-or-stop: key not found: "/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x18/disp8 . # push *(ebp+24) # . . call e8/call write-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write-slice-buffered(err, key) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x18/disp8 . # push *(ebp+24) # . . call e8/call write-slice-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . write-buffered(err, "\n") # . . push args 68/push Newline/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x18/disp8 . # push *(ebp+24) # . . call e8/call write-buffered/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . stop(ed, 1) # . . push args 68/push 1/imm32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x1c/disp8 . # push *(ebp+28) # . . call e8/call stop/disp32 # never gets here $get-slice-or-stop:terminus: # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # syscall(exit, 1) bb/copy-to-ebx 1/imm32 e8/call syscall_exit/disp32 test-get-slice-or-stop: # This test uses exit-descriptors. Use ebp for setting up local variables. # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # setup # . clear-stream(_test-error-stream) # . . push args 68/push _test-error-stream/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # . clear-stream($_test-error-buffered-file->buffer) # . . push args 68/push $_test-error-buffered-file->buffer/imm32 # . . call e8/call clear-stream/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp # var table/ecx: (stream {string, number} 24) # 2 rows * 12 bytes/row 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0x18/imm32 # subtract from esp 68/push 0x18/imm32/size 68/push 0/imm32/read 68/push 0/imm32/write 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx # var ed/edx: exit-descriptor 68/push 0/imm32 68/push 0/imm32 89/copy 3/mod/direct 2/rm32/edx . . . 4/r32/esp . . # copy esp to edx # var slice/ebx: slice = "code" # . (eax..ebx) = "code" b8/copy-to-eax "code"/imm32 8b/copy 0/mod/indirect 0/rm32/eax . . . 3/r32/ebx . . # copy *eax to ebx 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 3/index/ebx . 3/r32/ebx 4/disp8 . # copy eax+ebx+4 to ebx 05/add-to-eax 4/imm32 # . ebx = {eax, ebx} 53/push-ebx 50/push-eax 89/copy 3/mod/direct 3/rm32/ebx . . . 4/r32/esp . . # copy esp to ebx # size 'ed' for the calls to 'get-or-stop' (define no locals past this point) # . tailor-exit-descriptor(ed, 24) # . . push args 68/push 0x18/imm32/nbytes-of-args-for-get-or-stop 52/push-edx # . . call e8/call tailor-exit-descriptor/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # insert(table, "code", 12 bytes/row, Heap) # . . push args 68/push Heap/imm32 68/push 0xc/imm32/row-size 68/push "code"/imm32 51/push-ecx # . . call e8/call get-or-insert/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp $test-get-slice-or-stop:success: # eax = get-slice-or-stop(table, slice, row-size=12, msg, _test-error-buffered-file, ed) # . . push args 52/push-edx/ed 68/push _test-error-buffered-file/imm32 68/push "foo"/imm32/abort-prefix 68/push 0xc/imm32/row-size 53/push-ebx/slice 51/push-ecx # . . call e8/call get-slice-or-stop/disp32 # registers except esp may be clobbered at this point # restore register args, discard others 59/pop-to-ecx 5b/pop-to-ebx 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp 5a/pop-to-edx $test-get-slice-or-stop:success-assertion: # check-ints-equal(eax - table->data, 8, msg) # first row's value slot returned # . check-ints-equal(eax - table, 20, msg) # . . push args 68/push "F - test-get-slice-or-stop/0"/imm32 68/push 0x14/imm32 29/subtract 3/mod/direct 0/rm32/eax . . . 1/r32/ecx . . # subtract ecx from eax 50/push-eax # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp $test-get-slice-or-stop:failure: # slice = "segment2" # . *ebx = "segment2"->data b8/copy-to-eax "segment2"/imm32 05/add-to-eax 4/imm32 89/copy 0/mod/indirect 3/rm32/ebx . . . 0/r32/eax . . # copy eax to *ebx # . *(ebx+4) = "segment2"->data + len("segment2") 05/add-to-eax 8/imm32/strlen 89/copy 1/mod/*+disp8 3/rm32/ebx . . . 0/r32/eax 4/disp8 . # copy eax to *(ebx+4) # eax = get-slice-or-stop(table, slice, row-size=12, msg, _test-error-buffered-file, ed) # . . push args 52/push-edx/ed 68/push _test-error-buffered-file/imm32 68/push "foo"/imm32/abort-prefix 68/push 0xc/imm32/row-size 53/push-ebx/slice 51/push-ecx # . . call e8/call get-slice-or-stop/disp32 # registers except esp may be clobbered at this point # restore register args, discard others 59/pop-to-ecx 5b/pop-to-ebx 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp 5a/pop-to-edx $test-get-slice-or-stop:failure-assertion: # check that get-or-stop tried to call stop(1) # . check-ints-equal(ed->value, 2, msg) # . . push args 68/push "F - test-get-or-stop/1"/imm32 68/push 2/imm32 # . . push ed->value ff 6/subop/push 1/mod/*+disp8 2/rm32/edx . . . . 4/disp8 . # push *(edx+4) # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp $test-get-slice-or-stop:end: # . epilogue # don't restore esp from ebp; manually reclaim locals 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x34/imm32 # add to esp 5d/pop-to-ebp c3/return # if no row is found, return null (0) maybe-get: # table: (addr stream {(handle array byte), T}), key: (addr array byte), row-size: int -> result/eax: (addr T) # pseudocode: # curr = table->data # max = &table->data[table->write] # while curr < max # var c: (addr array byte) = lookup(*curr) # if string-equal?(key, c) # return curr+8 # curr += row-size # return 0 # # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 51/push-ecx 52/push-edx 56/push-esi # esi = table 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi # var curr/ecx: (addr handle array byte) = table->data 8d/copy-address 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 0xc/disp8 . # copy esi+12 to ecx # var max/edx: (addr byte) = &table->data[table->write] 8b/copy 0/mod/indirect 6/rm32/esi . . . 2/r32/edx . . # copy *esi to edx 8d/copy-address 0/mod/indirect 4/rm32/sib 1/base/ecx 2/index/edx . 2/r32/edx . . # copy ecx+edx to edx $maybe-get:search-loop: # if (curr >= max) return null 39/compare 3/mod/direct 1/rm32/ecx . . . 2/r32/edx . . # compare ecx with edx 73/jump-if-addr>= $maybe-get:null/disp8 # var c/eax: (addr array byte) = lookup(*curr) # . . push args ff 6/subop/push 1/mod/*+disp8 1/rm32/ecx . . . . 4/disp8 . # push *(ecx+4) ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . . # push *ecx # . . call e8/call lookup/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # if (string-equal?(key, c)) return curr+4 # . eax = string-equal?(key, c) # . . push args 50/push-eax ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call string-equal?/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . if (eax != false) return eax = curr+8 3d/compare-eax-and 0/imm32/false 74/jump-if-= $maybe-get:mismatch/disp8 8d/copy-address 1/mod/*+disp8 1/rm32/ecx . . . 0/r32/eax 8/disp8 . # copy ecx+8 to eax eb/jump $maybe-get:end/disp8 $maybe-get:mismatch: # curr += row-size 03/add 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0x10/disp8 . # add *(ebp+16) to ecx # loop eb/jump $maybe-get:search-loop/disp8 $maybe-get:null: b8/copy-to-eax 0/imm32 $maybe-get:end: # . restore registers 5e/pop-to-esi 5a/pop-to-edx 59/pop-to-ecx # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-maybe-get: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # - setup: create a table with one row # var table/ecx: (stream {string, number} 24) # 2 rows * 12 bytes/row 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0x18/imm32 # subtract from esp 68/push 0x18/imm32/size 68/push 0/imm32/read 68/push 0/imm32/write 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx # eax = get-or-insert(table, "code", 12 bytes/row, Heap) # . . push args 68/push Heap/imm32 68/push 0xc/imm32/row-size 68/push "code"/imm32 51/push-ecx # . . call e8/call get-or-insert/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp $test-maybe-get:success: # - check for the same key, verify that it was reused # eax = maybe-get(table, "code", 12 bytes/row) # . . push args 68/push 0xc/imm32/row-size 68/push "code"/imm32 51/push-ecx # . . call e8/call maybe-get/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # check-ints-equal(eax - table->data, 8, msg) # . check-ints-equal(eax - table, 20, msg) # . . push args 68/push "F - test-maybe-get/0"/imm32 68/push 0x14/imm32 29/subtract 3/mod/direct 0/rm32/eax . . . 1/r32/ecx . . # subtract ecx from eax 50/push-eax # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # no new row inserted # . check-ints-equal(table->write, row-size = 12, msg) # . . push args 68/push "F - test-maybe-get/1"/imm32 68/push 0xc/imm32/row-size ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . . # push *ecx # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # var curr-addr/eax: (addr array byte) = lookup(table->data) # . . push args ff 6/subop/push 1/mod/*+disp8 1/rm32/ecx . . . . 0x10/disp8 . # push *(ecx+16) ff 6/subop/push 1/mod/*+disp8 1/rm32/ecx . . . . 0xc/disp8 . # push *(ecx+12) # . . call e8/call lookup/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # check-strings-equal(curr-addr, "code", msg) # . . push args 68/push "F - test-maybe-get/2"/imm32 68/push "code"/imm32 50/push-eax # . . call e8/call check-strings-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp $test-maybe-get:failure: # - search for a new key # eax = maybe-get(table, "data", 12 bytes/row) # . . push args 68/push 0xc/imm32/row-size 68/push "data"/imm32 51/push-ecx # . . call e8/call maybe-get/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # check-ints-equal(eax, 0, msg) # . . push args 68/push "F - test-maybe-get/3"/imm32 68/push 0/imm32 50/push-eax # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp $test-maybe-get:end: # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return # if no row is found, return null (0) maybe-get-slice: # table: (addr stream {(handle array byte), T}), key: (addr slice), row-size: int -> result/eax: (addr T) # pseudocode: # curr = table->data # max = &table->data[table->write] # while curr < max # var c: (addr array byte) = lookup(*curr) # if slice-equal?(key, c) # return curr+8 # curr += row-size # return 0 # # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 51/push-ecx 52/push-edx 56/push-esi # esi = table 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi # var curr/ecx: (addr handle array byte) = table->data 8d/copy-address 1/mod/*+disp8 6/rm32/esi . . . 1/r32/ecx 0xc/disp8 . # copy esi+12 to ecx # var max/edx: (addr byte) = &table->data[table->write] 8b/copy 0/mod/indirect 6/rm32/esi . . . 2/r32/edx . . # copy *esi to edx 8d/copy-address 0/mod/indirect 4/rm32/sib 1/base/ecx 2/index/edx . 2/r32/edx . . # copy ecx+edx to edx $maybe-get-slice:search-loop: # if (curr >= max) return null 39/compare 3/mod/direct 1/rm32/ecx . . . 2/r32/edx . . # compare ecx with edx 73/jump-if-addr>= $maybe-get-slice:null/disp8 # var c/eax: (addr array byte) = lookup(*curr) # . . push args ff 6/subop/push 1/mod/*+disp8 1/rm32/ecx . . . . 4/disp8 . # push *(ecx+4) ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . . # push *ecx # . . call e8/call lookup/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # if (slice-equal?(key, c)) return curr+4 # . eax = slice-equal?(key, c) # . . push args 50/push-eax ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 . # push *(ebp+12) # . . call e8/call slice-equal?/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # . if (eax != false) return eax = curr+8 3d/compare-eax-and 0/imm32/false 74/jump-if-= $maybe-get-slice:mismatch/disp8 8d/copy-address 1/mod/*+disp8 1/rm32/ecx . . . 0/r32/eax 8/disp8 . # copy ecx+8 to eax eb/jump $maybe-get-slice:end/disp8 $maybe-get-slice:mismatch: # curr += row-size 03/add 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0x10/disp8 . # add *(ebp+16) to ecx # loop eb/jump $maybe-get-slice:search-loop/disp8 $maybe-get-slice:null: b8/copy-to-eax 0/imm32 $maybe-get-slice:end: # . restore registers 5e/pop-to-esi 5a/pop-to-edx 59/pop-to-ecx # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return test-maybe-get-slice: # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # - setup: create a table with one row # var table/ecx: (stream {string, number} 24) # 2 rows * 12 bytes/row 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0x18/imm32 # subtract from esp 68/push 0x18/imm32/size 68/push 0/imm32/read 68/push 0/imm32/write 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx # insert(table, "code", 12 bytes/row, Heap) # . . push args 68/push Heap/imm32 68/push 0xc/imm32/row-size 68/push "code"/imm32 51/push-ecx # . . call e8/call get-or-insert/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp $test-maybe-get-slice:success: # - check for the same key, verify that it was reused # (eax..edx) = "code" b8/copy-to-eax "code"/imm32 8b/copy 0/mod/indirect 0/rm32/eax . . . 2/r32/edx . . # copy *eax to edx 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 2/index/edx . 2/r32/edx 4/disp8 . # copy eax+edx+4 to edx 05/add-to-eax 4/imm32 # var slice/edx: slice = {eax, edx} 52/push-edx 50/push-eax 89/copy 3/mod/direct 2/rm32/edx . . . 4/r32/esp . . # copy esp to edx # eax = maybe-get-slice(table, "code" slice, 12 bytes/row) # . . push args 68/push 0xc/imm32/row-size 52/push-edx 51/push-ecx # . . call e8/call maybe-get-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # check-ints-equal(eax - table->data, 8, msg) # . check-ints-equal(eax - table, 20, msg) # . . push args 68/push "F - test-maybe-get-slice/0"/imm32 68/push 0x14/imm32 29/subtract 3/mod/direct 0/rm32/eax . . . 1/r32/ecx . . # subtract ecx from eax 50/push-eax # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # no new row inserted # . check-ints-equal(table->write, row-size = 12, msg) # . . push args 68/push "F - test-maybe-get-slice/1"/imm32 68/push 0xc/imm32/row-size ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . . # push *ecx # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # var curr-addr/eax: (addr array byte) = lookup(table->data) # . . push args ff 6/subop/push 1/mod/*+disp8 1/rm32/ecx . . . . 0x10/disp8 . # push *(ecx+16) ff 6/subop/push 1/mod/*+disp8 1/rm32/ecx . . . . 0xc/disp8 . # push *(ecx+12) # . . call e8/call lookup/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # check-strings-equal(curr-addr, "code", msg) # . . push args 68/push "F - test-maybe-get-slice/2"/imm32 68/push "code"/imm32 50/push-eax # . . call e8/call check-strings-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp $test-maybe-get-slice:failure: # - search for a new key # (eax..edx) = "data" b8/copy-to-eax "data"/imm32 8b/copy 0/mod/indirect 0/rm32/eax . . . 2/r32/edx . . # copy *eax to edx 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/eax 2/index/edx . 2/r32/edx 4/disp8 . # copy eax+edx+4 to edx 05/add-to-eax 4/imm32 # var slice/edx: slice = {eax, edx} 52/push-edx 50/push-eax 89/copy 3/mod/direct 2/rm32/edx . . . 4/r32/esp . . # copy esp to edx # eax = maybe-get-slice(table, "data" slice, 12 bytes/row) # . . push args 68/push 0xc/imm32/row-size 52/push-edx 51/push-ecx # . . call e8/call maybe-get-slice/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp # check-ints-equal(eax, 0, msg) # . . push args 68/push "F - test-maybe-get-slice/3"/imm32 68/push 0/imm32 50/push-eax # . . call e8/call check-ints-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp $test-maybe-get-slice:end: # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return # . . vim:nowrap:textwidth=0