“maybe next week I'll say we may as well all quit and go back to the farm- assuming they haven't taken over the farm as well.”
- What is the function of the ALU?
→ What is an ALU? ⇒ Arithmetic Logic Unit → It performs arithmetic & logical functions
- In signed arithmetic, is 0x7CA3 negative?
→ No. Why? ⇒ look at the first byte. 7 in binary is 0111 ⇒ the MSB is not 1, therfore the number is not negative ⇒ the LSB tells us whether the number is even or odd. in this case, the last byte is 3 (0011) therefore the number is odd. → The number expanded in binary is: ⇒ 0111 1100 1010 0011 → In signed arithmetic, the MSB is the sign bit. → In this case, the MSB is bit 15.
- How are characters, such as ‘A’ stored in memory?
→ As a binary number. → Stored iwht 8 bits. ⇒ this gives us 256 possible characters (2^8 is 256) ⇒ ASCII uses the Least Significant 7 bits, the MSB is assumed 0 ⇒ MSB is the parity bit. ⇒ So we actually have 128 possible characters (2^7) → ASCII table maps the numerical values to the characters.
- Where is a return address stored?
→ What is a return address? ⇒ The address of the function's caller that will be returned to after the function's execution. ⇒ Program counter tells us which instruction will be executed next. ⇒ When the call takes place, the program counter gets the address of the function. By doing that, the old value of the program counter gets overwritten. We need to remember the original value of the PC, the return address. Return to one instruction AFTER the function call. ⇒ During the function call, the computer remembers the current PC value. Then it restores the value when the function returns. → How can we remember the return address? ⇒ A specialized register aka Link Register. ⇒ When the call takes places, the Link Register gets the current PC value. ⇒ The PC gets the address of the subroutine. ⇒ PC starts executing the subroutine. ⇒ How do we return using the link register? • PC gets the value of the Link Register. ⇒ Another way: The call uses the stack. • What is a stack? Area of memory that starts at the higher addresses. ◇ PC starts from lower memory and moves higher. ◇ A stack supports push and pull/pop operations. ◇ Each time we push, we fill up a part of the stack, The stack pointer moves further down (in addresses) as more things are pushed. The stack pointer always points to the top of the stack. (first location in use, but I guess he's saying it can also point to the first free location) ◇ Popping (pulling) from the stack frees the data at the top of the stack, and the SP is incremented. • In a subroutine call: ◇ Push PC to stack ◇ PC gets the address of the subroutine ◇ to return, POP the previous PC from the stack ◇ what if we have a recursive subroutine? ▪ If we use the link register, calling multiple subroutines overrwrites the return addr for the previous subroutine call ▪ Using a stack prevents this issue. ▪ Push the value in the Link Register (LR) to the stack at each function call. ▪ There's a great advantage to using the LR, as long as you can guarantee there won't be any more subroutine calls. • PC starts from lower memory and moves higher.
- What is the purpose of the NUL character in a C/C++ string?
→ Indicates the end of the string in memory. → What is a string (in C)? ⇒ An array of characters. ⇒ we have a block of contiguous memory locations. ⇒ each block is 8 bits, probably an ascii character. ⇒ C does not maintain count of how many characters are in a string. So how do we know where the end is? • The null character ⇒ 0000 0000
- At minimum, what should be stored when an interrupt occurs?
→ A computer has a CPU, a Bus, Memory, and devices connected to it. → A device can undergo a state/status change. ⇒ Ex, “I've got a character” ⇒ In the case of UART, it can send data, receive data, and tell us its status. It can also receive control information. ⇒ We have the application (running, executing istructions) and it will have a status. This can store the result of the latest operation. It also has its PC storing the next instruction. The device can cause an interrupt, and cause the computer to move elsewhere. ⇒ At a minimum, the PC and and status must be preserved. PC and Status register can be pushed onto the stack. ⇒ Hardware pushes them on, but software can find a way to get them off.
- How can a number be multiplied by 16 on a machine without a multiplication instruction and without using addition?
→ Assume we have the number 00000001 → This is essential 1 * 2^0 → 00000010 = 1 * 2^1 + 0*2^0 → bitshifting left can multiply the number by 2 → to multiply by 16, bitshift left 4 times.
- Answer the question (in bold) in main()
→
int x1; void func1(int data){ int x1; x1 = data; } void func2(int data){ x1 = data; } main(){ func2(5); func1(3); // what is the value of x1? }
→ We have two x1's. One in the global scope and one is a local variable of a function. → The x1 in func2 refers to the x1 in the global scope. Changes to ‘x1’ in that function will apply to the one declared in the global scope. → Stack frame: ⇒ lo memory • automatics • new BP • base ptr (stack frame BP of the caller) • rtn addr • parameters ⇒ hi memory • caller's stack frame → In the case of func1, it gets its value of x1 from its stack frame → func2 has no x1 in its stack frame, so it uses the global x1 → in main, the value of x1 becomes 5. → the local variable of func1 gets changed to 3, but it is gone when the function returns.
- What is a memory mapped device?
→ Recall: computer has CPU, bus, meomry, and devices. → A device has registers. They are not the same as CPU registers. They're specific to the device. → If we have a memory mapped register, the device's registers are mapped directly to memory locations. This allows us to access them as if they were memory. The device also has its own external memory. → The device registers are associated with memory locations
- Under what conditions is the carry bit set?
→ Don't use the term overflow. → Carry is for unsigned arithmetic → Overflow is for signed arithmetic → They both refer to something that happens in the same bit → If we are adding two binary numbers, and the result of the operation produces a carry, the carry bit is set. → E.g FFFF + 1 = 0000 (and carry bit is set) → Overflow occurs when you have two numbers with the same sign and they overflow the sign bit.
- What is stored in an interrupt vector?
→ If a device has a status change, it doesn't necessarily cause an interrupt. → Keep polling the status register until the SR indicates there is DATA. → Read the data → In that case, the CPU when polling is just wasting cycles. → It makes more sense to continute running the application until there is a status change, If there's a READ, the PC has to go to the location of the device and perform the read. → ISR - Interrupt Service Routine ⇒ Checks the status, depending on the status it will read the data. CPU only changes location when an interrupt occurs. This is much faster than polling → Where is the ISR sitting? ⇒ When we call, we need the address of the subroutine. ⇒ When the interrupt occurs, we could be anywhere. the ISR is esserntially a subroutine. But the machine calls it. CPU needs the address of the ISR. Usually in HI memory. Interrupt vectors are stored there. Each device has its own interrupt vector
- What is a heap?
- What is a symbol table?
- What does a dataflow diagram represent?
- When funcX() is called, a segmentation fault occurs. What caused it?
→
int *funcX(int value){ int *ptr; *ptr = value; return ptr; }
- What does the value in the program counter indicate?
- How many bytes of storage would the following structure occupy?
- In a machine that only supports addition, how is subtraction performed?
- What is a Harvard architecture?
→ There's two ways of storing instructions and data ⇒ Von neumann princeton architecture • cpu accesses I&D from memory through the bus • instructions and data are in the same memory • this takes time because theres only one bus ⇒ Harvard architecture • has two memory banks, one for instructions and one for data • program memory and data memory
- In a function call, where are the parameters stored?
- Rewrite the following code fragment using a single if-else
- Name the three loop structures
- What are the values of a and b when this loop terminates?
- What does a state diagram (or state machine) represent?