0

So I have written a simple program for my comp arch class in MIPS assembly. We are now required to enhance this program so that it takes two arguments. If the arguments are both the same then the answer should be the same as that of the original program that takes only one argument. If they are different then you should figure out what your program should do based on the above. Try to make as few changes as possible. Enhance the program to allow it to receive the two arguments from the keyboard and display the result in the console window of SPIM. If any of the input arguments is a negative number (less than zero), your enhanced program should display a zero in the console.

Here is my code from the un-enhanced part:

.data   
arg:    .word   5

.text
.globl main
main:

la  $t3, arg    
lw  $t2, 0($t3) 
lw  $t3, 0($t3)

addi    $t1, $zero, 0
beqz    $t2, fin        
fori:

add $t1, $t1, $t2   
addi    $t3, $t3, -1

bnez    $t3, fori       

fin:

li  $v0, 10
syscall 
Michael
  • 57,169
  • 9
  • 80
  • 125

1 Answers1

1

Here's code to read an integer from the keyboard and store it in arg1.

        .data
  arg1: .word 0
        .text
        li $v0, 5        # system call code for read int
        syscall          # read the int
        la $t0, arg1
        sw $v0, 0($t0)   # store the integer at location arg1
markgz
  • 6,054
  • 1
  • 19
  • 41
  • Thank you! So I now get how to read and write integers to the console, but I am confused on how to add that implemination to the existing program. Any pointers or advice? – Connie Clark Mar 05 '15 at 06:03