C code to unoptimized MARS MIPS:
#include <stdio.h>
int main() {
int num1, num2, sum;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
sum = num1 + num2;
printf("Sum of %d and %d is %d\n", num1, num2, sum);
return 0;
}
Unoptimized MARS MIPS code:
.data
num1: .word 0
num2: .word 0
sum: .word 0
prompt: .asciiz "Enter two numbers: "
result: .asciiz "Sum of "
.text
main:
# Prompt user for input
la $a0, prompt
li $v0, 4
syscall
# Read in first number
li $v0, 5
syscall
sw $v0, num1
# Read in second number
li $v0, 5
syscall
sw $v0, num2
# Add the two numbers together
lw $t0, num1
lw $t1, num2
add $t2, $t0, $t1
sw $t2, sum
# Print the result
lw $a0, num1
lw $a1, num2
lw $a2, sum
la $t0, result
li $v0, 4
syscall
move $a0, $t2
li $v0, 1
syscall
# Exit the program
li $v0, 10
syscall