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

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

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