uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

lab3_ex2.asm (1565B)


      1 .eqv SYS_PRINT_WORD     1
      2 .eqv SYS_PRINT_STRING   4
      3 .eqv SYS_READ_WORD      5
      4 .eqv SYS_READ_STRING    8
      5 .eqv SYS_EXIT           10
      6 .eqv SYS_PRINT_CHAR     11
      7 .eqv SYS_READ_CHAR      12
      8 
      9 .macro endl()
     10         li      $v0, SYS_PRINT_CHAR
     11         li      $a0, 0xa
     12         syscall
     13 .end_macro
     14 
     15 .data
     16         str: .asciiz "hello\n"
     17        	name: .space 64
     18         x: .word 0
     19         a: .word 20
     20         b: .word 30
     21         c: .word 15
     22 
     23 .text
     24 .globl main
     25 
     26 main:   
     27         # 1. print 1st and 2nd character in string
     28         li      $v0, SYS_PRINT_CHAR
     29         lb      $a0, str
     30         syscall
     31         lb      $a0, str + 1
     32         syscall
     33         
     34         endl()
     35         
     36         # 2. read x and print str[x]
     37         li      $v0, SYS_READ_WORD
     38         syscall
     39         lb      $a0, str($v0)
     40         li      $v0, SYS_PRINT_CHAR
     41         syscall
     42         
     43         endl()
     44         
     45         # 3. read a string and print its 2nd char
     46         li      $v0, SYS_READ_STRING
     47         la      $a0, name
     48         li      $a1, 64
     49         syscall
     50         lb      $a0, name + 1
     51         li      $v0, SYS_PRINT_CHAR
     52         syscall
     53         
     54         endl()
     55         
     56         # 4. int x, a = 20, b = 30, c = 15;
     57         #    x = (a + b) - (c + 10);
     58         lw      $t0, x
     59         lw      $t1, a
     60         lw      $t2, b
     61         lw      $t3, c
     62         add     $t4, $t1, $t2
     63         addi    $t5, $t3, 10
     64         sub     $t0, $t4, $t5
     65         
     66         li      $v0, SYS_PRINT_WORD
     67         la      $a0, 0($t0)
     68         syscall
     69         
     70         endl()
     71         
     72         li      $v0, SYS_EXIT
     73         syscall