Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # h2.1
  2.  
  3.                     .data
  4. promptx:  .asciiz           "\nEnter x = "
  5. prompty:  .asciiz           "Enter y = "
  6. errort:     .asciiz         "Please enter an integer between 0 and 255."
  7. finish:     .asciiz         "Product = "
  8.                     .globl          main
  9.                     .text
  10.  
  11. main:
  12.                 li        $v0, 4                    # system call code for Print String
  13.         la        $a0, promptx              # load address of prompt into $a0
  14.         syscall                             # print the prompt message
  15.         li        $v0, 5                            # system call code for Read Integer
  16.         syscall                                             # read N into $v0
  17.         add             $t0, $v0, $zero         # store $v0 in $t0
  18.         slti            $t9, $t0, 0                 # if $t0 is less than 0, re-run main
  19.         bne             $t9, $zero, error
  20.         slti            $t9, $t0, 256               # if $t0 is greater than 255, re-run main
  21.         beq             $t9, $zero, error
  22.  
  23. main2:
  24.         li        $v0, 4                    # System call code for Print String
  25.         la        $a0, prompty              # load address of prompt into $a0
  26.         syscall                             # Print the prompt message
  27.         li        $v0, 5                            # System call code for Read Integer
  28.         syscall                                             # Read N into $v0
  29.         add             $t1, $v0, $zero         # Store $v0 in $t1
  30.         slti            $t9, $t1, 0                 # if $t0 is less than 0, re-run main
  31.         bne             $t9, $zero, error
  32.         slti            $t9, $t1, 256               # if $t0 is greater than 255, re-run main
  33.         beq             $t9, $zero, error
  34.  
  35. main3:
  36.                 li              $t9, 0                          # use $t9 as counter - set to 0
  37.                 li              $t8, 0                          # running total - set to 0
  38.                 beq             $t1, $zero, end         # if either multiplier is 0, skip to end
  39.                 beq             $t0, $zero, end
  40.                 b                   times
  41.  
  42. times:                                                              # increment using the first value as added value, second value as iteration amount
  43.                 add             $t8, $t8, $t0               # add $t0 to $t8
  44.                 addi            $t9, $t9, 1                 # add 1 to $t9
  45.                 bne             $t1, $t9, times         # compare $t1 and $t9 and repeat until equal
  46.  
  47. end:
  48.                 li        $v0, 4                    # system call code for Print String
  49.         la        $a0, finish                   # load address of prompt into $a0
  50.         syscall                             # print the prompt message
  51.           li                $v0, 1                  # system call code for Print Integer
  52.                 move            $a0, $t8                        # move value to be printed to $a0
  53.         syscall                             # print current integer
  54.         li        $v0, 10                           # System call code for terminate
  55.         syscall                                             # return control to system
  56.  
  57. error:
  58.                 li              $v0, 4
  59.                 la              $a0, errort                 #load error message
  60.                 syscall                                             #print error message string
  61.                 b                   main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement