Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an assembly language program that runs under MIPSym. It should input two n

ID: 3699587 • Letter: W

Question

Write an assembly language program that runs under MIPSym. It should input two numbers A and B from the keyboard, then calculate 6 different values as follows:

1) Y1 = A + B

2) Y2 = A – B

3) Y3 = A * B

4) Y4 = A / B

5) Y5 = A << B

6) Y6 = A >> B

The division operation is an integer division so the decimal value is truncated. The << and >> operations correspond to “shift left” and “shift right” respectively.

You will need to use the syscall for inputting integers and the syscalls for outputting integers. The syscall for reading is as follows: syscall $read_int # read an integer into register (variable) $v0 The syscall for writing an integer stored in register (variable) $t0 is as follows: mov $a0,$t0 # move the value from register $t0 to register $a0 syscall $print_int # print the integer stored in register $a0 Your program should print each of these 6 values after computing them. Please do NOT use QtSPIM or MARS style syscall conventions. You must use the syscall convention presented in class.

Explanation / Answer

.data
msg1: .asciiz "Enter the first number: "
msg2: .asciiz " Enter the second number: "

sum: .asciiz " A + B = "
diff: .asciiz " A - B = "
mult_msg: .asciiz " A * B = "
div_msg: .asciiz " A / B = "
shift_left: .asciiz " A << B = "
shift_right: .asciiz " A >> B = "

.text
li $v0,4
la $a0,msg1
syscall

li $v0,5
syscall
move $t1,$v0

li $v0,4
la $a0,msg2
syscall

li $v0,5
syscall
move $t2,$v0

add $t3,$t1,$t2

li $v0,4
la $a0,sum
syscall

li $v0,1
move $a0,$t3
syscall

sub $t3,$t1,$t2

li $v0,4
la $a0,diff
syscall

li $v0,1
move $a0,$t3
syscall

mult $t3,$t1,$t2

li $v0,4
la $a0,mult_msg
syscall

li $v0,1
move $a0,$t3
syscall

div $t1,$t2

mflo $t3

li $v0,4
la $a0,div_msg
syscall

li $v0,1
move $a0,$t3
syscall

sll $t3,$t1,$t2

li $v0,4
la $a0,shift_left
syscall

li $v0,1
move $a0,$t3
syscall

srl $t3,$t1,$t2

li $v0,4
la $a0,shift_right
syscall

li $v0,1
move $a0,$t3
syscall

li $v0,10
syscall

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote