Module 4

The Art of Assembly

From C structures to raw machine code. Mastering directives, control flow, and data arrangement.

.text .data R12-R15 CMP.B

Anatomy of a Line

Hover parts to explore
RESET: mov.w #WDTHOLD, &WDTCTL ; Stop watchdog
Hover over the code above...

Directives: The Organizer

Directives start with a dot (`.`). They don't create machine code; they tell the assembler where to put things.

  • .text Executable Code -> FRAM
  • .data / .bss Variables -> RAM
  • .intvec Interrupt Vectors -> End of FRAM
Memory Map
0xFF80 Vectors (.intvec)
FRAM (.text)
RAM (.data / .bss)

Translation: C to Assembly

Matrices in Linear Memory

Memory is 1D. Matrices are 2D. We flatten them row by row.
Addr = Base + (Row × Width + Col) × Size

Logical View (3x4 Matrix)

int table[3][4]
0
0
Offset Calculation
Row (i) * Width (4) 0 * 4 = 0
+ Col (j) + 0
Index 0
x 2 bytes (int) Offset: 0
Physical Memory

The Stack: LIFO Storage

The Stack is a temporary storage area in RAM. It grows downwards (from high address to low address).

Used for:

  • Saving registers (`PUSH R4`)
  • Local variables
  • Return Addresses during `CALL`
Stack Pointer (R1) 0x2400

PUSH: SP -= 2, then Write.   POP: Read, then SP += 2.
CALL: Pushes return address (PC) then jumps.

RAM Segment
High Addresses (Top) ▲

Calling Convention Cheatsheet

R12 Arg 1
R13 Arg 2
R14 Arg 3
R15 Arg 4
Stack Arg 5+
R12 Return Val