Question

In: Computer Science

-If we assume we place the following MIPS code starting at location 8000 in memory, what...

-If we assume we place the following MIPS code starting at location 8000 in memory, what is the MIPS machine code for this code? Show the machine codes in decimal. Please explain each instruction and specify its type ( R format, I format, or J format). k corresponds to register $s4, j corresponds to register $s1, i corresponds to register $s0, and the base of the array v is in $a0

addi $s1,$s0,-1

label2: slti $t0, $s1, 0

bne $t0, $zero, label1

sll $t1, $s1, 2

add $t2, $a0, $t1

lw $t3, 0($t2)

beq $t3, $zero, label1

subi $s4, $s4, 1

addi $s1, $s1, –1

j label2

label1:

Solutions

Expert Solution

addi $s1,$s0,-1   (I type)//j = i-1
label 2:  
slti $t0, $s1, 0 (I type)//if (j<0) then $t0 = 1
bne $t0, $zero, label1(I type)   //if($t0 =1) branch to label1
sll $t1, $s1, 2   (R type)   //$t1 = 4*j
add $t2, $a0, $t1 (R type)   //$t2 = address of v[j]
lw $t3, 0($t2)   (I type)   //$t3 = v[j]
beq $t3, $zero, label1(I type) //if(v[j] == 0) branch to label1
subi $s4, $s4, 1 (I type)    // k = k-1
addi $s1, $s1, –1 (I type)    // j = j-1
j label2   (J type)   //jump to label2

label1:


Related Solutions

The following code segment is stored in memory starting at memory location 0x00445670. What are the...
The following code segment is stored in memory starting at memory location 0x00445670. What are the two possible values for the contents of the PC after the branch instruction has executed?       bgez $a0, skip                      # mem location: 0x00445670 subu $s2, $s1, $t0 # branch NOT taken (false) ori    $v0, $t1, 0x0003 #       skip: addi $t0, $t1, 2 # branch taken (true) if taken: if not taken: Hint: Remember how many bytes each instructions takes.
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...
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...
Compile the following C code to MIPS assembly. a. Assume that i and j are stored...
Compile the following C code to MIPS assembly. a. Assume that i and j are stored in register $s1 and $s2, respectively. i = i – 2 + j; b. Assume base address of Array B and the variable i are stored in registers $s3 and $s1, respectively. B[1] = (B[0] x 4) - I; Explain each step in detail! my professor has the following answer: 1) addi $t0, $s1, -2 add $s1, $$t0, $s2 2) lw $t0, 0 ($s3)...
Write assembly code for the following machine code. Assume that the segment is placed starting at...
Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual memory addresses represented by such labels. 0010 1010 0000 1000 0000 0000 0000 1010 0001 0001 0000 0000 0000 0000 0000 0010 0000 0010 0001 0001 1000 0000 0010 0000 0000 1000 0000 0000 0100 1110 0010 0101 0000 0010 0001 0010 1000 0000 0010 0000
a. Write machine code for the following assembly code. Assume that the segment is placed starting...
a. Write machine code for the following assembly code. Assume that the segment is placed starting at location 80000. Use decimal numbers to represent each instruction. loop:         beq $s3, $s1, endwhile                  add $t0, $s3, $s4                  lw $t1, 0($t0)                  add $s0, $s0, $t1                  addi $s3, $s3, 4                  j loop endwhile: b. Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual...
Write a program segment to copy a table with five items from a memory location starting...
Write a program segment to copy a table with five items from a memory location starting at $5000 to a memory location starting at $6000.
Assume that 20 bytes of Packed BCD data is present in a data memory at location...
Assume that 20 bytes of Packed BCD data is present in a data memory at location 0x300 to 0x313. You have to write an assembly program that will display data on a two seven segment displays one connected to Port A and other connected to Port B using loops. You also have to analyze data if the data is equal to 0x22 then start storing data bytes at corresponding memory address 0x400 to 0x413 in reverse order i.e. if the...
Place each of the following in the correct location in the table.
Place each of the following in the correct location in the table.  Congested toll roads Knowledge Fish in the ocean National defense Congested nontoll roads Cable TV The environment Fire protection Ice-cream cones Uncongested toll roads Clothing Uncongested nontoll roads
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT