.131 15-20 Flashcards
(80 cards)
How do functions help w/ programming?
simplify programming - abstraction, modularity, reusability, readability, maintainability + testability/validation
What is a function?
stored subroutine that performs a specific task based on the param provided
How is the link register related to ARM functions?
bl = branch + change PC but store current address in link register to be restored later using mov pc, lr / bx lr
What are the register conventions for ARM functions?
r0-r3 = argument registers to pass parameters to
r0 = return value register
link register = return address register
What is stack memory for in ARM functions?
memory region used to store local state of your functions (dynamic, LIFO)
SP starts at 0x20020000 + grows down in memory (decrements by word size w/ each push)
Which registers are preserved/non-preserved in ARM functions?
preserved = r4-r11, SP, LR + stack above SP
non-preserved = r12, r0-r3, CPSR + stack below SP
Why are certain registers not preserved in ARM functions?
helps ensure scope so no unexpected side effects
What is register spilling?
when you need more registers than given, can move contents of registers to main memory
- useful for procedure nesting as LR needs to be saved in stack before calling another procedure
How do defined variables work in ARM?
load via ldr r1, =varname
define via .space
varname: .type value
Why would you want to add assembler into C code?
- can outsmart GCC logic
- enables specific optimisations
- close control of hardware
- can embed existing code fragments
- better performance in SOME cases
What does push/pop {r, r, r) do?
pushes/pops the 1st 2 registers onto/from the stack in the 3rd register
What does the GCC inline assembler do?
compiler that inserts assembler code in code of its caller
removes function call overheads + can add your own assembly using asm(“code”) or __asm__(“code”)
What does the inline assembler compile assembly to?
an object file
What does an extended inline assembler do?
allows embedded assembler code to interact w/ C code
e.g. can assign C variables to registers
What are the input/output operands for extended inline assembly?
char to tell compiler how to treat variables assigned to registers
I = immediate value
J = indexing constraints (offset)
M = constant in the range
m = any valid memory address
r = general registers R0-R15 (simplest to use)
X = any operand
How do we counteract limited CPU register count?
use main mem. to store data → copy data into register for processing
What is register allocation?
compiler assigns variables into processor register
What are the rules of register allocation?
- any 2 vars must not be assigned to the same register at any point
- can use spilling to store var values
- coalescing aims to optimise register allocation to reduce value copying
What does the volatile qualifier do to inline assembler?
stops GCC moving code for optimisation so that code executes sequentially to avoid processor side effects
written as volatile asm (“code”)
What is a clobbered register?
value of register only to be modified inside “asm” so compiler doesn’t use it to store any other value
denoted as :”r0”
What are the inline assembler special arguments?
“cc” = instruc. modifies condition code flag (saves to PSR) - used for macros + interrupts
“memory” = instruc. accesses unknown memory addresses
What does each assembly instruc. convert to?
16/32 bit representation that contains instruction, registers + immediate values
What do high-performance CPUs (x86) do to appear faster?
use caches (small fast RAM) to make main memory (large slow RAM) look faster at low cost
What do low-performance CPUs (ARM-Cortex) do for memory?
put memory-on-chip w/ CPU, RAM + flash ROM