about summary refs log tree commit diff stats
path: root/dwm.png
Commit message (Expand)AuthorAgeFilesLines
* alternate dwm.pngarg@10ksloc.org2006-07-191-0/+0
* renamed/changedAnselm R. Garbe2006-07-131-0/+0
K. Agaram <vc@akkartik.com> 2021-07-16 08:28:56 -0700 .' href='/akkartik/mu/commit/linux/apps/parse-int.mu?h=main&id=44d26b77c45668c9b0c99894a4294cec004361fe'>44d26b77 ^
ad61776f ^



c8e41a47 ^
ad61776f ^
66daf3cc ^
ad61776f ^



74f1512f ^
c8e41a47 ^
ad61776f ^



c8e41a47 ^
ad61776f ^

c8e41a47 ^
ad61776f ^


c8e41a47 ^
ad61776f ^


c8e41a47 ^
ad61776f ^
c8e41a47 ^
ad61776f ^

c8e41a47 ^
ad61776f ^
c8e41a47 ^


ad61776f ^


c8e41a47 ^
ad61776f ^
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


                                        
                                   



                 
                                                           
                                        
                                                          



                               
                                                         
            



                                                     
            

 
                                                   


                                           
                               


                  
                  
                                
                          

                                           
                                     
     


                                            


                  
               
 
# parse a decimal int at the commandline
#
# To run:
#   $ ./translate apps/parse-int.mu
#   $ ./a.elf 123
#   $ echo $?
#   123

fn main _args: (addr array addr array byte) -> _/ebx: int {
  # if no args, print a message and exit
  var args/esi: (addr array addr array byte) <- copy _args
  var n/ecx: int <- length args
  compare n, 1
  {
    break-if->
    print-string 0/screen, "usage: parse-int <integer>\n"
    return 1
  }
  # otherwise parse the first arg as an integer
  var in/ecx: (addr addr array byte) <- index args, 1
  var out/eax: int <- parse-int *in
  return out
}

fn parse-int _in: (addr array byte) -> _/eax: int {
  var in/esi: (addr array byte) <- copy _in
  var len/edx: int <- length in
  var i/ecx: int <- copy 0
  var result/edi: int <- copy 0
  {
    compare i, len
    break-if->=
    # result *= 10
    var ten/eax: int <- copy 0xa
    result <- multiply ten
    # c = in[i]
    var tmp/ebx: (addr byte) <- index in, i
    var c/eax: byte <- copy-byte *tmp
    #
    var g/eax: grapheme <- copy c
    var digit/eax: int <- to-decimal-digit g
    result <- add digit
    i <- increment
    loop
  }
  return result
}