For the following C code what are the corresponding MIPS Mic
For the following C code, what are the corresponding MIPS (Microprocessor without Interlocked Pipeline Stages) assembly instructions?
X=(Y-Z)-(V+W)
where V, W, X, Y, Z are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. You may need temporary register(s) for this question.
2. For the following C code, what are the corresponding MIPS assembly instructions?
B=C+A[7];
where (B) represented by $s0, C by $s1, and (A base address) represented by $s2 (temporary register(s) may be needed).
Solution
X=(Y-Z)-(V+W)
This above given equation can be defined as below using MIPS instructions
add $s0,$s0,$s1 ;V=V+W
sub $s3,$s3,$s4 ;Y=Y-Z
sub $s2,$s3,$s0 ; X= Y-V
; X=(Y-Z)-(V+W)
By using the above instructions we can compute the given equation..
2)
li $s3,7 ;put the index into $s2
add $s3,$s3,$s3 ;double the value
add $s3,$s3,$s3 ;double the index value again
add $s3,$s2,$s3 ;combine the base address and index value
lw $s3,0($s3) ;load the A[7] value into $s3
add $s0,$s1,$s3 ;B=C+A[7]
These given instructions are used to compute the result of above given equation
