https://github.com/akkartik/mu/blob/main/linux/406int32.mu
 1 # Some slow but convenient helpers
 2 
 3 # slow, iterative shift-left instruction
 4 # preconditions: _nr >= 0, _dr > 0
 5 fn repeated-shift-left nr: int, dr: int -> _/eax: int {
 6   var result/eax: int <- copy nr
 7   {
 8     compare dr, 0
 9     break-if-<=
10     result <- shift-left 1
11     decrement dr
12     loop
13   }
14   return result
15 }
16 
17 # slow, iterative shift-right instruction
18 # preconditions: _nr >= 0, _dr > 0
19 fn repeated-shift-right nr: int, dr: int -> _/eax: int {
20   var result/eax: int <- copy nr
21   {
22     compare dr, 0
23     break-if-<=
24     result <- shift-right 1
25     decrement dr
26     loop
27   }
28   return result
29 }
30 
31 fn abs n: int -> _/eax: int {
32   var result/eax: int <- copy n
33   {
34     compare n, 0
35     break-if->=
36     result <- negate
37   }
38   return result
39 }