From 3d1c4216ede8c628558c9fe700fb2be1aa08b473 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 2 Nov 2020 21:24:53 -0800 Subject: 7162 --- html/406try-divide.mu.html | 145 +++++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 70 deletions(-) (limited to 'html/406try-divide.mu.html') diff --git a/html/406try-divide.mu.html b/html/406try-divide.mu.html index c7531fec..ea3d1eb9 100644 --- a/html/406try-divide.mu.html +++ b/html/406try-divide.mu.html @@ -60,7 +60,7 @@ if ('onhashchange' in window) {
   1 # slow, iterative divide instruction
   2 # preconditions: _nr >= 0, _dr > 0
-  3 fn try-divide _nr: int, _dr: int -> result/eax: int {
+  3 fn try-divide _nr: int, _dr: int -> _/eax: int {
   4   # x = next power-of-2 multiple of _dr after _nr
   5   var x/ecx: int <- copy 1
   6   {
@@ -90,79 +90,84 @@ if ('onhashchange' in window) {
  30     i <- increment
  31     loop
  32   }
- 33   result <- copy i
+ 33   var result/eax: int <- copy i
  34   result <- decrement
  35 #?   print-string 0, "=> "
  36 #?   print-int32-hex 0, result
  37 #?   print-string 0, "\n"
- 38 }
- 39 
- 40 fn test-try-divide-1 {
- 41   var result/eax: int <- try-divide 0, 2
- 42   check-ints-equal result, 0, "F - try-divide-1"
- 43 }
- 44 
- 45 fn test-try-divide-2 {
- 46   var result/eax: int <- try-divide 1, 2
- 47   check-ints-equal result, 0, "F - try-divide-2"
- 48 }
- 49 
- 50 fn test-try-divide-3 {
- 51   var result/eax: int <- try-divide 2, 2
- 52   check-ints-equal result, 1, "F - try-divide-3"
- 53 }
- 54 
- 55 fn test-try-divide-4 {
- 56   var result/eax: int <- try-divide 4, 2
- 57   check-ints-equal result, 2, "F - try-divide-4"
- 58 }
- 59 
- 60 fn test-try-divide-5 {
- 61   var result/eax: int <- try-divide 6, 2
- 62   check-ints-equal result, 3, "F - try-divide-5"
- 63 }
- 64 
- 65 fn test-try-divide-6 {
- 66   var result/eax: int <- try-divide 9, 3
- 67   check-ints-equal result, 3, "F - try-divide-6"
- 68 }
- 69 
- 70 fn test-try-divide-7 {
- 71   var result/eax: int <- try-divide 0xc, 4
- 72   check-ints-equal result, 3, "F - try-divide-7"
- 73 }
- 74 
- 75 fn test-try-divide-8 {
- 76   var result/eax: int <- try-divide 0x1b, 3  # 27/3
- 77   check-ints-equal result, 9, "F - try-divide-8"
- 78 }
- 79 
- 80 fn test-try-divide-9 {
- 81   var result/eax: int <- try-divide 0x1c, 3  # 28/3
- 82   check-ints-equal result, 9, "F - try-divide-9"
- 83 }
- 84 
- 85 # only positive dr for now
- 86 fn try-modulo nr: int, dr: int -> result/eax: int {
- 87   var _positive-nr/eax: int <- abs nr
- 88   var positive-nr/ecx: int <- copy _positive-nr
- 89   var tmp/eax: int <- try-divide positive-nr, dr
- 90   tmp <- multiply dr
- 91   tmp <- subtract positive-nr
- 92   result <- negate
- 93 }
- 94 
- 95 fn test-try-modulo-negative-nr {
- 96   var result/eax: int <- try-modulo -0xa, 7
- 97   check-ints-equal result, 3, "F - test-try-modulo-negative-nr"
- 98 }
- 99 
-100 fn abs n: int -> result/eax: int {
-101   result <- copy n
-102   compare n, 0
-103   break-if->=
-104   result <- negate
-105 }
+ 38   return result
+ 39 }
+ 40 
+ 41 fn test-try-divide-1 {
+ 42   var result/eax: int <- try-divide 0, 2
+ 43   check-ints-equal result, 0, "F - try-divide-1"
+ 44 }
+ 45 
+ 46 fn test-try-divide-2 {
+ 47   var result/eax: int <- try-divide 1, 2
+ 48   check-ints-equal result, 0, "F - try-divide-2"
+ 49 }
+ 50 
+ 51 fn test-try-divide-3 {
+ 52   var result/eax: int <- try-divide 2, 2
+ 53   check-ints-equal result, 1, "F - try-divide-3"
+ 54 }
+ 55 
+ 56 fn test-try-divide-4 {
+ 57   var result/eax: int <- try-divide 4, 2
+ 58   check-ints-equal result, 2, "F - try-divide-4"
+ 59 }
+ 60 
+ 61 fn test-try-divide-5 {
+ 62   var result/eax: int <- try-divide 6, 2
+ 63   check-ints-equal result, 3, "F - try-divide-5"
+ 64 }
+ 65 
+ 66 fn test-try-divide-6 {
+ 67   var result/eax: int <- try-divide 9, 3
+ 68   check-ints-equal result, 3, "F - try-divide-6"
+ 69 }
+ 70 
+ 71 fn test-try-divide-7 {
+ 72   var result/eax: int <- try-divide 0xc, 4
+ 73   check-ints-equal result, 3, "F - try-divide-7"
+ 74 }
+ 75 
+ 76 fn test-try-divide-8 {
+ 77   var result/eax: int <- try-divide 0x1b, 3  # 27/3
+ 78   check-ints-equal result, 9, "F - try-divide-8"
+ 79 }
+ 80 
+ 81 fn test-try-divide-9 {
+ 82   var result/eax: int <- try-divide 0x1c, 3  # 28/3
+ 83   check-ints-equal result, 9, "F - try-divide-9"
+ 84 }
+ 85 
+ 86 # only positive dr for now
+ 87 fn try-modulo nr: int, dr: int -> _/eax: int {
+ 88   var _positive-nr/eax: int <- abs nr
+ 89   var positive-nr/ecx: int <- copy _positive-nr
+ 90   var result/eax: int <- try-divide positive-nr, dr
+ 91   result <- multiply dr
+ 92   result <- subtract positive-nr
+ 93   result <- negate
+ 94   return result
+ 95 }
+ 96 
+ 97 fn test-try-modulo-negative-nr {
+ 98   var result/eax: int <- try-modulo -0xa, 7
+ 99   check-ints-equal result, 3, "F - test-try-modulo-negative-nr"
+100 }
+101 
+102 fn abs n: int -> _/eax: int {
+103   var result/eax: int <- copy n
+104   {
+105     compare n, 0
+106     break-if->=
+107     result <- negate
+108   }
+109   return result
+110 }
 
-- cgit 1.4.1-2-gfad0