231 Fall 2007 -- Exam 1 Name:________________________ Word Bank - questions 1-8. Place the appropriate term by its description below. (2 pts. each) accumulator machine direct addressing immediate value load/store machine indexed addressing memory location stack machine indirect addressing register ALU load address instruction location counter (loc) CPU store label pseudo-op program counter (PC) 1. _____________________ an assembly language statement that doesn't generate a machine instruction but instead acts as a directive to the assembler 2. _____________________ an instruction that will make a copy of the value in the accumulator (or other register) and place it into a specified memory word 3. _____________________ unit within a computer that performs arithmetic and logical computations (it has no registers) 4. _____________________ machine design in which an add instruction only has an opcode (the source operands are fetched from, and the result is stored in, a structure within the CPU) 5. _____________________ a symbolic name in an assembly language program used to access data or as a branch target 6. _____________________ addressing mode in which the instruction holds the address of a memory word which contains the address of the memory word which is accessed as data 7. _____________________ register in the CPU that contains the address of the memory word from which the next instruction will be fetched 8. _____________________ a number used as the name of a memory location 9. Define "assembly language" and "machine language", clearly indicating both the difference between them and the relationship between them. (8 pts.) Give the power of ten that corresponds to these prefixes. (2 pts. each) 10. mega _____________ 12. milli _____________ 11. giga _____________ 13. micro _____________ 14. (a) Why do assemblers use two passes? ______________________________ (Hint: two words.) (2 pts.) (b) What does the first pass do? increment the ____________________ (Hint: two words each.) and (2 pts. each) build the ________________________ (c) What does the second pass do? __________________________________ (Hint: one word.) (2 pts.) 15. On the right hand side, give the symbol table produced by the first pass of the assembler for the following accumulator machine program. (12 pts.) word(data,five) word(five,5) word(ten,10) label(start) load(ten) sub(ten) store(data) halt end(start) 16. The opcodes for the load, sub, store, and halt instructions are 50, 30, 60, and 0, respectively. On the right hand side give the executable file produced by the second pass of the assembler for the following accumulator machine program. (14 pts.) word(data,five) word(five,5) word(ten,10) label(start) load(ten) sub(ten) store(data) halt end(start) accumulator machine instruction set opcode address operation name machine action ------ ------- -------------- -------------- halt ---- halt stop execution div addr divide acc = acc/memory[addr] mul addr multiply acc = acc*memory[addr] sub addr subtract acc = acc-memory[addr] add addr add acc = acc+memory[addr] load addr load acc = memory[addr] store addr store memory[addr] = acc ba addr branch always pc = addr blt0 addr branch on less than if acc<0 then pc = addr ble0 addr branch on less than or equal if acc<=0 then pc = addr beq0 addr branch on equal if acc==0 then pc = addr bne0 addr branch on not equal if acc/=0 then pc = addr bge0 addr branch on greater than or equal if acc>=0 then pc = addr bgt0 addr branch on greater than if acc>0 then pc = addr 17. Analyze this program segment and provide a concise explanation of what it does. Be accurate but also be as brief as possible in conveying the effect of the segment. (E.g., a line-by-line narrative is nonresponsive.) (8 pts.) word(a,__) word(b,__) word(c,__) ... load(a) sub(b) blt0(there) load(a) store(c) ba(done) label(there) load(b) store(c) label(done) 18. Give the output and explain what the following m4 macro does when called as "test(0)" (8 pts.) define(`test',`ifelse(len($1),0,equal,not equal)') Extra Credit 1. Give the output and explain what the redefined m4 macro does when called as "test(3)". (Note the absence of quotes in the body of the definition.) (4 pts.) define(`test',ifelse(len($1),0,equal,not equal)) 19. Write code that implements the expression y = ((x-1)*(x-7))/(x-11) in the assembly language for the accumulator machine. Do not overwrite source operands. (18 pts.) Assume this data section: word(one_m,1) word(seven_m,7) word(eleven_m,11) word(x_m,1) word(y_m,0) word(temp1_m,0) word(temp2_m,0) comment(`add others if needed') Extra credit 2. (up to 6 pts.) We discussed in class how an algorithm could be fully implemented in hardware, fully in software, or in a hybrid manner. Consider implementing an assembler fully in hardware. Identify and explain the pros and cons of doing so. (Knee-jerk responses will garner some credit, but well-thought-out and well-expressed responses will receive more credit.)