CS 5330 001 Assignment 2 4 Due 11 59pm September 19 2024 QUESTION 1 8 Number conversion a Convert to binary 248310 3E8A16 I II I II III b Convert the following 8 bit binary numbers to decimal 111010112 100000002 010001012 Give 2 sets of answers Assuming that they are signed 2 s complement numbers Assuming that the numbers are unsigned For example as a signed number 111101012 11 as unsigned number 111101012 245 QUESTION 2 6 Do the following addition exercises by translating the numbers into 8 bit 2 s complement binary numbers performing the arithmetic and translating the result back into a decimal number Indicate where overflow occurs and why based on the binary arithmetic a 47 38 b 47 38 c 47 38 d 47 88 e 47 88 f 47 88 QUESTION 3 9 Assume that registers s0 and s1 hold the values 8000000016 and D000000016 respectively a What is the value of t0 for the following assembly code b Is the result in t0 the desired result or has there been overflow c For the contents of registers s0 and s1 as specified above what is the values of t0 for add t0 s0 s1 the following assembly code sub t0 s0 s1 d Is the result in t0 the desired result or has there been overflow e For the contents of registers s0 and s1 as specified above what is the values of t0 for the following assembly code add t0 s0 s1 add t0 t0 s0 f Is the result in t0 the desired result or has there been overflow QUESTION 4 10 For the following C statement write the corresponding MIPS assembly code Assume that the variables i and j are assigned to registers 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 use sll shift left logical for multiplication of 2 4 QUESTION 5 12 For the MIPS assembly instructions below what is the corresponding C statement 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 t0 f 4 t1 g 4 sll t0 s0 2 add t0 s6 t0 t0 A f sll t1 s1 2 add t1 s7 t1 t1 B g lw s0 0 t0 addi t2 t0 4 lw t0 0 t2 add t0 t0 s0 sw t0 0 t1 f A f QUESTION 6 10 Consider the following MIPS code assuming 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 array A is in register s6 addi add sw t0 s6 4 t1 s6 0 t1 0 t0 t0 0 t0 s0 t1 t0 lw add a Translate the above MIPS code to C b For each MIPS instruction show the values of the opcode op source register rs and funct field and destination register rd fields In addition for the I type instructions show the value of the immediate field and for the R type instructions show the value of the second source register rt QUESTION 7 6 Assume the following register contents t0 AAAAAAAA16 t1 1234567816 a For the register values shown above what is the value of t2 for the following sequence b For the register values shown above what is the value of t2 for the following sequence c For the register values shown above what is the value of t2 for the following sequence of instructions sll t2 t0 4 or t2 t2 t1 of instructions sll t2 t0 4 andi t2 t2 1 of instructions t2 t0 3 srl andi t2 t2 0xFFEF QUESTION 8 14 Find the shortest sequence of MIPS instructions that extracts bits 16 down to 11 from register t0 and uses the value of this field to replace bits 31 down to 26 in register t1 without changing the other bits of register t1 QUESTION 9 5 Assume t0 holds the value 0010100016 What is the value of t2 after the following instructions t2 0 t0 t2 0 ELSE DONE slt bne j ELSE addi t2 t2 2 DONE QUESTION 10 15 Consider the following C code 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 the base address of the array D for i 0 i a i for j 0 j b j D 4 j i j a Translate the above C code to MIPS assembly code Use a minimum number of instructions No pseudo instructions b How many MIPS instructions does it take to implement the C code If the variables a and b are initialized to 10 and 1 and all elements of D are initially 0 what is the total number of MIPS instructions that is executed to complete the loop QUESTION 11 5 For the following code t0 0 t1 t0 0 t2 lbu sw Assume that the register t1 contains the address 0x10000000 and the data at the address is 0x11223344 Assume t2 contains the address 0x10000004 a What value is stored in 0x10000004 on a big endian machine b What value is stored in 0x10000004 on a little endian machine 1 Clearly write your answers to the corresponding questions in a WORD or plain text file 2 Submit your answers clearly marked with your name through eLearning by the due 3 Plagiarizing homework answers obtained from the internet or AI chatbots is not 4 No late homework or assignment will be accepted SUBMISSION date permitted Yi Zhao
View Full Document