In: Computer Science
Translate the code in translateMe.c to MIPS in a file called translated.asm.Make sure you run both versions of the programto see that they get the same result.
Code:
int main() {
// use $t0 for x
int x = 0xC0FFEE00;
// use $t1 for y
unsigned int y = 0xC0FFEE00;
// use $t2 for z
int z = (x >> 8) & 0xFF;
// use $t3 for w
int w = ((y | 0xFF000000) << 6) ^ 0xFF;
}
Greetings!!
Code in C:
#include <stdio.h>
#include <stdlib.h>
int main()
{
// use $t0 for x
int x = 0xC0FFEE00;
printf("%x\n",x);
// use $t1 for y
unsigned int y = 0xC0FFEE00;
printf("%x\n",y);
// use $t2 for z
int z = (x >> 8) & 0xFF;
printf("%x\n",z);
// use $t3 for w
int w = ((y | 0xFF000000) << 6) ^ 0xFF;
printf("%x\n",w);
return 0;
}
Code in MIPS
.data
nl: .asciiz "\n"
.text
li $t0,0xC0FFEE00 #load 0xC0FFEE00 into t0
li $t1,0xC0FFEE00 #load 0xC0FFEE00 into t1
#int z = (x >> 8) & 0xFF;
srl $t2,$t0,8 #shift x right by 8
and store result in t2
andi $t2,$t2,0xFF #AND content of t2 with FF and store
the result in t2
#int w = ((y | 0xFF000000) << 6) ^ 0xFF;
ori $t3,$t1,0xFF000000 #OR x with FF000000 and store
the result in t3
sll $t3,$t3,6 #shift t3 content
right by 6
xori $t3,$t3,0xFF #XOR t3 with FF
#print x
move $a0,$t0
li $v0,34
syscall
#print newline
la $a0,nl
li $v0,4
syscall
#print y
move $a0,$t1
li $v0,34
syscall
#print newline
la $a0,nl
li $v0,4
syscall
#print z
move $a0,$t2
li $v0,34
syscall
#print newline
la $a0,nl
li $v0,4
syscall
#print w
move $a0,$t3
li $v0,34
syscall
li $v0,10
syscall
Output screenshots:
In C:
In MIPS
Hope this helps
Thank You