#Add two integers and print the result .data num1: .word 10 # first number num2: .word 20 # second number result:.word 0 # to store the sum .text .globl main main: lw $t0, num1 # load num1 into $t0 lw $t1, num2 # load num2 into $t1 add $t2, $t0, $t1 # $t2 = $t0 + $t1 sw $t2, result # store result in memory # print the result li $v0, 1 # syscall: print integer move $a0, $t2 # value to print syscall # exit program li $v0, 10 # syscall: exit syscall #===================================================================== #Add Two User-Input Numbers (MARS) .data prompt1: .asciiz "Enter first number: " prompt2: .asciiz "Enter second number: " result: .asciiz "Sum = " .text .globl main main: # Ask for first number li $v0, 4 # syscall: print string la $a0, prompt1 syscall li $v0, 5 # syscall: read integer syscall move $t0, $v0 # store first number in $t0 # Ask for second number li $v0, 4 la $a0, prompt2 syscall li $v0, 5 # read integer syscall move $t1, $v0 # store second number in $t1 # Add the two numbers add $t2, $t0, $t1 # Print result message li $v0, 4 la $a0, result syscall # Print the sum li $v0, 1 # syscall: print integer move $a0, $t2 syscall # Exit program li $v0, 10 syscall #===================================================================== #Addition with Immediate Input .text .globl main main: li $t0, 15 # load first number into $t0 addi $t1, $t0, 10 # $t1 = $t0 + 10 (immediate value) # print result li $v0, 1 # syscall: print integer move $a0, $t1 syscall # exit li $v0, 10 syscall #===================================================================== #user input + immediate value .text .globl main main: # read integer from user li $v0, 5 syscall move $t0, $v0 addi $t1, $t0, 5 # add immediate value 5 # print result li $v0, 1 move $a0, $t1 syscall li $v0, 10 syscall