From 34c84469c23a5a0acf6f26c2c163a506d013d7ac Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Tue, 2 Oct 2018 14:33:08 -0700 Subject: 4654 --- html/subx/apps/factorial.subx.html | 78 +++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 38 deletions(-) (limited to 'html/subx/apps') diff --git a/html/subx/apps/factorial.subx.html b/html/subx/apps/factorial.subx.html index cbb66b9e..7111a908 100644 --- a/html/subx/apps/factorial.subx.html +++ b/html/subx/apps/factorial.subx.html @@ -95,11 +95,11 @@ if ('onhashchange' in window) { 39 # then 40 e8/call run_tests/disp32 41 eb/jump $main_exit/disp8 - 42 # else EAX <- factorial(5) + 42 # else EAX = factorial(5) 43 $run_main: 44 # push arg 45 68/push 5/imm32 - 46 # EAX <- call + 46 # call 47 e8/call factorial/disp32 48 # discard arg 49 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP @@ -123,42 +123,44 @@ if ('onhashchange' in window) { 67 # EBX: n-1 68 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 3/r32/EBX 8/disp8 . # copy *(EBP+8) to EBX 69 81 5/subop/subtract 3/mod/direct 3/rm32/EBX . . . . . 1/imm32 # subtract from EBX - 70 # EAX: factorial(n-1) - 71 53/push-EBX - 72 e8/call . . . . . . factorial/disp32 - 73 # discard arg - 74 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP - 75 # return n * factorial(n-1) - 76 f7 4/subop/multiply 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 8/disp8 . # multiply *(EBP+8) into EAX - 77 # TODO: check for overflow - 78 $factorial:exit: - 79 # epilog - 80 5b/pop-to-EBX - 81 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP - 82 5d/pop-to-EBP - 83 c3/return - 84 - 85 test_factorial: - 86 # factorial(5) - 87 # push arg - 88 68/push 5/imm32 - 89 # call - 90 e8/call factorial/disp32 - 91 # discard arg - 92 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP - 93 # check_ints_equal(EAX, 120, failure message) - 94 # push args - 95 68/push "F - test_factorial"/imm32 - 96 68/push 0x78/imm32/expected-120 - 97 50/push-EAX - 98 # call - 99 e8/call check_ints_equal/disp32 -100 # discard args -101 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP -102 # end -103 c3/return -104 -105 # vim:ft=subx:nowrap:so=0 + 70 # EAX = factorial(n-1) + 71 # push args + 72 53/push-EBX + 73 # call + 74 e8/call . . . . . . factorial/disp32 + 75 # discard arg + 76 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + 77 # return n * factorial(n-1) + 78 f7 4/subop/multiply 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 8/disp8 . # multiply *(EBP+8) into EAX + 79 # TODO: check for overflow + 80 $factorial:exit: + 81 # epilog + 82 5b/pop-to-EBX + 83 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP + 84 5d/pop-to-EBP + 85 c3/return + 86 + 87 test_factorial: + 88 # factorial(5) + 89 # push arg + 90 68/push 5/imm32 + 91 # call + 92 e8/call factorial/disp32 + 93 # discard arg + 94 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32 # add to ESP + 95 # check_ints_equal(EAX, 120, failure message) + 96 # push args + 97 68/push "F - test_factorial"/imm32 + 98 68/push 0x78/imm32/expected-120 + 99 50/push-EAX +100 # call +101 e8/call check_ints_equal/disp32 +102 # discard args +103 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32 # add to ESP +104 # end +105 c3/return +106 +107 # vim:ft=subx:nowrap:so=0 -- cgit 1.4.1-2-gfad0