Question: Create code to accept one subtraction, addition, or multiplication expression from the command line, perform the operation and display the result as in the samples
Create code to accept one subtraction, addition, or multiplication expression from the command line, perform the operation and display the result as in the samples below. $ spim -f code.s 11 + 12 23 $ spim -f code.s 22 - 12 I wanted how to go about reading and breaking up the command line input to do the operations. They give us the following code to modify.
# prompt the user to enter two integers, sum integers and display the result .text .globl read .globl main .ent main main: jal read li $v0,10 # 10 is exit system call syscall .end main read: # prompt for first integer li $v0 4 # 4 is print string la $a0, iprompt # load address of prompt into $a0 to print syscall # display the prompt # read the first integer li $v0 5 # setup syscall 5 (read_int) syscall # integer returned in $v0 move $t0, $v0 # move first integer to $t0 # prompt for second integer li $v0 4 # 4 is print string la $a0, iprompt # load address of prompt into $a0 to print syscall # display the prompt # read the second integer li $v0 5 # setup syscall 5 (read_int) syscall # integer returned in $v0 move $t1, $v0 # move first integer to $t1 # sum the two integers add $t2, $t0, $t1 move $a0,$t2 # move the result into register $a0 li $v0, 1 # setup syscall 1 (print_int) syscall # make the call to display the integer li $v0, 4 # print newline la $a0, newline syscall jr $ra .data iprompt: .asciiz "Enter an integer [return]: " newline: .asciiz " "
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
