Question

In: Computer Science

1) Provide the type and assembly language instruction for the following binary value: 0000 0010 0001...

1) Provide the type and assembly language instruction for the following binary value: 0000 0010 0001 0000 1000 0000 0010 0000 (two)

2) Provide the type, assembly language instruction, and binary representation of instruction described by the following MIPS fields: op=0, rs=3, rt=2, rd=3, shamt=0, funct=34

3)For the following C statement, write a minimal sequence of MIPS assembly instructions that does the identical operation. Assume $t1 = A, $t2 = B, and $s1 is the base address of C. A = C[0] << 4;

4) Consider the following MIPS loop:

LOOP: slt $t2, $0, $t1

beq $t2, $0, DONE

subi $t1, $t1, 1

addi $s2, $s2, 2

j LOOP

DONE:

4a) Assume that the register $t1 is initialized to the value 10. What is the value in register $s2 assuming $s2 is initially zero?

4b) For each of the loops above, write the equivalent C code routine. Assume that the registers $s1, $s2, $t1, and $t2 are integers A, B, i, and temp, respectively.

4c) For the loops written in MIPS assembly above, assume that the register $t1 is initialized to the value N. How many MIPS instructions are executed?

Solutions

Expert Solution

1) Provide the type and assembly language instruction for the following binary value:
0000 0010 0001 0000 1000 0000 0010 0000 (two)
Answer:----------

000000 10000 10000 10000 00000 100000
Op=0 rs = 16 rt = 16 rd = 16 shamt=0 funct =0x20
(add) ($s0) ($s0) ($s0) (add)

Thus this is a R-type instruction: add $s0,$s0,$s0


2) Provide the type, assembly language instruction, and binary representation of instruction described by the following MIPS fields: op=0, rs=3, rt=2, rd=3, shamt=0, funct=34
Answer:----

000000 00011 00010 00011 00000 100010
Op=0 rs = 3 rt = 2 rd = 3 shamt=0 funct =34
($v1) ($v0) ($v1) (sub)

So,
Type of instruction:---------
R-type instruction
Assembly language instruction :----------- sub $v1, $v0 , $v1


3)For the following C statement, write a minimal sequence of MIPS assembly instructions that does the identical operation. Assume $t1 = A, $t2 = B, and $s1 is the base address of C. A = C[0] << 4;
Answer:----
Assume the base address of C is in $s1 and that A is in $s2. Use the minimum number of registers. Do not destroy   the contents of $s1 or $s2.  
A   =   C[0]   <<   4;  

lw $t1,   0($s1) ---------------------- # loads C[0] into A  
sll $t1 ,$t1, 4 --------------------------# shift left by 4 bits contents of $t1  
sw $t1,   0($s2) --------------------- #  store C[0] << 4 into A  

4) Consider the following MIPS loop:

LOOP: slt $t2, $0, $t1

beq $t2, $0, DONE

subi $t1, $t1, 1

addi $s2, $s2, 2

j LOOP

DONE:

4a) Assume that the register $t1 is initialized to the value 10. What is the value in register $s2 assuming $s2 is initially zero?
Answer:----
LOOP:
slt $t2, $0, $t1 ------------------------- # if $t1 > 0 then $t2 = 1 else $t2 = 0
beq $t2, $0, DONE ------------------- # if $t2 = 0 then go to DONE
subi $t1, $t1, 1-------------------------- # $t1 = $t1 -1
addi $s2, $s2, 2 ------------------------- # $s2 = $s2 + 2
j LOOP --------------------------- # Go to LOOP
DONE:

Number of loop executions:
$t1 at top = 10;
$t1 at bottom = 9
...............…
t1 at top = 1; $t1 at bocom = 0 => 10 executions => s2 = 2x10 = 20

4b) For each of the loops above, write the equivalent C code routine. Assume that the registers $s1, $s2, $t1, and $t2 are integers A, B, i, and temp, respectively.
Answer:----
while(i > 0){
i= i // Decrement i by one during each iteration of the loop (sub $t1, $t1, 1)
B = B + 2 // Increment B by 2 each time (addi $s2, $s2, 2)
} //exit loop

4c) For the loops written in MIPS assembly above, assume that the register $t1 is initialized to the value N. How many MIPS instructions are executed?
Answer:----
Base case: N= 0. If N=0, only 2 MIPS instructions are executed:

LOOP: slt $t2, $0, $t1 -------------------------- # 0 == 0; here, $t2 = 0 [#1]
beq $t2, $0, DONE ------------------------------ # 0 == 0; go to DONE [#2]
sub $t1, $t1, 1
addi $s2, $s2, 2
j LOOP
DONE:
For any value of N > 0, (N full loops + 2 lines) of MIPS instructions must be executed; each full loop contains 5 MIPS instructions. Therefore, if the register $t1 is initialized to the value N, a total of (5*N)+2 MIPS instructions are executed.


Related Solutions

Provide the instruction type, assembly language instruction, and binary representation of the instruction described by the...
Provide the instruction type, assembly language instruction, and binary representation of the instruction described by the following LEGv8 fields: op = 0x458, Rm = 14, Rn = 16, Rd = 18, shamt = 0
Multiply the following 16 bit signed binary number together Provide a 32bit signed binary answer 0000...
Multiply the following 16 bit signed binary number together Provide a 32bit signed binary answer 0000 0001 0001 0001 1111 1111 1000 0000
1) What are the hexadecimal, and octal equivalents for the unsigned binary value 0111 0000 1101?...
1) What are the hexadecimal, and octal equivalents for the unsigned binary value 0111 0000 1101? (note the spaces in the binary are for readability (like a comma in a decimal value; there is only a single 12 bit binary value) PLEASE EXPLAIN IT IN DETAIL
Write a possible assembly language instruction or set of instructions to accomplish the following: a) Compare...
Write a possible assembly language instruction or set of instructions to accomplish the following: a) Compare the byte stored at the memory location pointed to by register R4 to the upper (higher) byte stored in register R5 b) Branch to instruction at label ‘ZERO’ if the lower byte of register R6 is zero c) Jump to the instruction at label ‘EVEN’ if the value in register R7 is an even number
Assembly Language Programming: a)If eax = 0FFFFFFFFH, and edx = 0FFFFFFFFH, then the instruction                            
Assembly Language Programming: a)If eax = 0FFFFFFFFH, and edx = 0FFFFFFFFH, then the instruction                              imul edx will leave the value ______________________________ in the edx register. b)If eax = 0D000000DH, and edx = 50000005H, then the instruction                              idiv dl will leave the value ______________________________ in the eax register. c)If ax = 3BC4H, then the following instructions                              cmp ah, al jg   Label will / will not cause a jump to Label. d)If ax = 3BC4H, then...
Write in ARM assembly language the following operations without using multiplication instruction: a) A * 17...
Write in ARM assembly language the following operations without using multiplication instruction: a) A * 17 b). A * 23
Assume that the instruction pointer, EIP, initially contains 2010 and the assembly language representation of the...
Assume that the instruction pointer, EIP, initially contains 2010 and the assembly language representation of the instructions in memory starting at address 2010 is Instruction Address Instruction 20 CMP DL, 0xD2 21 JE 72 Before the instruction sequence is executed, the flags are CF=0, ZF=0 and SF=0 and the Registers have the values AL=0x0D, BL=0xA9 CL=0x5E andDL=0xCF. What is the value of the instruction pointer after the sequence executes?
The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly instruction. What...
The following 32-bit binary word written in hexadecimal format represents a single RISC-V assembly instruction. What is the RISC-V instruction format and specific assembly language instruction? 0xfe810113
ASSEMBLY LANGUAGE PROGRAMMING 1. The decimal equivalent of the signed 2’s complement 8-bit binary number 11010101B...
ASSEMBLY LANGUAGE PROGRAMMING 1. The decimal equivalent of the signed 2’s complement 8-bit binary number 11010101B is ______________. 2. The decimal equivalent of the unsigned 8-bit hex number 0B4H is ______________. 3. The value of the expression ‘H’ – ‘B’ is less than / equal to / greater than that of the expression ‘L’ – ‘C’. 4. If the .data segment contains declarations A BYTE 2 DUP (‘a’), ‘+’ B BYTE 3 DUP (‘b’), 0 C BYTE 4 DUP (‘c’),...
Represent following LEGv8 machine code into assembly instruction. 0x784302CD
Represent following LEGv8 machine code into assembly instruction. 0x784302CD
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT