Question: Can someone help me write this c++ code in mips?. I have to use AND for modulus but i dont understand how to do it.
Can someone help me write this c++ code in mips?. I have to use AND for modulus but i dont understand how to do it. I have to loop through the code.
Here is the code
include
include
using namespace std;
void main()
{
//declare variables
int x = 0;
//loop 3 times thru 0..3
for(int i=0; i<=12; i++)
{
cout << x;
x++;
x = x & 0x03; //modulus 4
}
}//end main()
OUTPUT: 0 1 2 3 0 1 2 3 0 1 2 3
//MIPS code starts here
.data
.eqv SYS_PRINT_WORD 1 #word, byte, character
.eqv SYS_PRINT_FLOAT 2 #float
.eqv SYS_PRINT_DOUBLE 3 #double
.eqv SYS_PRINT_TEXT 4 #text (zero terminated)
.eqv SYS_INPUT_WORD 5 #input word
.eqv SYS_EXIT 10 #terminate
# //declare variables
# int x = 0;
x: .word 0
endl: .asciiz " "
blank: .asciiz " "
.text
.globl main
main:
//loop 3 times thru 0..3
// for(int i=0; i<=12; i++)
// {
// cout << x;
loop:
// x++;
// x = x & 0x03; //modulus 4
// }
Please help. The above is just a format of how it should be written using the loop
#---- terminate ---
exit:
li $v0, SYS_EXIT
syscall
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
