Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # h2.1
- .data
- promptx: .asciiz "\nEnter x = "
- prompty: .asciiz "Enter y = "
- errort: .asciiz "Please enter an integer between 0 and 255."
- finish: .asciiz "Product = "
- .globl main
- .text
- main:
- li $v0, 4 # system call code for Print String
- la $a0, promptx # load address of prompt into $a0
- syscall # print the prompt message
- li $v0, 5 # system call code for Read Integer
- syscall # read N into $v0
- add $t0, $v0, $zero # store $v0 in $t0
- slti $t9, $t0, 0 # if $t0 is less than 0, re-run main
- bne $t9, $zero, error
- slti $t9, $t0, 256 # if $t0 is greater than 255, re-run main
- beq $t9, $zero, error
- main2:
- li $v0, 4 # System call code for Print String
- la $a0, prompty # load address of prompt into $a0
- syscall # Print the prompt message
- li $v0, 5 # System call code for Read Integer
- syscall # Read N into $v0
- add $t1, $v0, $zero # Store $v0 in $t1
- slti $t9, $t1, 0 # if $t0 is less than 0, re-run main
- bne $t9, $zero, error
- slti $t9, $t1, 256 # if $t0 is greater than 255, re-run main
- beq $t9, $zero, error
- main3:
- li $t9, 0 # use $t9 as counter - set to 0
- li $t8, 0 # running total - set to 0
- beq $t1, $zero, end # if either multiplier is 0, skip to end
- beq $t0, $zero, end
- b times
- times: # increment using the first value as added value, second value as iteration amount
- add $t8, $t8, $t0 # add $t0 to $t8
- addi $t9, $t9, 1 # add 1 to $t9
- bne $t1, $t9, times # compare $t1 and $t9 and repeat until equal
- end:
- li $v0, 4 # system call code for Print String
- la $a0, finish # load address of prompt into $a0
- syscall # print the prompt message
- li $v0, 1 # system call code for Print Integer
- move $a0, $t8 # move value to be printed to $a0
- syscall # print current integer
- li $v0, 10 # System call code for terminate
- syscall # return control to system
- error:
- li $v0, 4
- la $a0, errort #load error message
- syscall #print error message string
- b main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement