CPS 104 (Ramm) Page 1 of 4 2 Nov. 1994 Fall Semester, 1994 OPEN BOOK Hour Test #2 NAME________________________ When possible, answer on the test sheets or on the back. Use additional sheets if needed. (25) A. 1) Hand assemble the following program for an hypothetical A ____ machine similar to the one used in lectures to explain two pass assemblers. For each instruction, the location and machine (5) language code should be given in decimal. B ____ 2) Show what the symbol table would look like at the end of the first pass. (5) C ____ NOTE: Assume everything is simple; all addressing is absolute. It has only 1 accumulator (which isn't mentioned in each instruction). (5) Assume all addressing is in terms of words, that the accumulator D ____ is one word long, that each instruction is one word long, etc. The symbol table requires only two columns. Assume that each (10) instruction is 5 decimal digits long; that it has a two digit E ____ opcode, and a 3 digit address field. (A word = 5 decimal digits.) (5) LOC. MACHINE LANG ASSEMBLER LANGUAGE F ____ ORG 200 (3) G ____ A DW ? (10) B DW A H ____ START LOAD C (5) I ____ AGAIN ADDI B - A (30) CMPI CHECK J ____ JL QUIT (5) K ____ JMP AGAIN (4) QUIT STORE A L ____ HALT (4) M ____ ORG 100 (4) C DW -2 N ____ -------- CHECK EQU 110 SYMBOL TABLE: END START TABLE OF OP CODES: ADD 11 ADDI 16 CMP 30 CMPI 35 HALT 00 JG 43 JL 44 JMP 41 LOAD 21 STORE 22 SUB 12 SUBI 17 Test #2 NAME ___________________ Page 2 of 4 B. For a simple two pass assembler, which one(s) of the following kinds of statements directly result(s) in a change to the LOCATION COUNTER 1) an ORG statement (i.e. origin)? 2) an EQU statement (i.e. equivalence)? 3) an arithmetic statement such as ADD without a label? 4) an HALT statement with a label? C. To handle the input from a keyboard, a system could use either 1) interrupt driven I/O or 2) direct control (busy-waiting). Which of these two methods is the EASIER TO PROGRAM? D. Explain why the use of a paged virtual memory system may actually reduce the memory requirements for a given execution. E. Assume that the IBM PC assembler syntax for macros (covered in class) is applied to the MIPS machine. Assume we define the following macro: mystery macro b, a sll b, a, 2 add b, a, b sll b, b, 1 endm Then assume we invoke it with: lui $t2, 23 mystery $t4, $t2 lui $v0, 1 move $a0, $t4 syscall 1) Show the expanded version of this code (with the macro substitutions made.) 2) what output does this code fragment produce? Test #2 NAME__________________ Page 3 of 4 F. Explain how in a UNIX file system, the same file may have more than one name. Include the roles that inodes and directories play in this. G. TRUE/FALSE: In UNIX the file name is contained in the inode? H. Assume a very simple hypothetical machine as is assumed for problem A above. Of the statements show below, which one would need relocation (which statements would have to be fixed up if the program were moved)? Put an "R" next to each statement so identified. ORG 200 A DW ? B DW A START LOAD C AGAIN ADDI B - A CMPI CHECK JL QUIT JMP AGAIN QUIT STORE A HALT ORG 100 C DW -2 CHECK EQU 110 END START I. In virtual memory systems in general and in the simple system described in lecture, which address is longer (i.e. has more bits): 1) The physical address of real memory? OR 2) The virtual address? Test #2 NAME__________________ Page 4 of 4 J. On the back of the previous page, write a simple MIPS assembler language procedure that searches a section of memory for the occurrence of a particular character. Assume that the address of the search area is passed in the $A0 register, that the length of the area is passed in the $A1 register, and that the search character is passed as the low order byte of the $A2 register. Your procedure should change $A0 to 0 if the character is not found and to the address of the first occurrence of the character if it is found. (You may ignore subsequent occurrences.) Write this routine so that it is ready to be separately assembled. You need not show you main program. However, your procedure should be complete and preserve all registers (other than $A0) that are supposed to be preserved over procedure calls. You need not include a flowchart or any other signs of documentation. K. We have made the distinction between (1) an INTERRUPT (or true interrupt), (2) a TRAP, and (3) a SUPERVISOR CALL (or service call) Classify each of the following occurrences as one of these three: OCCURRENCE CLASSIFICATION 1) The computer response to an invalid instruction. __________ 2) We request that the operating system allocate more memory. __________ 3) The computer deals with a divide by zero. __________ 4) Computer responds to a press of the break key of a keyboard. __________ 5) The printer signals the completion of an I/O operation. __________ L. TRUE/FALSE: In the data path of our example microarchitecture (Page 171) the 16 registers could have been placed in any order? M. TRUE/FALSE: In the data path of our example microarchitecture (Page 171) the A and B latches are used to allow the C bus to load several registers simultaneously. N. TRUE/FALSE: In the microinstruction shown in Fig 4-9, Page 174, we show the ENC field. It is needed because with only four bits, there is no way to indicate that none of the 16 registers are to be loaded from the C bus.