.131 10-15 Flashcards

1
Q

Bugs may occur during…

A

compilation time or run time

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

Why may a bug occur during compilation time?

A
  • code has incorrect syntax
  • program violates common programming conventions
  • issues may appear as warnings
  • static analysis of code detects program is invalid
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why may a bug occur during run time?

A

logical error
works but not as expected

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

2 common (but semi-impractical) ways to debug:

A

divide + conquer - remove/add code till you find the bug (comment it out/back in)

printf - outputs to help follow program flow

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

What are the problems with debugging using printf statements?

A
  • statements may change the behaviour of the program
  • takes a lot of printf statements (timely)
  • cannot examine program flow in detail
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does uBit.serial. do?

A

allows you to call printf + scanf functions (uBit.serial.printf/uBit.serial.scanf)

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

What do you need to debug a running microbit?

A

DAPLink
on-chip debugger (OCD) allows remote debugging
integration with VS code = powerful debugging environment

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

Benefits of using a debugger:

A
  • less invasive than printf
    +
    allows you to…
  • step through program 1 instruc. at a time
  • set breakpoints
  • investigate machine state (memory + registers)
  • investigate crashes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Debuggers tend to be…

A

language dependent
(though some can handle multiple)

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

What kind of hardware support may a debugger need?

A

in-system programming of logic devices
hardware support for code/data breakpoints

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

What different interfaces can debuggers provide?

A

GUI or command line

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

What is GDB?

A

GNU DeBugger - open source debugger developed by the GNU project that also created gcc
designed for C
command line interface but can be used w/ IDEs

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

What does (gdb) x/40xb &s do?

A

asks the debugger to display 40 bytes of memory starting from the address s

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

What is a problem when using the (gdb) x/… command?

A

need to consider if the system is using little/big endian when displaying data that takes up >1 byte

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

What does (gdb) run do?

A

runs the debugger

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

What does (gdb) break 4 do?

A

adds a breakpoint at line no. 4

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

What allows for m:b wireless communication?

A

2.4GHz radio module primarily designed to run BLE but also supports standard for wireless personal networks

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

What does simpler proprietary mode mean for m:b radio communication?

A

allows m:b to broadcast general purpose data packets to other m:bs

for privacy all devices appear identical

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

What is the m:b radio mode bandwidth used for?

A

split into 256 frequency channels for users to communicate on

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

Explain what dBm is:

A

used to express transmission range
received signal strength = dB
received power = W
ratio of P/1milliW = how much stronger P is than 1mW

P(dBm) = 10 x log10 (P(W)/1mW)
P(W) = 1mW x 10 x P(dBm)/10

a minus dBm indicates it’s less than 1mW

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

What is a datagram?

A

transmitted by microbits
a packet (sequence of bytes) that can be >= 32 bytes

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

What ways can a datagram be represented?

A
  • an array of bytes (uint8_t array[10])
  • a sequence of chars (ManagedString s(“string))
  • a packet buffer - PacketBuffer b(int)

generally best to use packet buffers in latest CODAL ver

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

What is a managed type?

A

automatically reserves + releases memory as needed
e.g. PacketBuffer + ManagedString

while PacketBuffers can be read/written to anytime
ManagedStrings are immutable (cannot be changed once created unless comparing/joining to other strings)

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

What does packetBufferName.getRSSI() do?

A

retrieves received signal strength indicator measured in dBm of the most recently received datagram

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How do you activate/deactivate the radio module?
uBit.radio.enable() uBit.radio.disable()
26
How do you ensure m:b devices are communicating together?
make sure they're on the same channel uBit.radio.setGroup(int)
27
How do you send a datagram?
uBit.radio.datagram.send(datagramName)
28
How does the MMU manage memory?
uses translation lookaside buffer in microprocessor to translate virtual to physical addresses
29
What uses VM addresses?
read/write operations
30
In principle, how much byte-addressable memory is there for a 64-bit microprocessor?
2^64 bytes
31
What does the OS do in relation to memory management?
dynamically allocates pages of memory (typically 4KB for x86 arch.) to processes + records it in the TLB your code remains agnostic to coordination w/ other processes when accessing memory
32
What is the difference between RAM and direct access memory?
RAM = same access speed regardless of address direct access memory = access speed dependent on address - accesses linearly, e.g. HDD, CD, DVD, vinyl, etc.
33
Describe memory layout:
OS Kernel Stack Heap Blocking Starting Symbol (BSS) Data Text
34
What is the OS Kernel?
memory reserved by OS to monitor + control mapping between physical + virtual addresses
35
What is the stack?
data needed by function calls (inc. arguments + local var) set of values pushed for 1 function call = stack frame
36
What is the heap?
dynamic memory allocation for variables whose size is only known at runtime
37
What does the BSS hold?
global variables that are initialised to 0/do not have explicit initialisation
38
What does data hold?
global variables that have been initialised
39
What does text hold?
binary executable instruc. of a program
40
How do you find out the memory layout of an object file?
size program.o in terminal gives bytes of text,data + bss then overall size in decimal + hex
41
What is the stack layout?
function parameters saved instruction pointer (IP) saved base pointer (BP) locally declared variables also a top of stack pointer (SP)
42
What does the SP do?
points to lowest address of the stack for the current frame (top)
43
What does the BP do?
(also called frame pointer) - points to reference address of the prev. frame
44
What does the IP do?
points to address that function returns to
45
Why is there a fixed offset from the BP regardless of no. of parameters?
parameter values are pushed in reverse order (1st parameter = last pushed)
46
What does lscpu do?
display info about CPU arch. (outputs architecture, CPU op-mode(s), address sizes + byte order) - imagine list CPU
47
What is byte order?
little endian vs big endian
48
Why is there physical and virtual address sizes?
physical = theoretical byte-addressable memory virtual = remaining bytes after extra stuff like prefix to denote number systems (e.g. 0x = hex)
49
What does (gdb) info stack do?
displays the call stack (while running w/ debugger at a breakpoint)
50
What does (gdb) info frame int do?
displays info about the specified frame where: rip = address of next instruc. pointer saved rip = address that frame will return to at end
51
What is the difference between SRAM and DRAM?
SRAM = static - used for CPU cache DRAM = dynamic - used as main memory
52
What allows microcontrollers to interact w/ other GPIOs? (nRF52833 SoC)
memory mapped IO reading/writing to predefined memory addresses
53
What is memory shared between? (nRF52833 SoC)
microcontroller + on-board peripherals or external devices
54
How is the nRF52833 SoC memory used when Bluetooth is disabled?
NOINIT - memory area keeps count of no. of time reset button is pressed to activate Bluetooth pairing mode UICR = user info configuration register storage - holds long term non-volatile data
55
How is the nRF52833 SoC memory used when Bluetooth is enabled?
MBR = master boot record SD = soft device - holds info about BLE protocol bootloader - holds info about over-the-air firmware updates settings - holds similar info to storage as well as Bluetooth pairing keys + states
56
Why do we need build automation?
automating code compilation helps support collaboration + allows faster compilation through large and incremental builds
57
What does a build automation system do?
automates the process of compiling source code (from multiple source files) in binary executable code
58
What do build script generation tools do?
generate files for build automation systems - but do NOT build executable files directly users can set up high-level configuration + generate build scripts for specific OS
59
What is make?
a build automation system that reads a script called makefile is language-independent!!
60
What do makefile scripts contain?
the project structure (files + dependencies) + instructions for binary file creations
61
What is a target? (makefile)
- can be a filename, variable or string - name for the actions that follow (can execute an action by typing make targetname)
62
What happens when there are multiple targets and none are specified in the make?
either runs all or just runs the first
63
What is a dependency? (makefile)
- can be filenames or other targets - list of requirements for a target
64
How does a dependency and target work if concerning a filename? (makefile)
files timestamps compared - the action is only executed if the target does not exist or is older than the dependencies given no need to recompile if compiled recently!!
65
What happens if a dependency is the name of another target? (makefile)
control descends to the actions of the other target
66
What is an action? (makefile)
- shell commands - actions should be indented and only 1 per line
67
What is a rule? (makefile)
- the target, dependencies + actions form a rule - contains the actions to meet a target when the dependencies are fulfilled
68
What signifies a comment in makefile?
begins with a #
69
What signifies a variable in makefile?
begins with a $ and is enclosed within () or {} used within rules NOTE: single char variables are not enclosed
70
What are automatic variables? (makefile)
further shorten the script denoted with the usual $ followed by a symbol
71
What does the char % do? (makefile)
matches a dependency filename w/o the file extension (pattern matching char)
72
What is a "phony" target? (makefile)
always treated as out of date so always executed
73
What were the design goals of the ARM instruction set?
basic but fast instruction set for compiler to translate lowers compiler to hardware level
74
How many bits is ARM architetcure?
32-bit which defines... - range of values in basic arithmetic - no. of addressable bytes (0 to 2^32 -1) - width of a standard register
75
What is a label in assembly code?
pointer inside the program or memory of the program
76
What is a directive in assembly code?
metadata that helps the assembler understand how best to translate instructions begins with a . + treat like a comment so it doesn't appear in machine code
77
What are registers? (ARM arch.)
most fundamental storage on the chip as can carry many types similar to vars for high level as ALU cannot process info from main mem.
78
How do you bypass the small size of registers?
can use pointers to represent larger data types like strings (register is only 32 bits)
79
What are special registers?
reserved for operational CPU state e.g. stack pointer, link register, program counter + current program status register
80
What does the link register and CPSR do?
LR - stores where a function is called from CPSR - stores current program status
81
Which registers are used to store your program data in ARM arch.?
R0-R12
82
How is ARM more space efficient?
can merge destination + source register when the same to help simplify code writing e.g. ADD r0, r0, r1 → ADD r0, r1
83
What does an assembler do?
translates assembly → binary (1 to 1 mapping) platform specific output!!
84
What is a pseudo-instruction?
helps simplify code writing by represent multiple statements as one
85
What does mov do?
mov rd, rs copies contents of the source register into the destination register
86
What does add do?
adds the values in the 2 source registers + stores the value in the destination reigster presumes operands are encoded using 2's
87
Why is there alternate versions of SUB + ADD?
alternates (ADCS/SUBCS + ADDS/SUBS) produce flags to indicate unusual arithmetic results
88
What CPSR flags are there for arithmetic results?
N bit = negative flag Z bit = zero flag C bit = carry flag V bit = overflow flag
89
What are the different right shifts in assembly?
ASR = arithmetic right shift (adds 1s to keep negative numbers negative) LSR = logical shift right (standard) ROR = right rotation (shifted bits wrap from front to end)
90
What are the logical operators in assembly?
AND, EOR (XOR), ORR, MVN
91
What does MOVN do?
like MOV but flips the bit as if a NOT
92
What is an immediate operand?
using # followed by an int to replace a source register with a constant helps save memory
93
What does MOVT do?
copies values like MOV but into the upper 16 bits of a register as MOV usually copies to the lower 16 helps take advantage of all 32 bits
94
What kind of memory addressing does ARM use?
byte-addressable - each byte has a unique address
95
What is two types of directive?
data-type directives - helps assembler allocate appropriate space depending on data type e.g. .word, .byte, .ascii, etc. data directives - tells the compiler where the data should go in memory e.g. .bss, .data, .rodata + .text
96
What are the 3 addressing modes?
reg+ const (ldr r0, [r1, #20]) reg+reg (ldr r0, [r1, r2]) reg+reg<
97
What the different load variations?
LDRB (load byte) LDRSB (load signed byte) LDRH (load halfword) LDRSH (load signed halfword)
98
What are the different variations of store?
STRB (store byte) + STRH (store halfword)
99
What is an offset?
an integer value used to access part of a register (think like an array index) e.g. ldr r0, [r2, #10]
100
What is the difference between sequential execution and branching?
sequential execution = PC increments by 4 each time to go to the next instruction branching = PC offset by a multiple of 4 to skip certain instructions
101
What are the 2 types of branching?
unconditional = branching always executes same target instruction (no condition needs to be met) conditional = branching performs a jump when a condition is met
102
What is a label (branching)?
alphanumeric representation of an address address can point to an instruc. or data
103
What is program-relative addressing?
referencing a label to offset the PC
104
How is the CPSR involved in branching?
when you do a CMP operation, result stored as a flag in CPSR needed for conditional branching
105
What are some conditional branching statements?
BNE, BEQ, BLT, BGE (can also append conditions to instructions, e.g. ADDEQ + ADDNE)