From 5a2cb154eb016aa8b84ad939f63eb56dd7a0a90f Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 2 Oct 2018 01:21:01 -0700 Subject: 4649 --- html/subx/examples/ex9.subx.html | 59 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'html/subx/examples/ex9.subx.html') diff --git a/html/subx/examples/ex9.subx.html b/html/subx/examples/ex9.subx.html index 78d8323e..882f6b51 100644 --- a/html/subx/examples/ex9.subx.html +++ b/html/subx/examples/ex9.subx.html @@ -58,9 +58,9 @@ if ('onhashchange' in window) { 2 # Show difference between ascii codes of first letter of first arg and first 3 # letter of second arg. 4 # - 5 # To run: - 6 # $ subx translate ex9.subx ex9 - 7 # $ subx run ex9 z x + 5 # To run (from the subx directory): + 6 # $ subx translate examples/ex9.subx -o examples/ex9 + 7 # $ subx run examples/ex9 z x 8 # Expected result: 9 # $ echo $? 10 # 2 @@ -76,33 +76,32 @@ if ('onhashchange' in window) { 20 # instruction effective address operand displacement immediate 21 # op subop mod rm32 base index scale r32 22 # 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 -23 # s1 = argv[1] (EAX) -24 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 0/r32/EAX 8/disp8 . # copy *(ESP+8) to EAX -25 # s2 = argv[2] (EBX) -26 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 3/r32/EBX 0xc/disp8 . # copy *(ESP+12) to EBX -27 # call string_equal(s1, s2) -28 # push args -29 50/push-EAX -30 53/push-EBX -31 # call -32 e8/call ascii_difference/disp32 -33 # discard args -34 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add 8 to ESP -35 # exit(EAX) -36 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # copy EAX to EBX -37 b8/copy . . . . . . . 1/imm32/exit # copy 1 to EAX -38 cd/syscall 0x80/imm8 -39 -40 ascii_difference: # (s1, s2) : null-terminated ascii strings -41 # a = first letter of s1 (ECX) -42 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 0/r32/EAX 8/disp8 . # copy *(ESP+8) to EAX -43 8b/copy 0/mod/indirect 0/rm32/EAX . . . 0/r32/EAX . . # copy *EAX to EAX -44 # b = first letter of s2 (EDX) -45 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 1/r32/ECX 4/disp8 # copy *(ESP+4) to ECX -46 8b/copy 0/mod/indirect 1/rm32/ECX . . . 1/r32/ECX . . # copy *ECX to ECX -47 # a-b -48 29/subtract 3/mod/direct 0/rm32/EAX . . . 1/r32/ECX . . # subtract ECX from EAX -49 c3/return +23 # prolog +24 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP +25 # call ascii_difference(argv[1], argv[2]) +26 # push argv[2] +27 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0xc/disp8 . # push *(EBP+12) +28 # push argv[1] +29 ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none . . 0x8/disp8 . # push *(EBP+8) +30 # call +31 e8/call ascii_difference/disp32 +32 # discard args +33 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +34 # exit(EAX) +35 89/copy 3/mod/direct 3/rm32/EBX . . . 0/r32/EAX . . # copy EAX to EBX +36 b8/copy . . . . . . . 1/imm32/exit # copy to EAX +37 cd/syscall 0x80/imm8 +38 +39 ascii_difference: # (s1, s2) : null-terminated ascii strings +40 # a = first letter of s1 (ECX) +41 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 0/r32/EAX 4/disp8 . # copy *(ESP+4) to EAX +42 8b/copy 0/mod/indirect 0/rm32/EAX . . . 0/r32/EAX . . # copy *EAX to EAX +43 # b = first letter of s2 (EDX) +44 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 1/r32/ECX 8/disp8 # copy *(ESP+8) to ECX +45 8b/copy 0/mod/indirect 1/rm32/ECX . . . 1/r32/ECX . . # copy *ECX to ECX +46 # a-b +47 29/subtract 3/mod/direct 0/rm32/EAX . . . 1/r32/ECX . . # subtract ECX from EAX +48 c3/return -- cgit 1.4.1-2-gfad0