uni

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

lab4_ex4.asm (1006B)


      1 .eqv SYS_PRINT_STRING   4
      2 .eqv SYS_READ_WORD      5
      3 .eqv SYS_EXIT           10
      4 .eqv SYS_PRINT_CHAR     11
      5 
      6 .data
      7         msg:    .asciiz "Number: "
      8         errstr: .asciiz "Give a positive number.\n"
      9 
     10 .text
     11 .globl main
     12 
     13 main:
     14         li      $v0, SYS_PRINT_STRING
     15         la      $a0, msg
     16         syscall
     17         
     18         li      $v0, SYS_READ_WORD
     19         syscall
     20         move    $t0, $v0
     21         
     22         # exit if t0 <= 0
     23         beq     $t0, $zero, err
     24         slt     $t1, $t0, $zero
     25         bne     $t1, $zero, err
     26         
     27         # init loop counter
     28         li      $t2, 0
     29         
     30 loop:
     31         beq     $t2, $t0, exit
     32         addi    $t2, $t2, 1
     33         
     34         li      $v0, SYS_PRINT_CHAR
     35         li      $a0, '*'
     36         syscall
     37         
     38         j       loop
     39         
     40         li      $v0, SYS_PRINT_CHAR
     41         li      $a0, 0xa
     42         syscall
     43         
     44 err:
     45         li      $v0, SYS_PRINT_STRING
     46         la      $a0, errstr
     47         syscall
     48 
     49 exit:
     50         li      $v0, SYS_EXIT
     51         syscall