Question

Translate the following C code into a procedure in MIPS. Assume the two arguments are passed in registers $a0 and $a1. You are not required to preserve the values of registers $a0 and Şa1 1. [By the way-this is a basic implementation of the forward predict step of the 1-D Haar Lifting Transform, a kind of Discrete Wavelet Transform. The real version would use doubles, not ints.] void haarpredict (int vector[], int N) int half = N >> 1; int count-0 for(int i -0; i < half; i++) int predictVal -vector[i] int j i half; vector[j] vector[j] predictval

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

Please find the code below:::

.data
vector :.space 100

.text
la $a0,vector #load vector address
li $a1,10 #loadd N in a1

jal haarPredict
li $v0,10 #terminate program
syscall

haarPredict:
srl $s0,$a1,1 #int half = N >>1 ;
li $t0,0 #count = 0
li $t7,0 #i=0
loop :

mul $s1,$t7,4 #multiply i by integer size 4
add $s1,$s1,$a0 #get base address of vector[i]
lw $s1,($s1) #load vector[i] to s1

add $s2,$t7,$s0 # j = i+half
mul $s2,$s2,4 #multiply j by integer size 4
add $s2,$s2,$a0 #get base address of vector[j]
lw $s3,($s2) #load vector[j] to s3
sub $s3,$s3,$s1 #get vector[j] - predictVal
sw $s3,($s2) #save value to vector[j]

addi $t7,$t7,1 #i++
blt $t7,$s0,loop #loop if i < half
jr $ra #jmp to calling function

Add a comment
Know the answer?
Add Answer to:
Translate the following C code into a procedure in MIPS. Assume the two arguments are passed...
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
ADVERTISEMENT