Title: Chapters 914 Exam 3 Review
1Chapters 9-14Exam 3 Review
2Exam 3 Information
- Tuesday to FridayBe sure to check the testing
centers hours! - Closed book, closed note, no time limit
- No calculators or electronic devices are allowed
- Covers chapters 9-14
- 50 multiple choice questions (1-25 1 point, 26-50
3 points) - You may NOT write on exam! But only the bubble
sheet will be graded
3Suggestions on Studying for an Exam
- Make sure you understand these review slides
- Review your homework
- Make sure you understand your mistakes
- If you guessed on anything, go back and see why
your guess was right or wrong - Skim through the all the lecture slides
- Slow down and take a close look when you get to a
topic with which you arent comfortable - Reread the relevant paragraphs in the book, if
necessary - Read the review topics posted online
- Look at relevant lecture slides if you arent
completely confident you understand the topic
4Suggestions on Studying for an Exam
- As you review, ask yourself questions
- Consider scenarios or ideas not discussed in
class - Dont just read try to understand
- If you find something you dont understand, take
the time to figure it out! - Look at other sources or examples
- Try not to move on without resolving your
questions - Ask the TAs or instructor about questions you
cannot resolve or topics you dont understand
5Test Taking Strategy
- Take your time!
- Theres no time limit on these exams
- Read each question carefully and completely
- Dont be mislead by a partially correct answer
- The correct answer may be further down the list
- If you read too quickly you might miss keywords
- Double-check any question that involves
calculation - If possible, solve the problem a different way
6Exam 3 Review
- What is the purpose of the trap and interrupt
vector tables? - They contain the starting addresses of the trap
and interrupt service routines - How does the TRAP instruction compare with the
JSR instruction? - TRAP gets its target address from the trap vector
table, whereas JSR uses PCoffset to calculate
its target address - TRAP loads the PC with an OS address, JSR loads
PC with user-space address - The programmer/assembler does not need to know
the target address for a trap service routine
it just needs its number. The programmer/assembler
must know the target address for a subroutine to
be called with JSR
7Exam 3 Review
- What is the purpose of the LC-3 TRAP instruction?
- For calling OS service routines for common system
operations (e.g., I/O) - What precautions must be taken regarding R7 in
assembly code that uses TRAP or other
subroutines? - A subroutine must properly save and restore R7 if
it going to be modified (e.g., by making another
subroutine call) - What is the difference between caller-save and
callee-save? - Caller-save Code saves needed registers before
calling a subroutine, restores them after
subroutine returns - Callee-save Subroutine saves registers before
using them, restores them before returning
8Exam 3 Review
- What is polling?
- A method of I/O where a loop is executed to
constantly check a device status register until
the device is ready - What is interrupt driven I/O?
- A method of I/O where an I/O device informs the
CPU that it is ready via an interrupt signal,
causing the CPU to interrupt what its other
processing and service the device - What are the advantages/disadvantages of each?
- Polling is very simple and requires little code,
but is often inefficient because it keeps the
processor busy - Interrupt driven I/O is more complicated and
requires more code, but is usually much more
efficient (especially for slow I/O devices)
because the CPU can be doing other processing
while waiting for an I/O device
9Exam 3 Review
- What are the KBSR, KBDR, DSR, and DDR?
- Keyboard Status Register
- Keyboard Data Register
- Display Status Register
- Display Data Register
10Exam 3 Review
- What is the MCR?
- Machine Control Register
- What is the MCR used for?
- MSB is ANDed with clock
- Can be used to halt the machine
- Whats the common name for a LIFO data structure
- A stack
- How does a LIFO data structure behave
- Last In First Out
- The last item pushed will be the next item popped
11Exam 3 Review
- What is the stack pointer?
- R6 on the LC-3
- Always points to top of run-time stack
- Write the push and pop operations for the LC-3
- PUSH ADD R6, R6, -1 STR R0, R6, 0
- POP LDR R0, R6, 0 ADD R6, R6, 1
- What is stack overflow?
- When too many items are pushed onto the stack
- What is stack underflow?
- When too many items are popped off the stack
12Exam 3 Review
- What are the advantages of high-level languages
as compared to low-level? - Allows us to give symbolic names to values
- ISA independent
- More expressive do more with less code by
providing commonly used operators, data types,
and control structures - More readable, easier/faster to write and debug
- Provides safeguards, such as checking data type
usage and checking for common errors - Provides commonly used operators
13Exam 3 Review
- What are the differences between an interpreter
and a compiler? - Compiler creates an executable image once,
whereas interpreter must interpret the program
each time it is run - Compiled code runs faster
- Interpreted programs are platform independent
- Interpreted code is often easier to debug and
develop
14Exam 3 Review
- What are the three components of a compiler
- Preprocessor
- Compiler (and assembler)
- Linker
- In which order are the compilers components run?
- Preprocessor ? Compiler (and assembler) ? Linker
- What does the preprocessor do?
- Preprocesses your C code, making insertions,
deletions, and substitutions - What does the compiler do?
- Converts the preprocessed code into a binary
object module - What does the linker do?
- Links the binary object file with libraries
and/or other object files to create the final
executable image
15Exam 3 Review
- What are the essential components of a C program?
- include ltstdio.hgtint globalVarint
main() int localVar 1 printf(d and d
makes d\n, globalVar, localVar,
globalVarlocalVar) - Where does a C program start?
- The main() function
- Preprocessor Directives
- Variable declarations
- The main() function (must be present)
- Statements (ending in or )
- Note the syntax!
16Exam 3 Review
- What are valid C identifier names?
- Must start with letter or underscore, not with
number - Cannot use C operator symbols (, -, /,
, gt, etc.) - Cannot use C reserved words (for, if,
while, etc.) - What are the differences between a local and
global variables? - Local variables are not initialized by default,
global variables initialized to 0 - Local variables are stored on the stack (pointed
to by the frame pointer, R5), global variables
stored in global data section (pointed to by R4) - Local variables have limited scope (from the
variable declaration to the following ),
global variables can be used anywhere in the
program
17Exam 3 Review
- How big of a number can be stored in a variable
of type int? - Depends on ISA!
- Whats the difference between int and signed int?
- They are the same
- Which can represent more values, an int or an
unsigned int? - The ranges are different, but they both represent
the same number of values (2n where n is the
number of bits) - E.g., -32,768 to 32,767 compared to 0 to 65,535
(both 16-bit) - Or in general -2n-1 to 2n-1-1 compared 0 to
2n-1-1 - Which is bigger, a char or int?
- Usually int, but depends on ISA
- On the LC-3, they are the same!
18Exam 3 Review
- Whats the difference between bitwise and logical
operators in C? - Bitwise operators operate on individual bits
using Boolean operators (hence the name bitwise) - Logical operators treat the operands as Boolean
values and produce a Boolean result (0 or 1) - Example x 6 y 5
- x y ? 01102 01012 ? 01002 ? 4
- x y ? true true ? true ? 1
19Exam 3 Review
- What is operator precedence?
- Determines the order in which operations are
executed in an expression - See the operator precedence table for details
- How is variable scope determined?
- Based on where the variable is declared
- Local variables are declared within a function,
and scope is from variable declaration to - Global variables are declared outside any
function, scope is global
20Exam 3 Review
- What does the following code do?
START add r6, r6, -2 str r2, r6, 0 str r3,
r6, 1 and r0, r0, 0 and r3, r3, 0 add r2,
r2, 0 brzp L02 not r2, r2 add r2, r2,
1 add r3, r3, -1 L02 add r2, r2,
0 brz L04 add r2, r2, -1 add r0, r0,
r1 brnzp L02 L04 add r3, r3, 0 brz L06 not r0
, r0 add r0, r0, 1 L06 ldr r2, r6,
0 ldr r3, r6, 1 add r6, r6, 2 ret
21Exam 3 Review
- What does the following code do?
START add r6, r6, -2 Store r2, r3 on the
stack str r2, r6, 0 NOTE r0 isnt stored on
the stack since str r3, r6, 1 a value
gets returned in r0 and r0, r0, 0 Clear
r0,r3 and r3, r3, 0 add r2, r2, 0 Test r2,
if negative then invert r2 and brzp L02 set
flag in r3 not r2, r2 add r2, r2, 1 add r3,
r3, -1 L02 add r2, r2, 0 Test r2, if zero
then skip to the end brz L04 else perform
multiplication loop add r2, r2, -1 add r0, r0,
r1 brnzp L02 L04 add r3, r3, 0 Test r3, if
flag set then invert mult result brz L06 not r0,
r0 add r0, r0, 1 L06 ldr r2, r6, 0
Restore r2,r3 from the stack ldr r3, r6,
1 add r6, r6, 2 Clean up the stack
pointer ret
22Exam 3 Review
- What does the following code output?
include ltstdio.hgt int x int main() int y
x int x 15 int i 0 for (i 0 i
lt 4 i) int x i printf("d d\n",
x, y) printf("d d\n", x, y)
0 0 1 0 2 0 3 0 15 0