Question: Write a program in MIPS assembler that performs the following computations: Prompts the user to enter two integers and stores the smaller one in the
Write a program in MIPS assembler that performs the following computations:
- Prompts the user to enter two integers and stores the smaller one in the first data memory word (with the lowest address) and the larger one in the second data memory word.
- Then subtracts the smaller word from the larger word and stores the result in the third data memory word.
- Finally, it prints the three data memory words on separate lines each starting with a label (larger integer, smaller integer, difference).
Requirements and restrictions
- Use integer arithmetic only.
- Include at least one instruction from each instruction type: R-type arithmetic, I-type arithmetic, Memory transfer (lw, sw) and Branch (beq, bne).
- Use input and output through system calls including print string for prompting the user and printing labels.
- Do NOT use pseudo-instructions or non-machine level instructions (e.g. a label for a memory word in lw or sw). The program must load and run with "Allow pseudo instructions" unchecked (in Simulator/Settings).
- Do NOT use the simulator bare machine option (delayed load and branches) and instructions to fill the delayed load and branch slots.
- For each instruction Include as comment in the source file: its type, format and meaning in the program.
- Use the SPIM simulator to run the program.
# Assignment 1 Template .text .globl __start __start: lui $s0, 0x1000 # set up a base register for memory access # Print prompts and read 2 integers # print string input1 addi $a0, $s0, 12 # load address of input1 into $a0 (la $a0, input1) addi $v0, $0, 4 # syscall to print string syscall # read first integer # print string input2 # read second integer # compare them and store the smaller in $t0 and the larger in $t1 sw $t0, 0($s0) # store $t0 in A (smaller) sw $t1, 4($s0) # store $t1 in B (larger) # Subtract the smaller from the larger and store the result in C # Print A, B, and C with the corresponding label first # print the label and B addi $a0, $s0, 46 # load address of string larger addi $v0, $0, 4 # syscall to print string syscall lw $a0, 4($s0) # load B in $a0 addi $v0, $0, 1 # syscall to print integer syscall # print the label and A # print the label and C addi $v0, $0, 10 # syscall to end the program syscall .data 0x10000000 A: .word 0 # store here the smaller integer B: .word 0 # store here the larger integer C: .word 0 # store here the quotient input1: .asciiz "First integer : " input2: .asciiz "Second integer: " larger: .asciiz " Larger Integer: " smaller: .asciiz " Smaller Integer: " difference: .asciiz " Difference: "
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
