Shared Flashcard Set

Details

Exam 2
Chapter 6-9 Quizzes
28
Computer Science
Undergraduate 2
11/18/2015

Additional Computer Science Flashcards

 


 

Cards

Term
True or False? The LC-3 uses special input/output instructions to communicate with I/O devices.
Definition
False, uses Load/Store
Term
True or False? In the LC-3, when the number 5 on the keyboard is pressed, KBDR holds the 2's complement representation of that number.
Definition
False- it holds ASCII value
Term
True or False? An I/O device can signal the microprocessor when it needs to interact with it. This form of interaction is known as polling.
Definition
False- this is interrupts
Term
True or False? The LC-3 has two device registers to handle input from the keyboard. The keyboard data register (KBDR) and the keyboard status register (KBSR).
Definition
True
Term
What does the following LC3 program do (give your answer in terms of the inputs in registers R1 and R2, and the output in R3).
.ORIG x3000
AND R0, R0, #0; _____
ADD R0, R0, #1; _____
NOT R1, R1; _____
ADD R1, R1, R0; _____
ADD R3, R1, R2; _____
HALT
Num .FILL x0000
.END
Definition
clear R0; set R0=1; complement input in R1; add 1 to complement of R1 = negate original value in R1 to get (-R1); add R1 and R2 - therefore R3 contains, in terms of inputs, R2-R1
Term
True or False? The LC-3 uses the Load and Store instructions to communicate with I/O devices.
Definition
True
Term
True or False? Polling the I/O device is more efficient than Interrupt driven I/O.
Definition
False, interrupts are more efficient
Term
True or False? In the LC-3, when the number 7 on the keyboard is pressed, KBDR holds the 2's complement representation of 7.
Definition
False, KBDR holds ASCII value
Term
True or False? The LC-3 has three device registers to handle input from the keyboard. The keyboard data register (KBDR), keyboard power indicator (KPR), and the keyboard status register (KBSR).
Definition
False
Term
What does the following LC3 program do (give your answer in terms of the inputs in registers R1 and R2, and the output in R3).
.ORIG x3000
LD R0, Num; _____
NOT R1, R1; _____
ADD R1, R1, R0; _____
ADD R3, R1, R2; _____
HALT
Num .FILL x0001
.END
Definition
load value at address Num int R0...therefore 1 is loaded into R0 and now R0=1; complement original value in R1; add 1 to complement of R1 = negate original value in R1, i.e., (-R1); add R1 and R2 - therefore R3 contains, in terms of inputs, R2-R1
Term
What is printed out by the following code segment in C:
{int x = 0;
{int x = 1;
int y;
int z;
y = x++; /*_____*/
printf("y= %d\n", y); /*_____*/
z = ++x; /*_____*/
printf("z= %d\n", z); /*_____*/
}
printf("x= %d\n", x); /*_____*/
}
Definition
post increment...assign value of x to y and then increment x, prints y=1, pre-increment- increment x, to 3, and assign to z, prints z=3, prints x=0
Term
The RET instruction in LC3, to return from a TRAP (or a subroutine), returns to the calling program by setting the program counter (i.e., next instruction to be executed) equal to the value in
a. R0
b. Instruction register
c. R6
d. R7
Definition
d
Term
If we execute the following two LC3 instructions in sequence
ADD R1, R1, #-1
BRnzp NEXT
a. The program executes instructions at location NEXT if value in R1 is equal to 1 after executing the ADD instruction.
b. The program executes instructions at location NEXT if value in R1 is not equal to 1 after executing the ADD instruction
c. The program always execute instructions at location NEXT regardless of value stored in R1
Definition
c
Term
If R3 contains x4000 and the JSRR R3 instruction is stored at address x3000, the value of the PC (program counter) immediately after execution of the instruction JSRR R3 is:
a. x3000
b. the contents of memory location x4000
c. x4000
d. the contents of memory location x3000
e. none of the above
Definition
c
Term
If R3 contains x4000 and the JSRR R3 instruction is stored at address x3000, the value in R7 after execution of the instruction JSRR R3 is:
a. x3000
b. x3001
c. x4001
d. x4000
Definition
b
Term
What is printed out by the following code segment in C:
{int x = 5; /*_____*/
{int x = 1;
int y;
int z;
y = ++x; /*_____*/
printf("y= %d\n", y); /*_____*/
z = x++; /*_____*/
printf("z= %d\n", z); /*_____*/
}
printf("x= %d\n", x); /*_____*/
}
Definition
this x is different from x inside the scope of the next block; pre-increment- increment x and assign to y, so y=2; prints y=2; post increment- assign to z and increment x, so z=2; prints z=2; prints x=5
Term
When a program calls a TRAP (or a subroutine) service routine, the TRAP instruction stores the current value of the program counter (i.e., the instruction to return to from the TRAP) in
a. R7
b. Instruction register
c. R6
d. R0
Definition
a
Term
If we execute the following two LC3 instructions in sequence
ADD R1, R1, #-1
BRz NEXT
a. The program executes instructions at location NEXT if value in R1 is equal to 1 before executing the ADD instruction
b. The program executes instructions at location NEXT if value in R1 is not equal to 1 after executing the ADD instruction
c. The program always execute instructions at location NEXT regardless of value stored in R1
Definition
a
Term
If R3 contains x3000 and the JSRR R3 instruction is stored at address x4000, the value of the PC (program counter) immediately after execution of the instruction JSRR R3 is:
a. x3000
b. the contents of memory location x4000
c. x4000
d. the contents of memory location x3000
e. none of the above
Definition
a
Term
If R3 contains x3000 and the JSRR R3 instruction is stored at address x4000, the value of R7 after execution of the instruction JSRR R3 is:
a. x3000
b. x3001
c. x4001
d. x4000
Definition
c
Term
Consider the following LC3 code which is the code generated to implement some of the statements in a C program.
LDR R0, R4, #1
AND R0, R0, #0
STR R0, R4, #1
The C code in the program is most likely:
a. Setting/initializing the value of a local variable
b. Operating on two different variables
c. Setting the value of a global variable-R4 is global data pointer
d. Calling a function
Definition
c
Term
The items that are pushed on and popped off the run-time stack are:
a. Function definitions
b. Activation records
c. Symbol tables
d. Function declarations
Definition
b
Term
Show the contents of memory (run-time stack in particular) when function square is executing.
int square(int);
main()
{
int a;
a = square(4);
}
int square(int a)
{
int s;
s = a * a;
return s;
}
Definition
s
Frame ptr for main
Ret addr to main
Ret val
4
a
Term
Consider the following LC3 code which is the code generated to implement some of the statements in a C program.
LDR R0, R5, #-1
AND R0, R0, #0
STR R0, R5, #-1
The C code in the program is most likely:
a. Setting/initializing the value of a local variable
b. Operating on two different variables
c. Setting the value of a global variable
d. Calling a function
Definition
a
Term
In the LC3 processor, where are the frame pointer and top of stack pointer stored?
Definition
Frame pointer is stored in R5 and the stack pointer is stored in R6
Term
Show the contents of memory (run-time stack in particular) when function square is executing.
int square(int);
main()
{
int a, b;
b = 10;
a = square(b);
}
int square(int a)
{
int x, y
x = a * a;
y = x * a;
return y;
}
Definition
y
x
Frame ptr for main
Ret adddr to main
Ret value
10
b=10
a
Term
What is printed out by the program below. (Ignore any syntax errors) #include #include void foo1(void) { int x=10; static int y=50; printf("x= %d y=%d \n", x, y); y = y+50; } int main() { int x=10; /*_____*/ int D[10]; int I; int *ptr; int **ptr2; ptr = &x; /*_____*/ ptr2 = &ptr; /*_____*/ foo1(); /*_____*/ foo1(); /*_____*/ { int x=20; int y=30; printf(“Value of *ptr= %d \n”, *ptr); /*_____*/ *ptr = *ptr+10;/*_____*/ **ptr2 = **ptr2 +10; /*_____*/ printf(“Value of x is %d \n”, x); /*_____*/ printf(“Value at ptr2 is %d \n”, **ptr2); /*_____*/ } Printf(“Value of x is %d \n”, x); /*_____*/ for (i=0; i<10; i++){ D[i] = i+1;} ptr=D; /*_____*/ printf(“value of *ptr+2 is %d\n”, *(ptr+2)); /*_____*/ printf(“value of *ptr+11 is %d\n”, *(ptr+11)); /*_____*/ }
Definition
x refers to this x below; ptr points to x; ptr2 points to ptr-so *ptr and **ptr deference the same variable x; this prints x=10 y=50 first time fool is called; this prints x=10 y=100 2nd time fool called here; prints 10 (=x); increments contents of x, so x=20; increment again by 10, so x=30; x=20; 40; prints 40; ptr now points to D[0]; prints D[2]=3; prints D[11] which is some junk on stack
Term
What is printed out by the program below. #include #include void foo1(void) { int x=10; static int y=20; printf("x= %d y=%d \n", x, y); y = y+20; } int main() { int x=200; /*_____*/ int i; int D[10]; int *ptr; int **ptr2; ptr = &x; ptr2 = &ptr; foo1(); _____ foo1(); _____ { int x=50; int y=30; printf(“Value of *ptr = %d \n”, *ptr); _____ *ptr = *ptr+10; **ptr2 = **ptr2 +10; printf(“Value of x is %d \n”, x); _____ printf(“Value of **ptr2 is %d \n”, **ptr2); _____ } Printf(“Value of x is %d \n”, x); for (i=0; i<10; i++){ D[i] = i+2;} ptr=D; printf(“value of *ptr+2 is %d\n”, *(ptr+2)); _____ printf(“value of *ptr+11 is %d\n”, *(ptr+11)); _____ }
Definition
x refers to this x below, x=10 y=20, x=10 y=40, 200, 50, 220, 4, some junk D[11]
Supporting users have an ad free experience!