uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

lab6_ex3.asm (999B)


      1 .eqv SYS_PRINT_STRING   4
      2 .eqv SYS_READ_WORD      5
      3 .eqv SYS_EXIT           10
      4 
      5 .data
      6         inputmsg: .asciiz "Number: "
      7         posstr:   .asciiz "Positive\n"
      8         negstr:   .asciiz "Negative\n"
      9 
     10 .text
     11 .globl main
     12 
     13 main:
     14         li      $v0, SYS_PRINT_STRING
     15         la      $a0, inputmsg
     16         syscall
     17         
     18         li      $v0, SYS_READ_WORD
     19         syscall
     20         
     21         # Right shift number 31 bits so that the MSB falls
     22         # on the LSB's position. Since we're using 2's
     23         # complement, if the MSB is 1 the number is negative
     24         # and if it's 0 it's positive. After the right shift
     25         # `t0` will either be 0 or 1
     26         
     27         srl     $t0, $v0, 31
     28         beq     $t0, 0, positive
     29         
     30         li      $v0, SYS_PRINT_STRING
     31         la      $a0, negstr
     32         syscall
     33         
     34         j       exit
     35         
     36 positive:
     37         li      $v0, SYS_PRINT_STRING
     38         la      $a0, posstr
     39         syscall
     40 
     41 exit:
     42         li      $v0, SYS_EXIT
     43         syscall