From 104e521c04d1a0cad9c68fb11e250e12ad8917ef Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Wed, 17 Oct 2018 07:08:47 -0700 Subject: 4709 --- html/subx/052kernel_string_equal.subx.html | 418 +++++++++++++++-------------- 1 file changed, 210 insertions(+), 208 deletions(-) (limited to 'html/subx/052kernel_string_equal.subx.html') diff --git a/html/subx/052kernel_string_equal.subx.html b/html/subx/052kernel_string_equal.subx.html index 7e72aced..5322761d 100644 --- a/html/subx/052kernel_string_equal.subx.html +++ b/html/subx/052kernel_string_equal.subx.html @@ -77,15 +77,15 @@ if ('onhashchange' in window) { 21 # 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 22 23 # main: (manual test if this is the last file loaded) - 24 e8/call run_tests/disp32 # 'run_tests' is a function created automatically by SubX. It calls all functions that start with 'test_'. - 25 # exit(EAX) - 26 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # copy EAX to EBX - 27 b8/copy . . . . . . . 1/imm32 # copy to EAX + 24 e8/call run-tests/disp32 # 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'. + 25 # exit(Num-test-failures) + 26 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32 # copy *Num-test-failures to EBX + 27 b8/copy-to-EAX 1/imm32 28 cd/syscall 0x80/imm8 29 30 # compare a null-terminated ascii string with a more idiomatic length-prefixed byte array 31 # reason for the name: the only place we should have null-terminated ascii strings is from commandline args - 32 kernel_string_equal: # s : null-terminated ascii string, benchmark : length-prefixed ascii string -> EAX : boolean + 32 kernel-string-equal: # s : null-terminated ascii string, benchmark : length-prefixed ascii string -> EAX : boolean 33 # prolog 34 55/push-EBP 35 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP @@ -109,211 +109,213 @@ if ('onhashchange' in window) { 53 # if c1 != c2 54 # return false 55 # return *s1 == 0 - 56 # initialize s into EDI - 57 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 7/r32/EDI 8/disp8 . # copy *(EBP+8) to EDI - 58 # initialize benchmark length n into EDX - 59 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 2/r32/EDX 0xc/disp8 . # copy *(EBP+12) to EDX - 60 8b/copy 0/mod/indirect 2/rm32/EDX . . . 2/r32/EDX . . # copy *EDX to EDX - 61 # initialize benchmark data into ESI - 62 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 6/r32/ESI 0xc/disp8 . # copy *(EBP+12) to ESI - 63 81 0/subop/add 3/mod/direct 6/rm32/ESI . . . . . 4/imm32 # add to ESI - 64 # initialize loop counter i into ECX - 65 b9/copy . . . . . . . 0/imm32/exit # copy to ECX - 66 # while (i/ECX < n/EDX) - 67 $kernel_string_loop: - 68 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . . # compare ECX with EDX - 69 74/jump-if-equal $kernel_string_break/disp8 - 70 # c1/EAX, c2/EBX = *s, *benchmark - 71 b8/copy 0/imm32 # clear EAX - 72 8a/copy 0/mod/indirect 7/rm32/EDI . . . 0/r32/EAX . . # copy byte at *EDI to lower byte of EAX - 73 bb/copy 0/imm32 # clear EBX - 74 8a/copy 0/mod/indirect 6/rm32/ESI . . . 3/r32/EBX . . # copy byte at *ESI to lower byte of EBX - 75 # if (c1 == 0) return false - 76 3d/compare-EAX 0/imm32 - 77 74/jump-if-equal $kernel_string_fail/disp8 - 78 # if (c1 != c2) return false - 79 39/compare 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . . # compare EAX with EBX - 80 75/jump-if-not-equal $kernel_string_fail/disp8 - 81 # ++s1, ++s2, ++i - 82 41/inc-ECX - 83 46/inc-ESI - 84 47/inc-EDI - 85 # end while - 86 eb/jump $kernel_string_loop/disp8 - 87 $kernel_string_break: - 88 # if (*s/EDI == 0) return true - 89 b8/copy 0/imm32 # clear EAX - 90 8a/copy 0/mod/indirect 7/rm32/EDI . . . 0/r32/EAX . . # copy byte at *EDI to lower byte of EAX - 91 3d/compare-EAX 0/imm32 - 92 75/jump-if-not-equal $kernel_string_fail/disp8 - 93 b8/copy . . . . . . . 1/imm32 # copy to EAX - 94 eb/jump $kernel_string_end/disp8 - 95 # return false - 96 $kernel_string_fail: - 97 b8/copy . . . . . . . 0/imm32 # copy to EAX - 98 - 99 $kernel_string_end: -100 # restore registers -101 5f/pop-to-EDI -102 5e/pop-to-ESI -103 5b/pop-to-EBX -104 5a/pop-to-EDX -105 59/pop-to-ECX -106 # end -107 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP -108 5d/pop-to-EBP -109 c3/return -110 -111 ## tests + 56 # + 57 # initialize s into EDI + 58 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 7/r32/EDI 8/disp8 . # copy *(EBP+8) to EDI + 59 # initialize benchmark length n into EDX + 60 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 2/r32/EDX 0xc/disp8 . # copy *(EBP+12) to EDX + 61 8b/copy 0/mod/indirect 2/rm32/EDX . . . 2/r32/EDX . . # copy *EDX to EDX + 62 # initialize benchmark data into ESI + 63 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . 6/r32/ESI 0xc/disp8 . # copy *(EBP+12) to ESI + 64 81 0/subop/add 3/mod/direct 6/rm32/ESI . . . . . 4/imm32 # add to ESI + 65 # initialize loop counter i into ECX + 66 b9/copy-to-ECX 0/imm32/exit + 67 # while (i/ECX < n/EDX) + 68 $kernel-string-equal:loop: + 69 39/compare 3/mod/direct 1/rm32/ECX . . . 2/r32/EDX . . # compare ECX with EDX + 70 74/jump-if-equal $kernel-string-equal:break/disp8 + 71 # c1/EAX, c2/EBX = *s, *benchmark + 72 b8/copy-to-EAX 0/imm32 + 73 8a/copy 0/mod/indirect 7/rm32/EDI . . . 0/r32/EAX . . # copy byte at *EDI to lower byte of EAX + 74 bb/copy-to-EBX 0/imm32 + 75 8a/copy 0/mod/indirect 6/rm32/ESI . . . 3/r32/EBX . . # copy byte at *ESI to lower byte of EBX + 76 # if (c1 == 0) return false + 77 3d/compare-EAX 0/imm32 + 78 74/jump-if-equal $kernel-string-equal:false/disp8 + 79 # if (c1 != c2) return false + 80 39/compare 3/mod/direct 0/rm32/EAX . . . 3/r32/EBX . . # compare EAX with EBX + 81 75/jump-if-not-equal $kernel-string-equal:false/disp8 + 82 # ++s1, ++s2, ++i + 83 41/inc-ECX + 84 46/inc-ESI + 85 47/inc-EDI + 86 # end while + 87 eb/jump $kernel-string-equal:loop/disp8 + 88 $kernel-string-equal:break: + 89 # if (*s/EDI == 0) return true + 90 b8/copy-to-EAX 0/imm32 + 91 8a/copy 0/mod/indirect 7/rm32/EDI . . . 0/r32/EAX . . # copy byte at *EDI to lower byte of EAX + 92 3d/compare-EAX 0/imm32 + 93 75/jump-if-not-equal $kernel-string-equal:false/disp8 + 94 $kernel-string-equal:true: + 95 b8/copy-to-EAX 1/imm32 + 96 eb/jump $kernel-string-equal:end/disp8 + 97 # return false + 98 $kernel-string-equal:false: + 99 b8/copy-to-EAX 0/imm32 +100 +101 $kernel-string-equal:end: +102 # restore registers +103 5f/pop-to-EDI +104 5e/pop-to-ESI +105 5b/pop-to-EBX +106 5a/pop-to-EDX +107 59/pop-to-ECX +108 # epilog +109 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP +110 5d/pop-to-EBP +111 c3/return 112 -113 test_compare_null_kernel_string_with_empty_array: -114 # EAX = kernel_string_equal(Null_kernel_string, "") -115 # push args -116 68/push ""/imm32 -117 68/push Null_kernel_string/imm32 -118 # call -119 e8/call kernel_string_equal/disp32 -120 # discard args -121 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP -122 # call check_ints_equal(EAX, 1, msg) -123 # push args -124 68/push "F - test_compare_null_kernel_string_with_empty_array"/imm32 -125 68/push 1/imm32/true -126 50/push-EAX -127 # call -128 e8/call check_ints_equal/disp32 -129 # discard args -130 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP -131 c3/return -132 -133 test_compare_null_kernel_string_with_non_empty_array: -134 # EAX = kernel_string_equal(Null_kernel_string, "Abc") -135 # push args -136 68/push "Abc"/imm32 -137 68/push Null_kernel_string/imm32 -138 # call -139 e8/call kernel_string_equal/disp32 -140 # discard args -141 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP -142 # call check_ints_equal(EAX, 0, msg) -143 # push args -144 68/push "F - test_compare_null_kernel_string_with_non_empty_array"/imm32 -145 68/push 0/imm32/false -146 50/push-EAX -147 # call -148 e8/call check_ints_equal/disp32 -149 # discard args -150 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP -151 c3/return -152 -153 test_compare_kernel_string_with_equal_array: -154 # EAX = kernel_string_equal(Abc_kernel_string, "Abc") -155 # push args -156 68/push "Abc"/imm32 -157 68/push Abc_kernel_string/imm32 -158 # call -159 e8/call kernel_string_equal/disp32 -160 # discard args -161 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP -162 # call check_ints_equal(EAX, 1, msg) -163 # push args -164 68/push "F - test_compare_kernel_string_with_equal_array"/imm32 -165 68/push 1/imm32/true -166 50/push-EAX -167 # call -168 e8/call check_ints_equal/disp32 -169 # discard args -170 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP -171 c3/return -172 -173 test_compare_kernel_string_with_inequal_array: -174 # EAX = kernel_string_equal(Abc_kernel_string, "Adc") -175 # push args -176 68/push "Adc"/imm32 -177 68/push Abc_kernel_string/imm32 -178 # call -179 e8/call kernel_string_equal/disp32 -180 # discard args -181 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP -182 # call check_ints_equal(EAX, 0, msg) -183 # push args -184 68/push "F - test_compare_kernel_string_with_equal_array"/imm32 -185 68/push 0/imm32/false -186 50/push-EAX -187 # call -188 e8/call check_ints_equal/disp32 -189 # discard args -190 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP -191 c3/return -192 -193 test_compare_kernel_string_with_empty_array: -194 # EAX = kernel_string_equal(Abc_kernel_string, "") -195 # push args -196 68/push ""/imm32 -197 68/push Abc_kernel_string/imm32 -198 # call -199 e8/call kernel_string_equal/disp32 -200 # discard args -201 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP -202 # call check_ints_equal(EAX, 0) -203 # push args -204 68/push "F - test_compare_kernel_string_with_equal_array"/imm32 -205 68/push 0/imm32/false -206 50/push-EAX -207 # call -208 e8/call check_ints_equal/disp32 -209 # discard args -210 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP -211 c3/return -212 -213 test_compare_kernel_string_with_shorter_array: -214 # EAX = kernel_string_equal(Abc_kernel_string, "Ab") -215 # push args -216 68/push "Ab"/imm32 -217 68/push Abc_kernel_string/imm32 -218 # call -219 e8/call kernel_string_equal/disp32 -220 # discard args -221 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP -222 # call check_ints_equal(EAX, 0) -223 # push args -224 68/push "F - test_compare_kernel_string_with_shorter_array"/imm32 -225 68/push 0/imm32/false -226 50/push-EAX -227 # call -228 e8/call check_ints_equal/disp32 -229 # discard args -230 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP -231 c3/return -232 -233 test_compare_kernel_string_with_longer_array: -234 # EAX = kernel_string_equal(Abc_kernel_string, "Abcd") -235 # push args -236 68/push "Abcd"/imm32 -237 68/push Abc_kernel_string/imm32 -238 # call -239 e8/call kernel_string_equal/disp32 -240 # discard args -241 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP -242 # call check_ints_equal(EAX, 0) -243 # push args -244 68/push "F - test_compare_kernel_string_with_longer_array"/imm32 -245 68/push 0/imm32/false -246 50/push-EAX -247 # call -248 e8/call check_ints_equal/disp32 -249 # discard args -250 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP -251 c3/return -252 -253 == data +113 ## tests +114 +115 test-compare-null-kernel-string-with-empty-array: +116 # EAX = kernel-string-equal(Null-kernel-string, "") +117 # push args +118 68/push ""/imm32 +119 68/push Null-kernel-string/imm32 +120 # call +121 e8/call kernel-string-equal/disp32 +122 # discard args +123 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +124 # call check-ints-equal(EAX, 1, msg) +125 # push args +126 68/push "F - test-compare-null-kernel-string-with-empty-array"/imm32 +127 68/push 1/imm32/true +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 c3/return +134 +135 test-compare-null-kernel-string-with-non-empty-array: +136 # EAX = kernel-string-equal(Null-kernel-string, "Abc") +137 # push args +138 68/push "Abc"/imm32 +139 68/push Null-kernel-string/imm32 +140 # call +141 e8/call kernel-string-equal/disp32 +142 # discard args +143 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +144 # call check-ints-equal(EAX, 0, msg) +145 # push args +146 68/push "F - test-compare-null-kernel-string-with-non-empty-array"/imm32 +147 68/push 0/imm32/false +148 50/push-EAX +149 # call +150 e8/call check-ints-equal/disp32 +151 # discard args +152 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP +153 c3/return +154 +155 test-compare-kernel-string-with-equal-array: +156 # EAX = kernel-string-equal(Abc-kernel-string, "Abc") +157 # push args +158 68/push "Abc"/imm32 +159 68/push Abc-kernel-string/imm32 +160 # call +161 e8/call kernel-string-equal/disp32 +162 # discard args +163 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +164 # call check-ints-equal(EAX, 1, msg) +165 # push args +166 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 +167 68/push 1/imm32/true +168 50/push-EAX +169 # call +170 e8/call check-ints-equal/disp32 +171 # discard args +172 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP +173 c3/return +174 +175 test-compare-kernel-string-with-inequal-array: +176 # EAX = kernel-string-equal(Abc-kernel-string, "Adc") +177 # push args +178 68/push "Adc"/imm32 +179 68/push Abc-kernel-string/imm32 +180 # call +181 e8/call kernel-string-equal/disp32 +182 # discard args +183 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +184 # call check-ints-equal(EAX, 0, msg) +185 # push args +186 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 +187 68/push 0/imm32/false +188 50/push-EAX +189 # call +190 e8/call check-ints-equal/disp32 +191 # discard args +192 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP +193 c3/return +194 +195 test-compare-kernel-string-with-empty-array: +196 # EAX = kernel-string-equal(Abc-kernel-string, "") +197 # push args +198 68/push ""/imm32 +199 68/push Abc-kernel-string/imm32 +200 # call +201 e8/call kernel-string-equal/disp32 +202 # discard args +203 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +204 # call check-ints-equal(EAX, 0) +205 # push args +206 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 +207 68/push 0/imm32/false +208 50/push-EAX +209 # call +210 e8/call check-ints-equal/disp32 +211 # discard args +212 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP +213 c3/return +214 +215 test-compare-kernel-string-with-shorter-array: +216 # EAX = kernel-string-equal(Abc-kernel-string, "Ab") +217 # push args +218 68/push "Ab"/imm32 +219 68/push Abc-kernel-string/imm32 +220 # call +221 e8/call kernel-string-equal/disp32 +222 # discard args +223 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +224 # call check-ints-equal(EAX, 0) +225 # push args +226 68/push "F - test-compare-kernel-string-with-shorter-array"/imm32 +227 68/push 0/imm32/false +228 50/push-EAX +229 # call +230 e8/call check-ints-equal/disp32 +231 # discard args +232 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP +233 c3/return +234 +235 test-compare-kernel-string-with-longer-array: +236 # EAX = kernel-string-equal(Abc-kernel-string, "Abcd") +237 # push args +238 68/push "Abcd"/imm32 +239 68/push Abc-kernel-string/imm32 +240 # call +241 e8/call kernel-string-equal/disp32 +242 # discard args +243 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +244 # call check-ints-equal(EAX, 0) +245 # push args +246 68/push "F - test-compare-kernel-string-with-longer-array"/imm32 +247 68/push 0/imm32/false +248 50/push-EAX +249 # call +250 e8/call check-ints-equal/disp32 +251 # discard args +252 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP +253 c3/return 254 -255 Null_kernel_string: -256 00/null -257 Abc_kernel_string: -258 41/A 62/b 63/c 00/null -259 -260 # vim:ft=subx:nowrap:tw& +255 == data +256 +257 Null-kernel-string: +258 00/null +259 Abc-kernel-string: +260 41/A 62/b 63/c 00/null +261 +262 # vim:nowrap:textwidth=0 -- cgit 1.4.1-2-gfad0