about summary refs log tree commit diff stats
path: root/subx/034compute_segment_address.cc
Commit message (Expand)AuthorAgeFilesLines
* switch to new syntax for segment headers in C++Kartik Agaram2019-05-181-113/+12
* flag tests for opcode 05Kartik Agaram2019-05-131-1/+1
* 5001 - drop the :(scenario) DSLKartik Agaram2019-03-121-49/+75
* 4987 - support `browse_trace` tool in SubXKartik Agaram2019-02-251-4/+4
* 4981 - no, go back to 3 phasesKartik Agaram2019-02-181-16/+16
* 4959Kartik Agaram2019-02-131-10/+29
* 4771Kartik Agaram2018-11-241-0/+2
* 4761Kartik Agaram2018-11-231-1/+1
* 4754 - allow data segment to refer to variablesKartik Agaram2018-11-191-8/+10
* 4668Kartik Agaram2018-10-051-3/+3
* 4661Kartik Agaram2018-10-041-17/+17
* 4637 - subx: support multiple input filesKartik Agaram2018-10-011-3/+62
* 4631Kartik Agaram2018-10-011-0/+10
* 4614 - redo simulated RAMKartik Agaram2018-09-291-2/+0
* 4565Kartik Agaram2018-09-211-0/+15
* 4550Kartik Agaram2018-09-201-1/+2
* 4544Kartik Agaram2018-09-121-1/+1
* 4535 - support for global variable namesKartik Agaram2018-09-011-2/+26
* 4534Kartik Agaram2018-09-011-0/+31
29 30 31
32
33
34
35
36
37
38
39
40

                                                                          





                                       


                                                                       
             
                                 







                                            
                                                              




                                                                  



                                                            
                                           



                    


                       
 
# accept a filename on the commandline, read it and print it out to screen
# only ascii right now, just like the rest of Mu
#
# To run:
#   $ ./translate_mu apps/print-file.mu
#   $ echo abc > x
#   $ ./a.elf x
#   abc

fn main _args: (addr array (addr array byte)) -> exit-status/ebx: int {
  var args/eax: (addr array (addr array byte)) <- copy _args
$main-body: {
    var n/ecx: int <- length args
    compare n, 1
    {
      break-if->
      print-string "usage: cat <filename>\n"
      break $main-body
    }
    {
      break-if-<=
      var filename/edx: (addr addr array byte) <- index args 1
      var in: (handle buffered-file)
      {
        var addr-in/eax: (addr handle buffered-file) <- address in
        open *filename, 0, addr-in
      }
      var _in-addr/eax: (addr buffered-file) <- lookup in
      var in-addr/ecx: (addr buffered-file) <- copy _in-addr
      {
        var c/eax: byte <- read-byte-buffered in-addr
        compare c, 0xffffffff  # EOF marker
        break-if-=
        print-byte c
        loop
      }
    }
  }
  exit-status <- copy 0
}