parent
0d0af0ab1f
commit
21cb677f3b
|
@ -15,22 +15,20 @@ Entry: # run all tests
|
||||||
|
|
||||||
string-equal?: # s : (address string), benchmark : (address string) -> EAX : boolean
|
string-equal?: # s : (address string), benchmark : (address string) -> EAX : boolean
|
||||||
# pseudocode:
|
# pseudocode:
|
||||||
# lens = s->length
|
# if (s->length != benchmark->length) return false
|
||||||
# if (lens != benchmark->length) return false
|
|
||||||
# i = 0
|
|
||||||
# currs = s->data
|
# currs = s->data
|
||||||
# currb = benchmark->data
|
# currb = benchmark->data
|
||||||
# while i < s->length
|
# maxs = s->data + s->length
|
||||||
|
# while currs < maxs
|
||||||
# c1 = *currs
|
# c1 = *currs
|
||||||
# c2 = *currb
|
# c2 = *currb
|
||||||
# if (c1 != c2) return false
|
# if (c1 != c2) return false
|
||||||
# ++i, ++currs, ++currb
|
# ++currs, ++currb
|
||||||
# return true
|
# return true
|
||||||
#
|
#
|
||||||
# registers:
|
# registers:
|
||||||
# i: ECX
|
|
||||||
# lens: EDX
|
|
||||||
# currs: ESI
|
# currs: ESI
|
||||||
|
# maxs: ECX
|
||||||
# currb: EDI
|
# currb: EDI
|
||||||
# c1: EAX
|
# c1: EAX
|
||||||
# c2: EBX
|
# c2: EBX
|
||||||
|
@ -41,40 +39,38 @@ string-equal?: # s : (address string), benchmark : (address string) -> EAX : bo
|
||||||
# . save registers
|
# . save registers
|
||||||
51/push-ECX
|
51/push-ECX
|
||||||
52/push-EDX
|
52/push-EDX
|
||||||
53/push-EBX
|
|
||||||
56/push-ESI
|
56/push-ESI
|
||||||
57/push-EDI
|
57/push-EDI
|
||||||
# ESI = s
|
# ESI = s
|
||||||
8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 8/disp8 . # copy *(EBP+8) to ESI
|
8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 6/r32/ESI 8/disp8 . # copy *(EBP+8) to ESI
|
||||||
# EDI = benchmark
|
# EDI = benchmark
|
||||||
8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 0xc/disp8 . # copy *(EBP+12) to EDI
|
8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 7/r32/EDI 0xc/disp8 . # copy *(EBP+12) to EDI
|
||||||
# lens/EDX = s->length
|
# ECX = s->length
|
||||||
8b/copy 0/mod/indirect 6/rm32/ESI . . . 2/r32/EDX . . # copy *ESI to EDX
|
8b/copy 0/mod/indirect 6/rm32/ESI . . . 1/r32/ECX . . # copy *ESI to ECX
|
||||||
$string-equal?:lengths:
|
$string-equal?:lengths:
|
||||||
# if (lens != benchmark->length) return false
|
# if (ECX != benchmark->length) return false
|
||||||
39/compare 0/mod/indirect 7/rm32/EDI . . . 2/r32/EDX . . # compare *EDI and EDX
|
39/compare 0/mod/indirect 7/rm32/EDI . . . 1/r32/ECX . . # compare *EDI and ECX
|
||||||
75/jump-if-not-equal $string-equal?:false/disp8
|
75/jump-if-not-equal $string-equal?:false/disp8
|
||||||
# currs/ESI = s->data
|
# currs/ESI = s->data
|
||||||
81 0/subop/add 3/mod/direct 6/rm32/ESI . . . . . 4/imm32 # add to ESI
|
81 0/subop/add 3/mod/direct 6/rm32/ESI . . . . . 4/imm32 # add to ESI
|
||||||
|
# maxs/ECX = s->data + s->length
|
||||||
|
01/add 3/mod/direct 1/rm32/ECX . . . 6/r32/ESI . . # add ESI to ECX
|
||||||
# currb/EDI = benchmark->data
|
# currb/EDI = benchmark->data
|
||||||
81 0/subop/add 3/mod/direct 7/rm32/EDI . . . . . 4/imm32 # add to EDI
|
81 0/subop/add 3/mod/direct 7/rm32/EDI . . . . . 4/imm32 # add to EDI
|
||||||
# i/ECX = c1/EAX = c2/EBX = 0
|
# c1/EAX = c2/EDX = 0
|
||||||
31/xor 3/mod/direct 1/rm32/ECX . . . 1/r32/ECX . . # clear ECX
|
|
||||||
31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . . # clear EAX
|
31/xor 3/mod/direct 0/rm32/EAX . . . 0/r32/EAX . . # clear EAX
|
||||||
31/xor 3/mod/direct 3/rm32/EBX . . . 3/r32/EBX . . # clear EBX
|
31/xor 3/mod/direct 2/rm32/EDX . . . 2/r32/EDX . . # clear EDX
|
||||||
$string-equal?:loop:
|
$string-equal?:loop:
|
||||||
# if (i >= lens) return true
|
# if (currs >= maxs) return true
|
||||||
39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . . # compare ECX with EDX
|
39/compare 3/mod/direct 6/rm32/ESI . . . 1/r32/ECX . . # compare ESI with ECX
|
||||||
7d/jump-if-greater-or-equal $string-equal?:true/disp8
|
7d/jump-if-greater-or-equal $string-equal?:true/disp8
|
||||||
# c1 = *currs
|
# c1 = *currs
|
||||||
8a/copy-byte 0/mod/indirect 6/rm32/ESI . . . 0/r32/AL . . # copy byte at *ESI to AL
|
8a/copy-byte 0/mod/indirect 6/rm32/ESI . . . 0/r32/AL . . # copy byte at *ESI to AL
|
||||||
# c2 = *currb
|
# c2 = *currb
|
||||||
8a/copy-byte 0/mod/indirect 7/rm32/EDI . . . 3/r32/BL . . # copy byte at *EDI to BL
|
8a/copy-byte 0/mod/indirect 7/rm32/EDI . . . 2/r32/DL . . # copy byte at *EDI to DL
|
||||||
# if (c1 != c2) return false
|
# if (c1 != c2) return false
|
||||||
39/compare 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . . # compare EAX and EBX
|
39/compare 3/mod/direct 0/rm32/EAX . . . 2/r32/EDX . . # compare EAX and EDX
|
||||||
75/jump-if-not-equal $string-equal?:false/disp8
|
75/jump-if-not-equal $string-equal?:false/disp8
|
||||||
# ++i
|
|
||||||
41/increment-ECX
|
|
||||||
# ++currs
|
# ++currs
|
||||||
46/increment-ESI
|
46/increment-ESI
|
||||||
# ++currb
|
# ++currb
|
||||||
|
@ -89,7 +85,6 @@ $string-equal?:end:
|
||||||
# . restore registers
|
# . restore registers
|
||||||
5f/pop-to-EDI
|
5f/pop-to-EDI
|
||||||
5e/pop-to-ESI
|
5e/pop-to-ESI
|
||||||
5b/pop-to-EBX
|
|
||||||
5a/pop-to-EDX
|
5a/pop-to-EDX
|
||||||
59/pop-to-ECX
|
59/pop-to-ECX
|
||||||
# . epilog
|
# . epilog
|
||||||
|
|
BIN
subx/apps/assort
BIN
subx/apps/assort
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
subx/apps/handle
BIN
subx/apps/handle
Binary file not shown.
BIN
subx/apps/hex
BIN
subx/apps/hex
Binary file not shown.
BIN
subx/apps/pack
BIN
subx/apps/pack
Binary file not shown.
BIN
subx/apps/survey
BIN
subx/apps/survey
Binary file not shown.
Loading…
Reference in New Issue