1/101
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Which method of encoding signed integers is used in systems being built today?
B2T
Approximately how much did we say pipeline hazards reduce performance in real pipelines below the theoretical maximum performance?
about 10%
What is an important practical significance of laws or identities for Boolean functions?
all of the above
- they can be used to reduce the cost of a circuit which implements for a Boolean function
- they can be used to reduce the amount of heat produced by a circuit which implements a Boolean function
- they can be used to reduce the amount of power consumed by a circuit which implements a Boolean function
which of the following gates is universal?
NAND
what is a "full adder"
a circuit which can take two operand bits and carry-in as inputs and can output a sum, and a carry out
which choice precisely describes how the subtraction a - b can be done by a CPU using 2's complement representation of signed numbers?
add a to the inverted bit string for b, using a carry bit of 1 for the addition of the least significant bits
if a parity bit is used in the transmission of ASCII character data (for example, when data is transmitted over a network,) in which of the following cases will a receiver of the data determine that an error has occured?
if the number of 1's received for a one-byte character encoding is odd
which of the following gates (by itself, not in combination with any other gate(s) did we say can be used to compare the last two carry bits when doing arithmetic operations on signed integers, in order to set the overflow (O flag) in the CPU?
XOR
in systems currently being used today, how many bits are contained in a word of data?
usually 64, but the word size can vary from system to system
what is true of big-endian and little-endian encoded data?
little-endian storage of data in memory has the least significant byte in a piece of numerical data stored a the lowest numbered address, or first, in memory
what is address alignment?
It refers to the fact that, in some systems, memory addresses where valid words can be stored must be divisible by a certain whole number, such as 4 or 8.
which of the following is a type of operation that a CPU can do?
all of the above
- arithmetic and logical operations
- move, or transfer data, from the CPU to memory, or memory to the CPU
- program sequencing and control operations
which of the following is true of RISC and CISC?
in RISC instruction sets, all instructions always have the same length
what is the PC in the CPU?
A register used to store the address of the instruction which is to be read (or fetched) from memory and executed, until the address is sent to memory.
what is the IR in a CPU?
A register used to store the bit string for the instruction being executed.
if a multiplexor is used to select one of 4 input lines to pass to an output line, how many control lines were needed?
2
log base 2(4)
which method is used to encode (represent) unsigned integers in all systems being built today?
B2U
which of the following is not stored as bit strings in computer systems?
none of the above
starting with an integer in 2's complement, to form its negative, what needs to be done?
invert all of the bits (convert 1's to 0's, and 0's to 1's), and then add 1
which is a disadvantage of using a stack to store a return address for a subroutine call?
none of the other answers; we saw no disadvantage of using a stack to store a return address
in Y86-64, when an andq instruction is performed on two reregister operands, which choice is correct about what the instruction always stores in the overflow flag (or overflow condition code)?
the instruction always stores 0 in the overflow flag, because there cannot be overflow for a logical instruction.
if the last carry bit generated for addition of two 2's complement numbers is 1, which of the following is true?
the sum for the addition operation may or may not be correct; correctness in this case cannot be determined based on the last carry bit alone
which is true about the UTF-8 encoding method for character data?
in some cases, it uses encodings of a different number of bytes for example, one character may have a two-byte encoding, and a different character may have a three-byte encoding
which type of processor did we say Mc M1, M2, and M3 processors are?
RISC
when a CPU cache is used, how many words are moved to and from the cache when there is a cache miss?
a whole block of words (block size depends on the cache design, but is always more than 1 word)
for single precision (that is, 32 bit) encoding of IEEE 754 floating point numbers, how is the exponent encoded?
as an 8 bit unsigned value with a bias of 127 (the bias must be subtracted from the encoded exponent to get the true exponent)
for 1's complement addition, which type of gate can be used with an input of the two msbs (left most bits) of the two numbers being added to output the correct bit to use as the first carry?
AND
what is a subroutine?
A sequence of instructions which may need to be executed a number of times, with possibly different sets of data each time.
in Y86-64, how must the flags (condition codes) be set if the jump is taken (this means that the jump instruction will cause the next instruction ot eb one at the address of the label) for a jg label instruction?
the sign flag is 0, and the zero flag is 0
in Y86-64, how must the flags (condition codes) be set if the jump is taken (this means the jump instruction will cause the next instruction to be the one at the address of the label) for a jl label instructions?
the sign flag is 1, and the zero flag is 0
which choice describes the kinds of values which can be encoded precisely (with perfect precision) in IEEE 754 with a finite number of bits?
values which can be written as a quotient of x/y, where y is a number which can be written as a power of 2
what is the most significant bit in any ASCII character code (assume a parity bit is not being used)?
it is always 0
what is the range of values that can be encoded as a B2U number of n bits?
0 to 2^(n) - 1
what is true of a sequential circuit?
all of the above
- it always uses a clock input signal
- it has "memory"; that is, it can store prior state
- its current output may depend on current input as well as prior output
for a D gate/latch/flip-flop, which we said is implemented with a clocked SR gate/latch/flip-flop, how do the D gate inputs correspond to the SR gate?
D is used as the S input, and not-D is used as the R input
In Y86-64, what does a ret instruction do?
it first pops the return address off of the stack, and then writes the address to the PC
which of the following is true of the numbers of registers in Y86-64?
it is different from the number of registers in any real CPU, because it is not equal to a power of 2
what is the key idea of pipelining?
To improve performance by executing multiple instructions at the same time.
if a processor is pipelined, and if the pipeline has 10 stages, what is the theoretical maximum improvement in performance, once the pipeline is fully loaded?
instructions will be executed at a rate which is 10 times faster
When a cache is used, what is the difference between write-through and write-back?
with write-through, changes to data in the cache are written to memory immediately, but with write-back, changes are not written till the cache block is evicted (that is, replaced)
what types of hazards can occur with pipelining?
data hazards and instruction hazards
what is true about the addition of two B2U encoded numbers (that is, unsigned numbers) as we described addition in a CPU?
if the last carry is 1, the result is incorrect
suppose we have a system with a direct-mapped cache identical to the one we described in class and the class slides. The system uses 16 bit address (so 64 KB of memory), and blocks of 16 bytes in memory per memory block (that is, 2^4 bytes per block). If the system has a cache of 128 blocks (that is, 2^7 cache blocks), and the cache is direct-mapped, how many bits will the tag be? [the tag must be stored in the cache with a given block of memory which is stored in the cache]
5 bits
for an IEEE single precision values (that is, 32 bit encoding), how many bits are used to encode the mantissa?
23 bits
when a call function1 instruction is executed in the simulated Y86-64 CPU, which of the following is true?
first, the simulated CPU will push the address in the PC onto the stack, and then the address of the function1 label will be written to the PC register
if the bit string 101 is in B2O encoding of an integer, which integer is it?
-2
010 = 2^1 then add the neg sign
if the bit string 101 is a B2T encoding of an integer which integer is it?
-3
if the bit string 101 is a B2S encoding of an integer, which integer is it?
-1
the left most 1 means negative
2^0 = 1
what is the range of a signed integer values that can be encoded using B2T (2's complement) in 8 bits?
-2^7 to 2^7-1
how to calculate: -2^(n-1) to 2^(n-1)-1
which of the following is or are true about the labels in assembly language program?
all of the above
- when the assembly language program is converted to machine language by the assembler, the label occupies no space in memory
- labels are used to mark addresses in assembly language programs
- labels can be used to mark the address of a particular instruction (such as the first instruction in a loop); they can also be used to mark the address of a piece of data (such as the first element of an array)
in the simple accumulator architecture that we looked at in the last slide set, which is true about the MAR register?
the smaller transfer to memory
in the simple accumulator architecture that we look at in the last slide set, which is true about the MDR register?
it is used both for the CPU to send (write/transfer) data to memory, and also for the memory unit to send (write/transfer) data to the CPU
which of the following reasons for learning the C language was cited in the introduction to C?
all of the other answers
- C is still one of the most commonly used languages in the work world
- C is commonly used for operating systems, device drivers, and embedded systems
- C has very low overhead and is fast
suppose the following statements are the only ones in main in a program
float floatVar;
printf("%.2f", floatVar);
what will be the output when the printf statement is executed
garbage (unknown)
In a C program, which did we say is true about a call to any function?
the function must be declared in the same source file before it is called
suppose we compile a C program in a source file called lab9.c and specify that the executable si to be named lab9, and the program builds (compiles) without errors. We said that the systems programs that run to build the executable run in a certain order. Which choice specifies the order in which these programs are run?
preprocessor, compiler, assembler, linker
a way to remember: PCAL
suppose we declare parameters in main in the conventional way if we want to pass parameters from the command line, and use the command shown below to run the program, called prog8, from the command line in ceolinux (assume $ is the command line prompt): $prog8param1param2
What will be the value of argc be in main?
3
Suppose we declare parameters in main in the conventional way if we want to pass parameters from the command line, and use the command shown below to run the program, called prog8, from the command line in coelinux (assume $ is the command line prompt): what will the value of argv[argc] be in main?
NULL
consider the following in a C program
int sumArray(int *array, int size) {
what is the storage class of the parameter array in this code?
automatic
which choice is true about the use of the register keyword to declare a variable in C?
it can only be used for variables declared with block scope
which is true about the use of the keyword static in C?
it cannot be used in declaration of a parameter in a function definition
Suppose the following statements are all the code in a function:
void function2() {
static int x;
int *ptr = &x
printf("%i", *ptr);
)
What will be printed by the printf statement (Hint: think about the storage class of the variable ptr points to)?
0
Suppose the following declaration in a C program:
struct Node {
int data;
struct Node *next;
} NodeA, NodeB, *NodePtr;
NodePtr = &NodeA;
NodeA.next = &NodeB;
Which choice has an expression equivalent to NodePtr -> next?
(*NodePtr).next
Suppose the following code in a function in a program. What can be placed in the blank to make the code read a float value from the input, and store it in the variable rate?
void function1(/ parameters omitted /) {
float rate;
float *ratePtr = &rate;
scanf("%f", __________);
/ remaining code omitted /
}
ratePtr
Consider the following program statement in a C program:
double*ptr1, ptr2,ptr3;
How many double pointers are declared by this statement?
1
The return type of the C library function calloc() is:
void *
In a C program, consider the following declaration inside a block for a function: int *intP;
Now, if we use the expression intP in another statement later in the same block, what is the type of this expression, intP?
int
what is true about a NULL pointer in C?
it points to 0 or none of the other answers
consider the following C program:
# include
int main() {
char *string1 = "Brutus";
char string2[10] = "Go Ducks!";
if (string2[3] == 'D') string1[0] = 'F';
printf("%s", string1);
return 0;
}
This program compiles without errors. When the program runs, what will appear on the screen if all output of the program is sent to the screen?
segmentation fault
suppose the following declaration and statement are the only ones in main() in a C program:
int data[3] = {5,10};
printf("%i", data[2]);
What output will be printed by the printf statement?
0
consider the following declaration in a function block:
char string2[6] = "Go!";
After this statement, what value is stored at string2[3]?
'\0'
This question is about the following declarations and assignments in main():
struct { int a; } x, *p;
struct {int a; } y, z[3], *q;
Based on the declarations above, which of the following assignments added at the end of this code will compile without errors or warnings?
q = &y;
which of the following names all the aggregate data types in C which we discussed in class and the class slides?
structures and arrays
according to what we said, which type of programming language is C?
procedural
which of the following commands in coelinux (assuming a $ command line prompt) would run an executable called program1 compiled from C source code and would redirect the input to a file called infile1?
$ ./program1 < infile1
which of the choices is the name of a function in the C standard library which makes it unnecessary to keep track of the number of characters in a C string (because the library function can always be called to determine the number of characters in the string)?
strlen
What did we say about the size of a static array (that is, not a dynamic array) in C?
the size must be specified using some constant value in the C source file for the program.
Even though C does not have a Boolean type, what did we say about variables or expressions used as booleans in C?
any expression which evaluated to 0 will be treated as false, and any expression which evaluated to a non-zero value will be treated as true
which did we say is true about the C library function calloc()?
assuming dynamic allocation succeeds, calloc initalizaes all the allocated bytes to 0
where can variables which are declared inside blocks be validly declared in C18?
there are no restrictions on where variables can eb declared inside a block; C11/C18 has just-in-time declaration
consider the following code in main in a C program:
int main() {
float *ptrVar;
function3(&ptrVar);
}
If only one paramter is passed to function10, and we assume the call above is a valid call, and the type of the parameter being passed is correct, and if function10 returns void, which would be a correct declaration of the type of parameter in the definition of the function?
void function3 (float * ptrVar) {.../code omitted/}
suppose the following code in a function in a C program:
void function1 (/parameters omitted/) {
int intVar;
int *intPtr = &intVar;
function2 (___1___);
... (remaining code)
}
to pass intVar by reference to function2 when it is called, what can be placed in the blank numbered 1 in the code?
intPtr
consider the following function definition in a C program:
float arrayAverage (float *floatArray, size) {
.../ code for function omitted /
}
what is the scope of floatArray?
block
consider the following C program:
#include
static int total;
int main() {
int i;
..../remaining code omitted/
}
what does the use of static in the declaration of the variable total do?
it changes linkage to internal
Consider the following from a C program:
int function10(int *array, int size) {
int x = 10;
int *ptr = &x;
}
choose the option which is true about the statement:
int *ptr=&x;
it assigns &x to ptr
consider the following in a C program:
int total1;
int main() {
static int total2;
/ code omitted /
} // all remaining code omitted
What does the use of the static keyword in the declaration of the variable total do?
it changes storage class to static
what is the default linkage for file scope variables in C?
external
consider the following code:
void function1 () {
int intVar1 = 10;
int intVar2 = 5;
int *intPtr = &intVar1;
intVar1 = *intPtr +5;
}
What does the reference to *intPtr on the right side of the assignment operator do in the last statement in the code given above?
it reads the address stored in intPtr, goes to that address, and reads the value stored at that address (that is, 2 memory accesses are made).
which of the following is done by the preprocessor in C?
all of the answers
- removal of comments
- processing of #include directives in the source file
- processing of #define directives in the source file
When the C library function free is called to free dynamically allocated memory, what parameter or parameters must be passed to the function for it to work correctly?
A pointer to, or the address of, the first byte of the dynamically allocated memory
consider the following code
int function (int *array, int size) {
int p = 30;
int q = 10;
... /other code omitted/
}
which of the following is true of the statement int p =30;?
both definition and declaration
consider the following in a C program:
float calculateAverage (int *array, size) {
... /other code omitted/
}
what is the linkage of array?
none
The next 4 questions are about the code below for the insertNode function for the lab 2 linked list:
void insertNode (____1_____ listHeadPtr, Node *newNodePtr) {
Node *traversePtr = ____2____;
if(traversePtr==NULL) {
____3____;
___4____;
}
/ remaining code omitted /
}
what can go in the blank numbered 1 to make the code compile and work correctly to build the list?
node **
(see code in Q-32) what can go in the blank numbered 2 to make the code compile and work correctly to build the list?
*listHeadPrt
(see code in Q-32) what can go in the blank numbered 3 to make the code compile and work correctly to build the list?
*listHeadPtr=newNodePtr
(see code in Q-32) what can go in the blank numbered 4 to make the code compile and work correctly to build the list?
newNodePtr ->next ==NULL
The next 2 questions are about the code below for the insertNode function for the lab 2 linked list:
void insertNode(_____ listHeadPtr, Node *newNodePtr) {
Node *traversePtr = _______;
if (traversePtr == NULL) {/ block code omitted /}
else if(newNodePtr->book.stockNumberbook.stockNumber){
____1__;
____2___;
}
/ block code omitted /
}
what can go in the blank numbered 1 to make the code compile and work correctly to build the list?
*listHeadPtr=newNodePtr
(see code in Q-36) what can go in the blank numbered 2 to make the code compile and work correctly to build the list?
newNodePtr->next=traversePtr
The next 4 questions are about the code below for the insertNode function for the lab 2 linked list:
void insertNode (_____listHeadPtr, Node *newNodePtr) {
Node *traversePtr = _____;
if (traversePtr == NULL) {/block code omitted/
else if(/condition omitted /) {/block code omitted/}
else {
node *priorNodePtr= traversePtr;
traversePtr = traversePtr -> next;
while (____1__&&____2___) {
priorNodePtr = traversePtr;
traversePtr = traversePtr -> next;
}
____3____;
_____4____;
}
}
What can go in blank numbered 1 to make the code compile and work correctly to build the list?
traversePtr !=NULL
(see code in Q-38) what can go in the blank numbered 2 to make the code compile and work correctly to build the list?
traversePtr -> book.stockNumber < newNodePtr->book.stockNumber