MIPS Assembly Language C Write a MIPS assembly pseudo instru
MIPS Assembly Language, C
Write a MIPS assembly pseudo instruction \"push_multiple\". The instruction gets the name of 3 registers and pushes these registers to the stack in the same order they appear in the instruction. For example, \"push_multiple $a0, $a1, $a3\" Pushes $a0, then $a1, then $a3 to the stack. Assume that the stack grows down in addresses and that $sp points to the next available space. You do not need to check for overflow. Let \'stmt\' stand for an arbitrary pseudo code statement such as \'if, \' while\', \'for\' etc. Convert the following C-like pseudo code into MIPS assembly: do stmt while (aSolution
1 .MIPS Assembler:
The MIPS assembler supports several pseudo-instructions.
Programmers can use pseudo-instructions.
Assembler translates them into actual instructions or sequence of instructions.
Example:
move $7, $18
is translated into
add $7, $18, $0.
($0 always contains 0).
MIPS calling convention:
Many possible conventions are used by different programmers and assemblers.Several different approaches are outlined in the text.
Stack :
Is an abstract data structure which consists of information in a Last In First Out system. You put arbitrary objects onto the stack and then you take them off again, much like an in/out tray, the top item is always the one that is taken off and you always put on to the top.
Mips push instruction implemented as:
Mips pop instruction implemented as:
2. The purpose of an if statement is to provide conditional transfer of control to one or more blocks of statements, one of which is executed when its corresponding condition coded in the if-statement is satisfied. The if-statement can be implemented using mips assembly code
if(i=j)
f=g+h;
else
f=g-h:
mips code:
beq $3,$4, true
sub $0,$s1,$s2
j Fin
true:add $s0,Ss1,$s2
false:
while loop:
Here, the first three MIPS statements establish the loop index, which in turn establishes the address of the memory element save[i]. In the fourth MIPS statement, the condition (save[i] != k) is checked to see if it is time to exit the loop by transferring control to the label Exit. This is done using the bne operation. The sixth statement comprises the body of the loop, where the variable i is incremented by the amount j. The final MIPS statement implements loopback.
while (save[i]==k)
i=i+j;
mips:
loop:add $t1,$s3,$s3 #$t1=2*i
add $t1,$t1,$t1 #$t1=4*i
add $t1,$t1,$t6 #$t1=address of save[i]
lw $t0, 0($t1) #$t0=save[i]
bne $t0, $s5,exit #go to exit if save[1]!=k
add $s3,$s3,$s4 #i=i+j
j loop # go to loop
exit
3.Jump Instruction
The MIPS jump instruction functions like the go to instruction in C, that is, control is transferred to a specific destination address in memory. The instruction format is either of the following two forms:
where label is shown as \"L1\" . Here, label is a string and destination_address is a numberical constant within the range of permissible MIPS address values.
Suppose we have the following assembly language code:
The mips assembly code is
00 0000 0000 0000 0001 0000 0000
the machine language address representation is calculated as
256 = 1024 bytes / 4 bytes/word.
beq $s3, $s4, 20.
| Number | Name | Purpose |
| $0 | $0 | Always 0 |
| $1 | $at | the assembler temporary used by the assembler in expanding pseudo-ops |
| $2-$3 | $v0-$v1 | these registers contain the returned value of a subroutine, if the value is 1 word only $v0 is significant. |

