From ef21004a5c5b655b7e352f658a8368986ac1c1df Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 9 Dec 2019 16:53:57 -0800 Subject: 5809 --- apps/factorial2.subx | 8 ++++---- apps/factorial3.subx | 6 +++--- apps/factorial4.subx | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/factorial2.subx b/apps/factorial2.subx index ecaccbcf..e512521a 100644 --- a/apps/factorial2.subx +++ b/apps/factorial2.subx @@ -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 diff --git a/apps/factorial3.subx b/apps/factorial3.subx index 6cfd38c3..7a8cee8c 100644 --- a/apps/factorial3.subx +++ b/apps/factorial3.subx @@ -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 # diff --git a/apps/factorial4.subx b/apps/factorial4.subx index 2752dfd0..1881c79d 100644 --- a/apps/factorial4.subx +++ b/apps/factorial4.subx @@ -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 -- cgit 1.4.1-2-gfad0