Lecture 2 - ARM Assembly and Input/Output Flashcards
What is an immediate value?
A value that is not stored anywhere, but rather a part of the instruction itself
Why can immediate values only be 8 bits?
When looking at the instruction format, the operand 2 field contains bits for immediate value. However, these are only 8 bits and therefor sets the constraint
What does the ARM Assembly function bl do?
First sets Link Register (r14) to PC + 4.
PC is the address of the current instruction, in this case the bl instruction itself.
PC+ 4 corresponds to the sequentially next instructions, as each instructions are 32 bits.
Then the bl instruction sets the PC to the label provided with the bl instruction.
In ARM Assembly, what happens when you need to return from a function
Need to move LR to PC,LR remembers where the function was called from.
In ARM Assembly, what are callee registers?
r4 - r12 are defined as callee saved registers.
If a called function needs to write to any of these registers, it first needs to save these values. And before it returns to the callee function, it needs to restore the values to these registers.
In ARM Assembly language, what are caller saved registers?
r0-r3 are defined as caller registers.
parameters are passed in r0-r3.
return values are stored in r0 and r1.
If the caller wants to preserve the values of these registers after a function call, it needs to save these values before the fundtion call, and restore them afterwards.
How does the stack operate?
Last-in-First-out
Stack pointer (r13, SP) always points to the last occupied position in the stack
Stack grows downwards.
Push and pop are special instructions to operate on the stack. SP moves automatically with these
pop from stack does not remove values, just moves the stack pointer upwards
Content of stack, growing downwards:
- parameters
- caller context
- return address
- local vars
What is CISC?
Complex Instruction Set Computer.
Also known as register-memory architectures
appeared in early computers (i.e. x86)
Computers mostly programmed in assembly - assembly instructions close to what HLL now provide
Few registers - operands in memory, instructions were allowed to operate directly in memory
memory was limited, instructions were of variable length because of this
What are the two categories of ISAs?
CISC and RISC
What is RISC
Reduced Instruction Set Architecture.
load-store architectures
Appeared in the 80’s
HLL and compilers were already well developed. Because of this the instructions could remain simple
More registers and memory, faster clock.
Because of this fixed length/format instructions were implemented for easy and fast decoding
Name four properties of I/O devices?
Device (Mouse, keyboard, network)
Behaviour (Input, output, both, storage)
Partner (human, machine)
Data rate (Mbit / sec)
What is an IO controller?
Connects the I/Odevice and the CPU
contains a data- and a status registers.
Different IO devices connects to different IO controllers through different interfaces (video, USB, PCIe)
What does the data register in the IO controller contain
For input devices: Holds data read from device
For output devices: Holds data that needs to be written to the device
What does the status register in the IO controller contain
status of read/write operation
How is IO devices addressed?
Memory mapped I/O
Isolated I/O space
What is memory mapped I/O?
I/O controller registers are mapped to dedicated portion of memory
Upside: can use regular load/store ops for this
Downside: eats up memory space
What is isolated I/O space?
I/O devices are in a completely seperate memory space.
One memory address can both belong to a space in memory and an I/O device
Because of this, seperate instructions are used to communicate with these addresses to differentiate when you are communicating with memory or when you are communicating with I/O
What are the methods the CPU uses to determine if an I/O device is ready for data transfer?
Polling (busy-wait I/O)
Interrupt
What is polling (busy-wait I/O)?
CPU monitors I/O continuously to see if it’s ready.
This wastes CPU time, but makes CPU react fast when ready
What are interrupts?
The I/O controller sends an interrupt signal to the CPU when the device is ready
Slow response from CPU as CPU must finish what it was doing before it can handle the interrupt
Better CPU utilization as CPU resources are not wasted
What happens on an interrupt?
I/O controller sends an interrupt signal to the CPU
The CPU saves the address of the current instruction (saves state to be able to continue later on)
Jump to interrupt handler
Handle interrupt (service the I/O device, preserve registers)
Return to foregroung program. There is a special instruction to return from interrupt handler.
How do you connect more I/O devices to an CPU than there are ports on the CPU?
Connect I/O devices together through OR-gates.
When doing this, the CPU must poll each device to see where an interrupt signal came from.
Can use an interrupt controller that arbitrates CPU access amoung devices
What are the 2 methods of finding the correct interrupt handler?
1: Jump to predefined address. Use cause of interrupt (device id) to specify the right handler
2: Vector interrupts: Directly branch to a specific handler based on device.
What is an vector interrupt table
A table that contains information of where the interrupt handler is for each possible interrupt