4. PROGRAM: Modify the FriendlyAdd sample program to do a \"FriendlySubtract\".
ID: 3708548 • Letter: 4
Question
4. PROGRAM: Modify the FriendlyAdd sample program to do a "FriendlySubtract". Assemble and run it. Then paste the output as your answer.
Here is the FriendlyAdd program, and PLEASE use $random instead of sub:
.data
first: .asciiz " Please enter first integer:"
second: .asciiz " Please enter second integer:"
result: .asciiz " The sum is: "
.code
main:
la $a0,first
syscall $print_string
syscall $read_int # get first number from user
move $t0,$v0
la $a0,second
syscall $print_string
syscall $read_int # get second number from user
move $t1,$v0
add $t2,$t1,$t0 # do the addition
la $a0,result
syscall $print_string
move $a0,$t2 # output the result
syscall $print_int
syscall $exit
Explanation / Answer
.data
first: .asciiz " Please enter first integer:"
second: .asciiz " Please enter second integer:"
result: .asciiz " The difference is: "
.code
main:
la $a0,first
syscall $print_string
syscall $read_int # get first number from user
move $t0,$v0
la $a0,second
syscall $print_string
syscall $read_int # get second number from user
move $t1,$v0
sub $t2,$t1,$t0 # do the addition
la $a0,result
syscall $print_string
move $a0,$t2 # output the result
syscall $print_int
syscall $exit
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.