# Comparing 'regular' size-prefixed strings. == code # instruction effective address register displacement immediate # . 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 Entry: # run all tests #? e8/call test-compare-equal-strings/disp32 e8/call run-tests/disp32 # 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'. # 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 e8/call syscall_exit/disp32 string-equal?: # s: (addr array byte), benchmark: (addr array byte) -> result/eax: boolean # pseudocode: # if (s->size != benchmark->size) return false # return string-starts-with?(s, benchmark) # # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 51/push-ecx 56/push-esi 57/push-edi # esi = s 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 6/r32/esi 8/disp8 . # copy *(ebp+8) to esi # edi = benchmark 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 7/r32/edi 0xc/disp8 . # copy *(ebp+12) to edi # ecx = s->size 8b/copy 0/mod/indirect 6/rm32/esi . . . 1/r32/ecx . . # copy *esi to ecx $string-equal?:sizes: # if (ecx != benchmark->size) return false 39/compare 0/mod/indirect 7/rm32/edi . . . 1/r32/ecx . . # compare *edi and ecx b8/copy-to-eax 0/imm32/false 75/jump-if-!= $string-equal?:end/disp8 $string-equal?:contents: # string-starts-with?(s, benchmark) # . . 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 . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call string-starts-with?/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp $string-equal?:end: # . restore registers 5f/pop-to-edi 5e/pop-to-esi 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 string-starts-with?: # s: (addr array byte), benchmark: (addr array byte) -> result/eax: boolean # pseudocode: # if (s->size < benchmark->size) return false # currs = s->data # currb = benchmark->data # maxb = &benchmark->data[benchmark->size] # while currb < maxb #
// "a type" "needed cpp_includes"
"vector" "#include <vector>
using namespace std;"

"list" "#include <list>
using namespace std;"

"map" "#include <map>
using namespace std;"

"string" "#include <string>
using namespace std;"
. push args 68/push "F - test-compare-equal-strings"/imm32 68/push 1/imm32/true 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 c3/return test-compare-inequal-strings-equal-sizes: # eax = string-equal?("Abc", "Adc") # . . push args 68/push "Adc"/imm32 68/push "Abc"/imm32 # . . call e8/call string-equal?/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # check-ints-equal(eax, 0, msg) # . . push args 68/push "F - test-compare-inequal-strings-equal-sizes"/imm32 68/push 0/imm32/false 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 c3/return # helper for later tests check-strings-equal: # s: (addr array byte), expected: (addr array byte), msg: (addr array byte) # . prologue 55/push-ebp 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp # . save registers 50/push-eax # var eax: boolean = string-equal?(s, expected) # . . 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 . . . . 8/disp8 . # push *(ebp+8) # . . call e8/call string-equal?/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # check-ints-equal(eax, 1, msg) # . . push args ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x10/disp8 . # push *(ebp+16) 68/push 1/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 $check-strings-equal:end: # . restore registers 58/pop-to-eax # . epilogue 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp 5d/pop-to-ebp c3/return # test the helper test-check-strings-equal: # check-strings-equal?("Abc", "Abc") # . . push args 68/push "Abc"/imm32 68/push "Abc"/imm32 # . . call e8/call check-strings-equal/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp c3/return # . . vim:nowrap:textwidth=0