1. Loop: add $t1, $s1, $s2
2. or $s2, $s5, $s6
3. bne $s2, $t8, Loop
4. nop
Re-write the third instruction (bne) in binary.
Consider the following MIPS instruction:
Loop: add $t1, $s1, $s2
or $s2, $s5, $s6
bne $s2, $t8, Loop
nop
Re-writing Bne instruction in Binary:
Let's assume that Loop subroutine start at address 0x1000. So, writing instruction with addresses:
Instruction Format:
BNE - Branch on Not Equal
bne rs, rt, offset [I-type instruction]
Branch to specified offset if (rs != rt)
Given bne $s2, $t8, Loop: Branch to Loop if ($s2 != $t8)
Converting Given instruction bne to Binary:
Machine code for each field:
BNE: 000101 (6 bits)
$s2: 10010 (5 bits) ($s2 = $18 decimal value)
$t8: 11000 (5 bits) ($t8 = $24 decimal value)
Loop: 0001000000000000 (16 bits) (We have assume that Loop is at address 0x1000)
Binary of BNE instruction: bne $s2, $t8, Loop
Binary: 00010110010110000001000000000000
Hex: 0x16581000
Consider the following MIPS instruction: 1. Loop: add $t1, $s1, $s2 2. or...
1. What would be the output of the following MIPS code? .globl main main addu $s7, $0, $ra add $s3, $0,$0 addi $s4, $0, 1 $s5, $0,$0 $s6, save add . data .align 2 .globl save # the next line creates an array of 10 words that can be re ferred to as "save" # the array is initialized to the 10 values after .wo rd # so the first array entry is a 0 and the last entry is...
Reschedule (i.e., re-order) the instructions within the loop to improve performance. The loop must still produce the same results. Show timing of this MIPS instruction sequence through the pipeline, for two iterations of the loop. Show all stalls clearly, and mark with arrows all cases where forwarding takes place, as in our lectures. loop: lw $t0, 0($s0) lw $t1, 4($s0) add $t0, $t1, $t0 sw $t0, 0($s1) addi $s0, $s0, 8 addi $s1, $s1, 4 bne $s0, $s5, loop
2. The table below holds MIPS assembly code fragments with different branch instructions LOOP addi $s2. $s2. 2 subi $t1. st1. 1 bne t1. 0. LOOP DONE: LOOP: it st2. $0. stl beq t2. 0. DONE addi $s2. Ss2. 2 LOOP DONE: For the loops written in MIPS assembly in the above table, assume that the register Şt1 is initialized to the value of 10. What is the value in register $s2 assuming that $s2 initially has a value of...
1. (15 pts) For the following C statement, what is the corresponding MIPS assembly code? Assume f, g, h correspond to $80, $s1, and $s2, respectively. f=g+(h-5) 2. (15 pts) For the following pseudo-MIPS assembly instructions, what is the corresponding C code? add f, g, h add f,i, f 3. (30 pts) Provide the instruction type, assembly language instruction, and binary representation of the instruction described by the following MIPS fields: a. op = 0, rs = 18, rt=9, rd...
Consider the following MIPS code: add $t3,$t2,$t1 lw $t4,0($t3) sw $t7,0($t3) add $t6,$t2,$t8 addi $t3,$t5,4 (a) Draw a general pipeline diagram from CC1 to CC5 (b) Can you identify the type of hazard in pipeline for executing the code? (c) What is the solution to the hazard? If NOP (noop or bubbles) have to be inserted to avoid hazard, where will you put them? (d) Put the code into the MIPS simulator and observe your findings. You may want to...
Convert the following MIPS instructions Into Machine Code Instructions. Assume the first Instruction starts at memory address 20000 slt $t1, $s1, $s0 beq $s1, $s2, L1 beq $t1, $zer0, L2 j Exit L1: add $s1, $s1, $s1 j Exit L2: add! $s1, $s1, 1 Exit:
Question 3 (10 points) Convert the following MIPS assembly code into machine language. Write the instruction in hexadecimal. The opcode for sw 43 (101011). sw St1, -4(St3) Question 4 (10 points) Consider the following MIPS assembly code: addi $s3, $0, 5 addi $s1, S0, 3 addi Ss1, $s1, 2 beq Ss3, Ssl, target addi Ss1, Ss1, 1 target: add Ss3, Ss1, Ssl a. After running the code, what is the value of Ss3? b. If the memory address of the...
Given the following sequence of instructions: lw $s2, 0($s1) //1 lw $s1, 40($s3) //2 sub $s3, $s1, $s2 //3 add $s3, $s2, $s2 //4 or $s4, $s3, $zero //5 sw $s3, 50($s1) //6 a. List the read after write (current instruction is reading certain registers which haven’t been written back yet) data dependencies. As an example , 3 on 1 ($s2) shows instruction 3 has data dependency on instruction 1 since it is reading register $s2. b. Assume the 5...
Name B. (7 pts) MIPS short answer 1. (3pt) For the following MIPS assembly language program: loop: addi Sto, $to,-1 bne $to, $zero, loop Translate the second instruction into MIPS machine language and write it in hex. 2. (2 pt) Which best describes the reason that we maintain the stack pointer in a register? (circle one) i. The hardware forces use of a stack pointer. ii. We need a local pointer because we are often limited to relative addressing. ili....
This is vhdl code can you please explain how they got the
answer?
How many sor following instructions are executed by the MIPS single-cycle per instruction processor from class proces cycles will it elelt take for this processor's program counter to reach the "nop" instruction? To get credit explain how the cycles are accountecd andi $3, $3,0 andi $2, $2,0 addi $2, $2, 20 : initialize to O ; clear reg. ;loop bound ;load x(i) to R15 ; load yi)...