5809
This commit is contained in:
parent
af14739222
commit
ef21004a5c
|
@ -45,8 +45,8 @@ Entry: # run tests if necessary, compute `factorial(5)` if not
|
|||
e8/call kernel-string-equal?/disp32
|
||||
# . . discard args
|
||||
81 0/subop/add %esp 8/imm32
|
||||
# . if (eax == 0) goto run-main
|
||||
3d/compare-eax-and 0/imm32
|
||||
# . if (eax == false) goto run-main
|
||||
3d/compare-eax-and 0/imm32/false
|
||||
74/jump-if-equal $run-main/disp8
|
||||
# run-tests()
|
||||
e8/call run-tests/disp32
|
||||
|
@ -77,10 +77,10 @@ factorial: # n : int -> int/eax
|
|||
b8/copy-to-eax 1/imm32
|
||||
81 7/subop/compare *(ebp+8) 1/imm32
|
||||
7e/jump-if-<= $factorial:end/disp8
|
||||
# ebx = n-1
|
||||
# var ebx : int = n-1
|
||||
8b/-> *(ebp+8) 3/r32/ebx
|
||||
4b/decrement-ebx
|
||||
# eax = factorial(n-1)
|
||||
# var eax : int = factorial(n-1)
|
||||
# . . push args
|
||||
53/push-ebx
|
||||
# . . call
|
||||
|
|
|
@ -32,8 +32,8 @@ Entry: # run tests if necessary, compute `factorial(5)` if not
|
|||
7e/jump-if-lesser-or-equal $run-main/disp8
|
||||
# if (!kernel-string-equal?(argv[1], "test")) goto run-main
|
||||
(kernel-string-equal? *(ebp+8) "test") # => eax
|
||||
# . if (eax == 0) goto run-main
|
||||
3d/compare-eax-and 0/imm32
|
||||
# . if (eax == false) goto run-main
|
||||
3d/compare-eax-and 0/imm32/false
|
||||
74/jump-if-equal $run-main/disp8
|
||||
#
|
||||
(run-tests)
|
||||
|
@ -59,7 +59,7 @@ factorial: # n : int -> int/eax
|
|||
b8/copy-to-eax 1/imm32
|
||||
81 7/subop/compare *(ebp+8) 1/imm32
|
||||
7e/jump-if-<= $factorial:end/disp8
|
||||
# ebx = n-1
|
||||
# var ebx : int = n-1
|
||||
8b/-> *(ebp+8) 3/r32/ebx
|
||||
4b/decrement-ebx
|
||||
#
|
||||
|
|
|
@ -34,7 +34,7 @@ Entry: # run tests if necessary, compute `factorial(5)` if not
|
|||
7e/jump-if-lesser-or-equal break/disp8
|
||||
# if (!kernel-string-equal?(argv[1], "test")) break
|
||||
(kernel-string-equal? *(ebp+8) "test") # => eax
|
||||
3d/compare-eax-and 0/imm32
|
||||
3d/compare-eax-and 0/imm32/false
|
||||
74/jump-if-equal break/disp8
|
||||
#
|
||||
(run-tests)
|
||||
|
@ -70,6 +70,7 @@ factorial: # n : int -> int/eax
|
|||
# if (n > 1) return n * factorial(n-1)
|
||||
{
|
||||
7e/jump-if-lesser-or-equal break/disp8
|
||||
# var ebx : int = n-1
|
||||
8b/-> *(ebp+8) 3/r32/ebx
|
||||
4b/decrement-ebx
|
||||
(factorial %ebx) # => eax
|
||||
|
|
Loading…
Reference in New Issue