23Sp_test2

docx

School

University of Massachusetts, Lowell *

*We aren’t endorsed by this school

Course

2030

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

4

Uploaded by PresidentAardvarkPerson806

Report
COMP.2030 Test 2 3/17/23 Not allowed to use electronic devices including a calculator, a cell phone, etc. ID:________________________ NAME:____________________________________________ 1. (20 pt) Variables x and y are of an integer type and have arbitrary, valid values. Similarly, ds and dt are of a double data type with arbitrary values (also valid). For each of the following C expression, answer True/False to indicate whether the expression always yields 1 (true). For the relationship that is False, give an example that makes it yield False. a. ((x+y)<<2) +y – x == 5*y + 3*x (TRUE) b. x > y == –x < -y (TRUE) c. (double)(float) x == (double) x (FALSE) d. dt*dt >= 0.0 (TRUE) e. (dt + ds) – dt == ds (FALSE) 2. (10 pt) A floating point number format has 5-bit exp and 7-bit frac (sign bit is ignored). Write the following binary numbers shown in a scientific notation into the given floating point. 1.0101010x2 -5 exp: ___01010_ frac: ______0101010 1.1010101x2 5 exp: ___10100 frac: 10101010
3. (27 pt) The following positive real numbers are decimal values. Represent each of them into an IEEE floating point format with a sign bit, a 5-bit exponent, and a 10-bit fraction fields. Answer resulting each 16-bit string in hexadecimal. a. 8 9 (hint: 64 9 = 7 1 9 ) b. 15.1 c. 9 1 3 4. (10 pt) A linked list node has a 2-word for the field, val, and two double links , left and right. Each link is 32 bits, or 4 bytes. Each list node thus has four words, and is declared as below. struct node {struct node *left; double val; struct node *right;}. Write C function func(struct node *t) corresponding to the MIPS on the right in ONE C statement. void func(struct node *t){ # argument t is passed via $a0 func: lw $t0, 12($a0) lw $t1, ($a0) sw $t1, ($t0) jr $ra
5. (10 pt) Suppose we have two sets of MIPS codes shown below, which belong to the same program. MIPS codes on the left are being executed. What is the content of $t0 when the instruction at the label ‘cont’ is about to be executed. Write your answer in HEX. 6. (10 pt) The jump table in problem 5 above is located in the text segment. However, it can be constructed with target addresses alone in the data segment as shown on the right.Write MIPS instructions between ‘sll $s0, $s0, 2’ and ‘cont’ so that the program branches to the desired label among F0, F1, and F2 according to the index $s0 as in the code segment above. 7. (12 pt) An assembler generates a symbol table storing the symbol (max 8 characters), its value, and the status of the symbol for each line of instructions. The status has a flag if the symbol is defined (found in label field) or not. For the following snippet of the MIPS codes, show the symbol table after each line of instructions is assembled (starting at address 0x0400). WW: b F0 b F1 b F2 F0: add $t0, $t0, $t1 b cont F1: sub $t0, $t0, $t1 b cont F2: mul $t0, $t0, $t1 b cont li $t0, -2 li $t1, 4 la $s1, WW li $s0, 2 sll $s0, $s0, 2 add $s1, $s1, $s0 jr $s1 cont: .data WW: .word F0 .word F1 .word F2 .text F0: add $t0, $t0, $t1 b cont F1: sub $t0, $t0, $t1 b cont F2: mul $t0, $t0, $t1 b cont la $s1, WW li $s0, 2 sll $s0, $s0, 2 add $s1, ($s1) $0 lw $s1, ($s1)0 jr $s1 cont:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
newline: li $t5, 0 jal printline b newline printline: li $a3, 0 newline: li $t5,0 Jal printline b newline printline: li $a3,0 Symbol Value Status bit Newline 0x0400 1 Symbol Value Status bit Newline 0x0400 1 Printline 0x0404 0 Symbol Value Status bit Newline 0x0400 1 Printline 0x0404 0 Newline 0x048 0 Symbol Value Status bit Newline 0x0400 1 Printline 0x0404 0 Newline 0x0408 0 Printline 0x040C 1