Question

a. Write MIPS assembly code for the following machine code. Assume that the segment is placed...

a. Write MIPS assembly code for the following machine code. Assume that the segment is placed starting at location 8000. Create labels for branch and jump instructions and indicate the

0001 0001 0010 1000 0000 0000 0000 0011

1000 1110 0001 0001 0000 0000 0000 1000

0010 0010 0010 1000 0000 0000 0000 0110

0000 1000 0000 0000 0000 0001 0000 0010

b. Translate the following C function into MIPS assembly code.


int f1(int ar1[], int ar2[], int n) {

int c = 0;

for (int i = 0; i < n; i++) {

if (ar2[i] > 0) {

ar1[i] = ar1[i] + 5;

c++;

}

}

return c;

}

Homework Answers

Answer #1

Here is your solution:

Answer I: Machine code to MIPS assembly code

.BYTE 0x00, 0x01, 0x00, 0x01
.BYTE 0x00, 0x10, 0x10, 0x00
.BYTE 0x00, 0x00, 0x00, 0x00
ADD w0, w0, #0
ADR x16, #0x22010

.BYTE 0x00, 0x01, 0x00, 0x01
.BYTE 0x00, 0x00, 0x00, 0x00
.BYTE 0x00, 0x00, 0x10, 0x00
ADR x0, #0x220

.BYTE 0x00, 0x10, 0x10, 0x00
.BYTE 0x00, 0x00, 0x00, 0x00
ADR x0, #0x202c

.BYTE 0x00, 0x00, 0x10, 0x00
.BYTE 0x00, 0x00, 0x00, 0x00
.BYTE 0x00, 0x00, 0x00, 0x01
ADR x0, #0x3c

Answer 2:

C program to MIPS assembly code.

f1:

        daddiu  $sp,$sp,-64

        sd      $fp,56($sp)

        move    $fp,$sp

        sd      $4,16($fp)

        sd      $5,24($fp)

        move    $2,$6

        sll     $2,$2,0

        sw      $2,32($fp)

        sw      $0,0($fp)

        sw      $0,4($fp)

        b       .L2

        nop

.L4:

        lw      $2,4($fp)

        dsll    $2,$2,2

        ld      $3,24($fp)

        daddu   $2,$3,$2

        lw      $2,0($2)

        blez    $2,.L3

        nop

        lw      $2,4($fp)

        dsll    $2,$2,2

        ld      $3,16($fp)

        daddu   $2,$3,$2

        lw      $3,4($fp)

        dsll    $3,$3,2

        ld      $4,16($fp)

        daddu   $3,$4,$3

        lw      $3,0($3)

        addiu   $3,$3,5

        sw      $3,0($2)

        lw      $2,0($fp)

        addiu   $2,$2,1

        sw      $2,0($fp)

.L3:

        lw      $2,4($fp)

        addiu   $2,$2,1

        sw      $2,4($fp)

.L2:

        lw      $3,4($fp)

        lw      $2,32($fp)

        slt     $2,$3,$2

        bne     $2,$0,.L4

        nop

        lw      $2,0($fp)

        move    $sp,$fp

        ld      $fp,56($sp)

        daddiu  $sp,$sp,64

        j       $31

        nop

// happy coding

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write the MIPS assembly code that creates the 32-bit constant 0010 0000 0000 0001 0100 1001...
Write the MIPS assembly code that creates the 32-bit constant 0010 0000 0000 0001 0100 1001 0010 0100two and stores that value to register $t1, and print the value of $t1 to stdout in binary - i.e., as a 32 bit sequence of '1's and '0's (use the MIPS syscall functionality for I/O).
In MIPS assembly, write an assembly language version of the following C code segment: int A[100],...
In MIPS assembly, write an assembly language version of the following C code segment: int A[100], B[100]; for (i=1; i < 100; i++) { A[i] = A[i-1] + B[i]; }
Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere...
Translate the following C function into MIPS assembly code. Note that function f1 is defined somewhere else. int f2(int x, int y) { int i, z = 0; for (i = x; i <= y; i++) z = z + f1(i, 5); return z; }
Write the assembly language equivalent of the following MARIE machine language instructions: 0111 0000 0000 0000...
Write the assembly language equivalent of the following MARIE machine language instructions: 0111 0000 0000 0000 0001 0011 0011 0000 0100 1111 0100 1111 1000 0100 0000 0000
Machine Language - 1. Which of the following assembly code represents the high-level Java code below?...
Machine Language - 1. Which of the following assembly code represents the high-level Java code below? int x; int i = 5; if (i < 0) x = -1; else x = 1; @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JGE @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END...
2.     Explain each line of the following MIPS assembly language code segment. Write the corresponding C...
2.     Explain each line of the following MIPS assembly language code segment. Write the corresponding C language code and indicate the content of each register with the corresponding variable in C-code. muli $t2, $s1, 4    add $t2, $t4, $t2    lw $t15, 0($t2)    lw $t16, 4($t2)    sw $t16, 0($t2)    sw $t15, 4($t2)
Please use loop and branch instructions to write an assembly code segment to do the following:...
Please use loop and branch instructions to write an assembly code segment to do the following: Read DIP switch. If DIP switch has the setting: b7 = b0 = 1, then, load A with number $11, load B with number $22, and do A+B; save the result to memory location $1000; if DIP switch has the setting: b4= b3 = 1, then, load A with number $55, load B with number $33, and do A-B; save the result to memory...
2. (7 pts) Translate the following block of C code to MIPS assembly: if (i >...
2. (7 pts) Translate the following block of C code to MIPS assembly: if (i > 10) MemArray[i] = 0; else MemArray[i] = - MemArray[i]; Assume that the variable i is bound to register $t0, and that the base address of array MemArray is in register $s0.
(MIPS Assembly Language): Assume the following piece of MIPS code: label1: .text 0x4000fc lui $t0, 1022...
(MIPS Assembly Language): Assume the following piece of MIPS code: label1: .text 0x4000fc lui $t0, 1022 ori $t0, $t0, 2048 srl $t1, $t0, 18 sw $t0, 101($t1) slti $t2, $t1, 5 beq $t2, $0, label3 label2:... ... label3:... a) The code modifies a word in memory at the following address (circle one): (i) 1022 (ii) 101 (iii) 5 (iv) 10220000 (v) Other (provide your own answer): _________________ b) The following value is stored in memory (circle one): (i) 0x17 (ii)...
Can you translate this C code into MIPS assembly with comment? #include <stdio.h> #include <math.h> #include...
Can you translate this C code into MIPS assembly with comment? #include <stdio.h> #include <math.h> #include <stdlib.h> double fact (double); void main () { int angle_in_D; double term, angle_in_R; float sine = 0; unsigned int i = 1; double sign = 1; int n = 1000; printf ("Please enter an angle (Unit: Degree): "); scanf ("%d", &angle_in_D); angle_in_R = angle_in_D * M_PI / 180.0; do { term = pow(-1,(i-1)) * pow (angle_in_R, (2*i - 1)) / fact (2*i - 1);...