Question

Problem #2 (20pts) Please write the MIPS assembly code corresponding to the following C code segment. Assume that f is assigned to register $s2 int Example int i, int j, int k) int f; f i+j-k-1: return fi

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ScreenShot

-------------------------------------------------------------------------------------------------------

Program

#variable declaration
.data
       i: .asciiz "Please enter value of i:"
       j: .asciiz "Please enter value of j:"
       k: .asciiz "Please enter value of k:"
       f: .asciiz "f=i+j-k-1="
#main function
.text
.globl main
main:
       #prompt user for i value
       la $a0,i
       li $v0,4
       syscall
       #read i value
       li $v0,5
       syscall
       #store in a1
       move $a1,$v0
       #prompt user for j value
       la $a0,j
       li $v0,4
       syscall
       #read j value
       li $v0,5
       syscall
       #store in a2
       move $a2,$v0
       #prompt user for k value
       la $a0,k
       li $v0,4
       syscall
       #read i value
       li $v0,5
       syscall
       #store in a0
       move $a3,$v0
       #result prompt
       la $a0,f
       li $v0,4
       syscall
       #function call
       jal Example
       #result print
       move $a0,$v0
       li $v0,1
       syscall
       #exit
       li $v0,10
       syscall
#function definition
Example:
       #clear register s2 for f
       add $s2,$0,$0
       #s2=i+j
       add $s2,$a1,$a2
       #s2=i+j-k
       sub $s2,$s2,$a3
       #s2=i+j-k-1
       sub $s2,$s2,1
       #move value into v0 to return
       move $v0,$s2
       #return to main program
       jr $ra

Add a comment
Know the answer?
Add Answer to:
Problem #2 (20pts) Please write the MIPS assembly code corresponding to the following C code segment....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT