CS261 - Midterm 2 Flashcards
Elements of an array are next to each other in memory
True
Does A[i] = *(A+i)?
True
C has always supported variable sized multidimensional arrays?
False
How big will int C[5] be if ints are 32 bits?
It will be 20 bytes long.
Assume array long B[10] starts at address x. What address will be B[5] be?
x + 40
Assume the address of int C[5] is in %rdx, and i is in %rcx. What is the address for C[i]?
(%rdx, %rcx, 4)
%rdx = base register of C[5] %rcx = index register i 4 = an integer is 4 bytes, so the scale is going to be 4
Memory Addressing Mode
D(Rb, Ri, S) D = Constant "displacment" of Rb = Base register Ri = Index Register: Any, except for %rsp S = Scale: 1,2,4,8
Assume long A[4][6]. What will the size of A be?
8 * 4 * 6
long = 8 bytes
4 * 6 = 24 cells
Assuming long A[4][6] has base address x. What will the address of A[1][0] be?
x + 6*8
All pointers in C are the same type?
False, like in *p; char *c;
Adding 1 to a pointer will always add 1 byte
False
Pointers can point to functions
True
All pointers are how many bytes?
8
To add 2 operands in y86, the must both be
registers
y86 instructions are all the same size
False, 1-10 bytes
A multiplexor
selects a value from a set of different data values
Registers change value
When the clock signal rises
A single logic gate implements a boolean function in hardware
boolean function
We compute for the value for the next PC in
Fetch
The inputs to the ALU are
Register A and B, or register B and a constant
Whether we read or write during the memory stage, depends on the value of
the code
CPU
• We have the basic components we need to
create a CPU that runs y86 programs
– ALU: Does math/logic
– Registers: Hold values for ALU
– Memory: Holds values over time
– Instruction Memory: Holds instructions
– PC register: Holds pointer to current instruction
Instructions in Stages
Fetch: Read instruction from memory
• Decode: Read operands from the register file
• Execute: ALU performs operations
• Memory: Moves to or from memory are
performed if necessary
• Write Back: Results are saved to register
• PC Update: PC is set to address of next
instruction
FDEMW
What hardware do we need for
decode?
Register file