MIPS / MARS Program To take 3 integers as input and Add them to display Output.(CODE IN DESCRIPTION)

Опубликовано: 20 Июль 2026
на канале: Hamza Ashraf
536
3

CODE:
.text
.globl main
main:
Print string msg9
li $v0,4 # print_string syscall code = 4
la $a0, msg9 # load the address of msg
syscall
Print string newline
li $v0,4 # print_string syscall code = 4
la $a0, newline # load the address of msg
syscall
Print string msg1
li $v0,4 # print_string syscall code = 4
la $a0, msg1 # load the address of msg
syscall
Get input A from user and save
li $v0,5 # read_int syscall code = 5
syscall
move $t0,$v0 # syscall results returned in $v0
Print string msg2
li $v0,4 # print_string syscall code = 4
la $a0, msg2 # load the address of msg2
syscall
Get input B from user and save
li $v0,5 # read_int syscall code = 5
syscall
move $t1,$v0 # syscall results returned in $v0
Print string msg3
li $v0, 4
la $a0, msg3
syscall
Get input C from user and save
li $v0,5 # read_int syscall code = 5
syscall
move $t2,$v0 # syscall results returned in $v0

Math!
add $t0, $t0, $t1 # A = A + B
add $t1,$t0,$t2 # A = A + B
Print string msg10
li $v0,4 # print_string syscall code = 4
la $a0, msg10 # load the address of msg
syscall
Print string newline
li $v0,4 # print_string syscall code = 4
la $a0, newline # load the address of msg
syscall

Print string msg5
li $v0,4 # print_string syscall code = 4
la $a0, msg5 # load the address of msg
syscall
Get input A from user and save
li $v0,5 # read_int syscall code = 5
syscall
move $t3,$v0 # syscall results returned in $v0
Print string msg6
li $v0,4 # print_string syscall code = 4
la $a0, msg6 # load the address of msg2
syscall
Get input B from user and save
li $v0,5 # read_int syscall code = 5
syscall
move $t4,$v0 # syscall results returned in $v0
Print string msg5
li $v0, 4
la $a0, msg7
syscall
Get input C from user and save
li $v0,5 # read_int syscall code = 5
syscall
move $t5,$v0 # syscall results returned in $v0

Math!
add $t3, $t3, $t4 # A = A + B
add $t4,$t3,$t5 # A = A + B

Print string msg4
li $v0, 4
la $a0, msg4
syscall
Print sum
li $v0,1 # print_int syscall code = 1
move $a0, $t1 # int to print must be loaded into $a0
syscall
Print \n
li $v0,4 # print_string syscall code = 4
la $a0, newline
syscall
Print string msg8
li $v0, 4
la $a0, msg8
syscall
Print sum
li $v0,1 # print_int syscall code = 1
move $a0, $t4 # int to print must be loaded into $a0
syscall
Print \n
li $v0,4 # print_string syscall code = 4
la $a0, newline
syscall
li $v0,10 # exit
syscall
Start .data segment (data!)
.data
msg1: .asciiz "Enter A: "
msg2: .asciiz "Enter B: "
msg3: .asciiz "Enter C: "
msg5: .asciiz "Enter A: "
msg6: .asciiz "Enter B: "
msg7: .asciiz "Enter C: "
msg4: .asciiz "First Addition A1 + B1 + C1 = "
msg8: .asciiz "Second Addition A2 + B2 + C2 = "
msg9: .asciiz "Enter 3 integer for 1st addition"
msg10: .asciiz "Enter 3 integer for 2nd addition"
newline: .asciiz "\n"
Not related:
Mipsadd3integers,Mars,add,mips stands for,MIPS architecture