about summary refs log tree commit diff stats
path: root/406try-divide.mu
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-11-02 00:07:07 -0800
committerKartik Agaram <vc@akkartik.com>2020-11-02 00:07:07 -0800
commit951c3f4c92358d3962154a4ef24a19366ea8a619 (patch)
treee458ba9bd3e7759c24fd7850c56472fd62662078 /406try-divide.mu
parentc8e41a470f1c3ee1dbf7b881a3dec31633e39085 (diff)
downloadmu-951c3f4c92358d3962154a4ef24a19366ea8a619.tar.gz
7158
Diffstat (limited to '406try-divide.mu')
-rw-r--r--406try-divide.mu27
1 files changed, 16 insertions, 11 deletions
diff --git a/406try-divide.mu b/406try-divide.mu
index fce7b529..e5034e55 100644
--- a/406try-divide.mu
+++ b/406try-divide.mu
@@ -1,6 +1,6 @@
 # slow, iterative divide instruction
 # preconditions: _nr >= 0, _dr > 0
-fn try-divide _nr: int, _dr: int -> result/eax: int {
+fn try-divide _nr: int, _dr: int -> _/eax: int {
   # x = next power-of-2 multiple of _dr after _nr
   var x/ecx: int <- copy 1
   {
@@ -30,11 +30,12 @@ fn try-divide _nr: int, _dr: int -> result/eax: int {
     i <- increment
     loop
   }
-  result <- copy i
+  var result/eax: int <- copy i
   result <- decrement
 #?   print-string 0, "=> "
 #?   print-int32-hex 0, result
 #?   print-string 0, "\n"
+  return result
 }
 
 fn test-try-divide-1 {
@@ -83,13 +84,14 @@ fn test-try-divide-9 {
 }
 
 # only positive dr for now
-fn try-modulo nr: int, dr: int -> result/eax: int {
+fn try-modulo nr: int, dr: int -> _/eax: int {
   var _positive-nr/eax: int <- abs nr
   var positive-nr/ecx: int <- copy _positive-nr
-  var tmp/eax: int <- try-divide positive-nr, dr
-  tmp <- multiply dr
-  tmp <- subtract positive-nr
+  var result/eax: int <- try-divide positive-nr, dr
+  result <- multiply dr
+  result <- subtract positive-nr
   result <- negate
+  return result
 }
 
 fn test-try-modulo-negative-nr {
@@ -97,9 +99,12 @@ fn test-try-modulo-negative-nr {
   check-ints-equal result, 3, "F - test-try-modulo-negative-nr"
 }
 
-fn abs n: int -> result/eax: int {
-  result <- copy n
-  compare n, 0
-  break-if->=
-  result <- negate
+fn abs n: int -> _/eax: int {
+  var result/eax: int <- copy n
+  {
+    compare n, 0
+    break-if->=
+    result <- negate
+  }
+  return result
 }