.131 15-20 Flashcards

(80 cards)

1
Q

How do functions help w/ programming?

A

simplify programming - abstraction, modularity, reusability, readability, maintainability + testability/validation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a function?

A

stored subroutine that performs a specific task based on the param provided

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How is the link register related to ARM functions?

A

bl = branch + change PC but store current address in link register to be restored later using mov pc, lr / bx lr

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the register conventions for ARM functions?

A

r0-r3 = argument registers to pass parameters to
r0 = return value register
link register = return address register

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is stack memory for in ARM functions?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which registers are preserved/non-preserved in ARM functions?

A

preserved = r4-r11, SP, LR + stack above SP
non-preserved = r12, r0-r3, CPSR + stack below SP

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why are certain registers not preserved in ARM functions?

A

helps ensure scope so no unexpected side effects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is register spilling?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do defined variables work in ARM?

A

load via ldr r1, =varname
define via .space
varname: .type value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why would you want to add assembler into C code?

A
  • can outsmart GCC logic
  • enables specific optimisations
  • close control of hardware
  • can embed existing code fragments
  • better performance in SOME cases
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does push/pop {r, r, r) do?

A

pushes/pops the 1st 2 registers onto/from the stack in the 3rd register

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the GCC inline assembler do?

A

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”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the inline assembler compile assembly to?

A

an object file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does an extended inline assembler do?

A

allows embedded assembler code to interact w/ C code
e.g. can assign C variables to registers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the input/output operands for extended inline assembly?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do we counteract limited CPU register count?

A

use main mem. to store data → copy data into register for processing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is register allocation?

A

compiler assigns variables into processor register

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the rules of register allocation?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does the volatile qualifier do to inline assembler?

A

stops GCC moving code for optimisation so that code executes sequentially to avoid processor side effects

written as volatile asm (“code”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is a clobbered register?

A

value of register only to be modified inside “asm” so compiler doesn’t use it to store any other value
denoted as :”r0”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are the inline assembler special arguments?

A

“cc” = instruc. modifies condition code flag (saves to PSR) - used for macros + interrupts
“memory” = instruc. accesses unknown memory addresses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What does each assembly instruc. convert to?

A

16/32 bit representation that contains instruction, registers + immediate values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What do high-performance CPUs (x86) do to appear faster?

A

use caches (small fast RAM) to make main memory (large slow RAM) look faster at low cost

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What do low-performance CPUs (ARM-Cortex) do for memory?

A

put memory-on-chip w/ CPU, RAM + flash ROM

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is Thumb + its benefits?
subset of instruc. re-encoded in fewer bits (mainly 16, but some 32) reduces program memory size + bandwidth requirements
26
What is Thumb state?
indicated by PC being odd, means can compile code in ARM Thumb only available where ARM CPU allows operating state control (M3 doesn't)
27
How do you know if a Thumb instruc. is 16 or 32 bits?
if 1st 5 bits = 11101, 11110 or 11111 then 32 bits else then 16 bits
28
What does "=r" and "r" signify in inline asm?
=r assigns a var as the return value r assigns a var as the input value
29
Define an exception:
unexpected change in flow control that allows a CPU to notify your program to implement code that manages external events
30
What is an exception caused by?
software or hardware synchronous exception = caused by instruc. in running program asynchronous exception = caused by I/O device requesting the processor - aka hardware interrupt
31
Explain privilege levels:
due to security issues, computers do not allow full access to resources to any code CPU limits resources access offered to diff. processes
32
How can a user get protected resources given privilege levels?
can request services from OS by invoking OS functions (system calls) e.g. SVC in ARM + syscall in x86, however no OS for microbit
33
What privilege level does user code operate at?
low privilege level
34
How can you transition between privilege levels?
supervisor instruc. - CPU reads arguments from registers + executes the specific flavour of the SVC instruc. table specifies what actions to take next based on what the service user code wants from the OS
35
What does an exception create?
exception interrupt - looks like a special function that is called by the CPU
36
What does interrupt handling do?
- stops normal fetch-ex cycle - saves current CPU state - runs user code to manage interrupt - changes code execution to interrupt handling code
37
What is an exception handler?
handles exception then returns to user code - found in a branch instruc. in an exception vector
38
What is the vector table for?
stores an address to execute when exception/interrupt raised used to determine where to jump to the exception handler placed in low memory (close to where CPU goes to on power up)
39
What is a banked register?
like an extra (shadow) register used to preserve registers for exception handlers
40
Why are banked registers used over the stack during interrupts?
stack is in memory, memory is slow banked registers use FIQ which is a fast, low-latency interrupt handling mechanism in ARM
41
Explain the steps involved in exception handling:
CPSR → SPSR execution mode + privilege lvl set disable interrupts (using interrupt mask bits in CPSR) return address → banked LR push other registers → stack branch to exception function (vector table) execute exception handler LR → PC, SPSR → CPSR + pop registers off stack
42
What are execution modes?
diff. modes have diff. privilege lvls + helps CPU know which registers to save to and where to return to after interrupts e.g. user mode = PLO, other modes = PL1 specified in bottom bits of CPSR
43
How do CPSR flags affect execution modes?
I bit - “IRQ flag” - disables IRQ interrupts F bit - “FIQ flag” - disable fast IRQ (FIQ) interrupts T bit - “Thumb flag” - disable Thumb mode
44
What is a BusFault?
occurs during a memory access error in the bus interface escalates to a HardFault on Cortex-M0
45
What is memory mapped IO?
a mechanism for the CPU to interact w/ IO devices
46
How does the CPU interact w/ hardware devices?
devices are mapped to specific memory addresses (IO registers) so CPU reads (LDR) / writes (STR) to these locations
47
What is an interface?
define how diff. hardware components communicate at the electrical or signal level
48
What is a protocol
exact form + meaning of the signals exchanged between the sender + the receiver
49
Why do we need interfaces?
ensures that device is ready for next batch of data + host is ready to receive next batch of data from peripheral device
50
What are the 2 types of signals in protocols?
command + data signals
51
What is a handshake?
a protocol where the receiver sends an acknowledgement for the commands + data or indicates it's ready to receive
52
What does the temperature sensor (IO) do?
measures die temperature over the temp. range of the device
53
What MMIO registers are involved w/ the temperature sensor?
TEMP is started by triggering the START register + stopped by triggering the STOP register DATARDY event is generated when temp reading is reading + is available via the TEMP register INTENSET = enable interrupt INTENCLR = disable interrupt
54
How do the Micro:bit LEDs work?
uses 2 GPIO ports each w/ 32 I/O pins where the registers... OUT - writes GPIO port IN - reads GPIO port DIRSET - direction of GPIO pins
55
What is polled I/O?
CPU monitors a control/status register associated w/ a port when byte arrives in a port, sets bit in control register for CPU to poll + notice "data ready" to retrieve + process bytes
56
What is interrupt-driven I/O?
devices tell the CPU when they have data to send using interrupts where CPU can proceed w/ other tasks until a device requesting service sends it an interrupt
57
How does a button A (m:b) click interrupt work?
button connected to GPIO pins of ARM CPU GPIOTE module offers GPIO pin access using tasks + events where each GPIOTE channel can be assigned 1 pin
58
What can complicate system design?
cost, hardware limitation, energy + scalability can simplify coding via abstraction by trading CPU cycles
59
How do rows + columns work in m:b LEDs?
x + y controlled separately so to light up 1 LED must set row HIGH/enabled + column LOW to complete circuit + turn on LED
60
What are some LED m:b commands?
display.image.setPixelValue(x, y, value) - can also add a brightness level in value depending on mode display.print() display.scroll()
61
What are the ARM assembly directives for defining constant values?
.equ = assign name to constant value (immutable) .set = assign name to constant value (mutable)
62
What is LED multiplexing?
cannot light up multiple rows at same time so turn on LEDs line by line (human eye cannot perceive diff.)
63
How do you alter m:b LED brightness?
pulse width modulation - switching voltage on + off very fast (pins on board cannot output analogue signal - pins only full 3.3V output or 0V)
64
How do you access an array in assembly?
ldr r3, [r0, r1, lsl 2] where r1 is the index (shifted by 2 for each byte) and r0 holds the address of an array
65
Describe a pure tone:
sine waves w/ frequencies related to their perceived pitch have single freq. (f = 1/T where T = duration), sinusodial shape + no harmonics (so pure sine wave) used in testing + research
66
What is frequency?
waves produced per second
67
What do we use to visualise sound waves?
GNUplot - command line UNIX plotting tool
68
How do we represent sound digitally (ADC)?
as a set of discrete values obtained via sampling amplitude at regular intervals + representing w/ a binary value
69
What are the key features in sound sampling?
sampling rate (no. of samples per second) bit depth (no. of bits per sample)
70
What happens when you inc. sampling rate/bit depth?
file size inc. but so does accuracy as storing more data/greater range of possible values
71
What are the standards for sampling rate + bit depth?
sampling rate = 44.1/48kHz bit depth = 8/16/24 bits
72
How do calculate the file size of a sound file?
file size (bits) = sample rate (Hz) * bit depth * no. of channels * duration (secs)
73
What are examples of sound hardware?
PC speaker + sound card
74
What is a PC speaker?
hardware device that often can only beep at diff. frequencies (e.g. for errors) as not meant to reproduce complex sound
75
What is a sound card?
computer component to perform ADC + DAC developed due to demand for more complex audio died off in 2000s as Windows killed sound cards ability to accelerate sound + be interfaced by games in an easy way
76
What is sound software concerned w/?
generating sample + keeping audio subsystem of the OS/hardware fed w/ sound data
77
How does software generate a sound sample?
- using loops to iterate through values in a sample - store values in an array/list (depending on if you know size)
78
How can you examine a sound sample to check it's good?
by playing same data or by saving sample values to file + using GNUplot to check waveform
79
How do you feed audio subsystem w/ data?
short audio - generate entire sample + send it to the sound system in 1 go + let play longer audio (like music) - streaming audio data into sound system + fill a buffer to let audio subsystem “drain” it to refill before its empty
80
What data structure is useful for generating data for longer audios?
ring buffer (circular queue)