about summary refs log tree commit diff stats
path: root/subx/apps/factorial.subx
diff options
context:
space:
mode:
Diffstat (limited to 'subx/apps/factorial.subx')
-rw-r--r--subx/apps/factorial.subx22
1 files changed, 11 insertions, 11 deletions
diff --git a/subx/apps/factorial.subx b/subx/apps/factorial.subx
index 9b014313..d223b692 100644
--- a/subx/apps/factorial.subx
+++ b/subx/apps/factorial.subx
@@ -23,7 +23,7 @@
   # prolog
   89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
   # if (argc > 1)
-  81          7/subop/compare     1/mod/*+disp8   4/rm32/SIB    5/base/EBP  4/index/none  .           .           0/disp8         1/imm32           # compare *EBP with 1
+  81          7/subop/compare     1/mod/*+disp8   4/rm32/SIB    5/base/EBP  4/index/none  .           .           0/disp8         1/imm32           # compare *EBP
   7e/jump-if-lesser-or-equal  $run_main/disp8
   # and if (argv[1] == "test")
     # push args
@@ -32,9 +32,9 @@
     # call
   e8/call  kernel_string_equal/disp32
     # discard args
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add 8 to ESP
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
     # check result
-  3d/compare                      .               .             .           .             .           .           .               1/imm32           # compare EAX with 1
+  3d/compare-EAX  1/imm32
   75/jump-if-not-equal  $run_main/disp8
   # then
   e8/call  run_tests/disp32
@@ -46,11 +46,11 @@ $run_main:
     # EAX <- call
   e8/call  factorial/disp32
     # discard arg
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add 4 to ESP
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
 $main_exit:
   # exit(EAX)
   89/copy                         3/mod/direct    3/rm32/EBX    .           .             .           0/r32/EAX   .               .                 # copy EAX to EBX
-  b8/copy                         .               .             .           .             .           .           .               1/imm32           # copy 1 to EAX
+  b8/copy                         .               .             .           .             .           .           .               1/imm32           # copy to EAX
   cd/syscall  0x80/imm8
 
 # factorial(n)
@@ -60,18 +60,18 @@ factorial:
   89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
   53/push-EBX
   # initialize EAX to 1 (base case)
-  b8/copy                         .               .             .           .             .           .           .               1/imm32           # copy 1 to EAX
+  b8/copy                         .               .             .           .             .           .           .               1/imm32           # copy to EAX
   # if (n <= 1) jump exit
-  81          7/subop/compare     1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           .           8/disp8         1/imm32           # compare *(EBP+8) with 1
+  81          7/subop/compare     1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none  .           .           8/disp8         1/imm32           # compare *(EBP+8)
   7e/jump-if-<=  $factorial:exit/disp8
   # EBX: n-1
   8b/copy                         1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none              3/r32/EBX   8/disp8         .                 # copy *(EBP+8) to EBX
-  81          5/subop/subtract    3/mod/direct    3/rm32/EBX    .           .             .           .           .               1/imm32           # subtract 1 from EBX
+  81          5/subop/subtract    3/mod/direct    3/rm32/EBX    .           .             .           .           .               1/imm32           # subtract from EBX
   # EAX: factorial(n-1)
   53/push-EBX
   e8/call                         .               .             .           .             .           .           factorial/disp32
   # discard arg
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add 4 to ESP
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
   # return n * factorial(n-1)
   f7          4/subop/multiply    1/mod/*+disp8   4/rm32/sib    5/base/EBP  4/index/none                          8/disp8         .                 # multiply *(EBP+8) into EAX
   # TODO: check for overflow
@@ -89,7 +89,7 @@ test_factorial:
     # call
   e8/call  factorial/disp32
     # discard arg
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add 4 to ESP
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
   # check_ints_equal(EAX, 120, failure message)
     # push args
   68/push  "F - test_factorial"/imm32
@@ -98,7 +98,7 @@ test_factorial:
     # call
   e8/call  check_ints_equal/disp32
     # discard args
-  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add 12 to ESP
+  81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
   # end
   c3/return
 
?h=v1.5.4&id=e952d6cb8e67f80fcd2019abf3d30b20dc5b9f7c'>e952d6cb ^
36e4e71e ^

4a383291 ^
78a7d762 ^
e952d6cb ^
78a7d762 ^
e952d6cb ^
4ea0f69a ^

7838675f ^


4a383291 ^

7838675f ^



755e7df1 ^
7838675f ^
500cf259 ^



bf14a7e7 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90