Question

In: Computer Science

Translate the code in translateMe.c to MIPS in a file called translated.asm.Make sure you run both...

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;
}

Solutions

Expert Solution

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


Related Solutions

4. Translate the following C code to MIPS assembly (in two separate files). Run the program...
4. Translate the following C code to MIPS assembly (in two separate files). Run the program step by step and observe the order of instructions being executed and the value of $sp. int main() { int x=2; z=Subfunc(x); printf(“Value of z is: %d”, z); } int Subfunc(int x) { return x+1;} Submission file: Lab4_4a.asm and Lab4_4b.asm
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a,...
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a, i, and j are in registers $s0, $t0, and $t1, respectively. Assume that register $s2 holds the base address of the array A (add comments to your MIPS code). j = 0; for(i=0 ; i<a ; i++) A[i]=i+j++;
4.Translate the following C code to MIPS assembly code. Assume that the value of i is...
4.Translate the following C code to MIPS assembly code. Assume that the value of i is in register $t0, and $s0 holds the base address of the integer MemArray if (i > 10) MemArray[i] = 0; else MemArray[i] = -MemArray[i]; 6.Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0, and $t1, respectively. Also, assume that register $s2 holds...
Question: In the following MIPS assembly code, translate all the instructions to their corresponding machine code...
Question: In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x2fff0004. Loop: lw $t0, 4($s0)             addi $t1, $t1, -15             sll $t1, $t1, 2             beq $t1, $s1, Exit             addi $s0, $s0, 4             j Loop Exit: …
Translate the following C code into MIPS assembly code. Assume a in $s0, i in $s1,...
Translate the following C code into MIPS assembly code. Assume a in $s0, i in $s1, and base address of b[] in $s2, respectively. Note that the element’s data type in array b is integer (word). Please do not change the C code structure and please comment your MIPS code. for (i = 100; i>a; i--) {          b[i] = 16*i; b[i+1] = 16*(i+1); b[i+2] = 2*i + 16; }
I have to translate C++ code into MIPS. It is expected to have an output of:...
I have to translate C++ code into MIPS. It is expected to have an output of: Value of a: 25 Value of b: 31 Value of c: 18 Value of d: 49 Here is the C++ code: I need to translate this C++ into MIPS code. #include using namespace std; int main(void) { int a = 5; int b = 6; int c = 7; int d; d = -1; if ( a < 10){ a++; }else{ a--; } d...
1.) Translate the following C code to MIPS assembly code. Assume that the variables f, g,...
1.) Translate the following C code to MIPS assembly code. Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively   B[8] = A[i-j]; 2.Translate the following C code to MIPS assembly code. Assume that the values of v in $a0, k in $a1, temp in $t0.    // leaf procedure that...
Translate the following C code into MIPS Assembly code, assuming Loop Variable k is in $s0...
Translate the following C code into MIPS Assembly code, assuming Loop Variable k is in $s0 and initially containing 0 . Also assume base of array Arr is in $s3 while ( k < = 10 ) { Arr[k] = k ; k = k + 1; }
Translate the following C code to MIPS assembly. The main function and subfunction are translated to...
Translate the following C code to MIPS assembly. The main function and subfunction are translated to two separate .asm files. Finish the assembly code segment for the above requirement. int main() { int x=2; int y=1; int z=0; z=Subfunc(x,y); printf(“Value of z is: %d”, z); } int Subfunc(int x, int y) { int t1=0; t1=x+y+100; return t1;} File 1: .data str: .asciiz "The value of z:" .text #.globl main main: addi $s0, $0,2 #x addi $s1, $0,1 #y addi $s2,...
3. Translate the following C code to MIPS assembly code (in two separate files). int main()...
3. Translate the following C code to MIPS assembly code (in two separate files). int main() { printf(“before subroutine!\n”); Subfunc(); printf(“after subroutine!\n!”); } void Subfunc() {printf(“I am subroutine!\n”);} Submission file: Lab4_3a.asm for the main routine and Lab4_3b.asm for the sub-routine.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT