Module 2Módulo 2

The MSP430 CPULa CPU MSP430

Registers, addressing modes, timing, encoding. Registros, modos de direccionamiento, temporización, codificación.

Santi Scagliusi, PhD

The CPU in four blocks.La CPU en cuatro bloques.

What the next three modules cover.Lo que cubren los próximos tres módulos.

1
REGISTERSREGISTROS
where data livesdónde vive el dato
2
ADDRESSINGDIRECCIONAMIENTO
how to reach itcómo llegar a él
3
TIMINGTEMPORIZACIÓN
how long it takescuánto tarda
4
ENCODINGCODIFICACIÓN
how it looks in binarycómo se ve en binario

What you'll be able to read.Lo que podrás leer.

MOV.W R4, R6
opcodeopcode
src
Ad
B/W
As
dst
0100
0100
0
0
00
0110
= 0x4406
Every bit means something.Cada bit significa algo.
The chip we'll useEl chip que usaremos

MSP430FR6989

Sixteen registers. Four are special.Dieciséis registros. Cuatro son especiales.

R4–R15 are general purpose. R0–R3 each have a dedicated function.R4–R15 son de propósito general. R0–R3 tienen cada uno una función dedicada.

R0
PC
Program CounterContador de Programa
R1
SP
Stack PointerPuntero de Pila
R2
SR · CG1
Status / ConstantsEstado / Constantes
R3
CG2
Constant GeneratorGenerador de Constantes
R4 – R15 · general purposeR4 – R15 · propósito general
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13
R14
R15
R0

PC: the moving fetch pointer.PC: el puntero de fetch en movimiento.

By the time the CPU decodes an opcode, PC already points to the next word.Cuando la CPU decodifica un opcode, PC ya apunta a la siguiente palabra.

15
0
R0 (PC)
0

LSB is always 0 → instructions live at even addresses, PC advances by 2.El LSB siempre vale 0 → las instrucciones viven en direcciones pares y el PC avanza de 2 en 2.

PC = 0x4400
Fetch the opcode at 0x4400Captar el opcode en 0x4400
PC immediately becomes 0x4402PC pasa a 0x4402 inmediatamente
MOV.W PC, R6 R6 gets the next instruction’s address, not the current one.R6 recibe la dirección de la siguiente instrucción, no la actual.
R1

SP: descending, word-aligned.SP: descendente y alineado a palabra.

PUSH decrements first, then writes. POP reads first, then increments.PUSH decrementa y escribe. POP lee y luego incrementa.

15
0
R1 (SP)
0

LSB locked to 0 → the stack always moves in 2-byte words.LSB siempre 0 → la pila se mueve en palabras de 2 bytes.

Try the stackPrueba la pila
SP = 0x2400
PUSH / PUSH.B

SP −= 2
[SP] ← Rn.B
[SP+1] ← 0x00 *

* only on .Bsolo en .B

POP / POP.B

Rn ← [SP].B
SP += 2 (always)

@SP+ is hardwired to step 2.@SP+ siempre suma 2.

Stack frameMarco de pila
R2

R2's first role: the Status Register.El primer papel de R2: el Registro de Estado.

Four arithmetic flags, four low-power bits, and the interrupt enable.Cuatro flags aritméticos, cuatro bits de bajo consumo y el habilitador de interrupciones.

R2 as Status Register · click any bitR2 como Registro de Estado · pulsa un bit
SR = 0x0000
15
8
7
6
5
4
3
2
1
0
Reserved · bits 15–9Reservado · bits 15–9
V
SCG1
SCG0
OSC
OFF
CPU
OFF
GIE
N
Z
C
power control: SCG1, SCG0, OSCOFF, CPUOFFbajo consumo: SCG1, SCG0, OSCOFF, CPUOFF
interrupt enable: GIEhabilitador de interrupciones: GIE
arithmetic flags: V, N, Z, Cflags aritméticos: V, N, Z, C
Click any bit to see what it does.Haz clic en un bit para ver qué hace.
R2·R3

R2's second role: the constant generator.El segundo papel de R2: el generador de constantes.

As a source with certain As values, the register supplies a fixed constant instead of its contents.Como fuente con ciertos valores de As, el registro aporta una constante fija en lugar de su contenido.

R2 / CG1 when used as sourcecomo fuente
As=10
#4
As=11
#8

As=00 and As=01 still read R2: the status register.Con As=00 y As=01, R2 sigue leyendo el registro de estado.

R3 / CG2 always sourcesiempre fuente
00
#0
01
#1
10
#2
11
#-1

R3 has no other job: every read is a constant.R3 no tiene otro papel: cada lectura es una constante.

Six constants, 0, 1, 2, 4, 8, −1, available without an extra word.Seis constantes, 0, 1, 2, 4, 8, −1, disponibles sin una palabra extra.

The constant generator saves a word.El generador de constantes ahorra una palabra.

Same source code. The assembler picks the cheaper encoding.El mismo código fuente. El ensamblador elige la codificación más barata.

Without CGSin CG 2 wordspalabras
ADD.W #1, R7
0x4400
opcode · Rsrc=#N, As=11opcode · Rfuente=#N, As=11
0x4402
0x0001 ← extra word with the literalpalabra extra con el literal

A naive immediate mode would carry the literal in a second word.El modo inmediato "ingenuo" llevaría el literal en una segunda palabra.

With CGCon CG 1 wordpalabra
ADD.W #1, R7
0x4400
opcode · Rsrc=R3, As=01opcode · Rfuente=R3, As=01

The "1" is born inside the instruction itself. No extra word, no extra cycle.El "1" nace dentro de la propia instrucción. Sin palabra extra, sin ciclo extra.

Four rules behind the special cases.Cuatro reglas detrás de los casos especiales.

16-bit core

Registers, ALU and base word are 16 bits wide.Registros, ALU y palabra base son de 16 bits.

Unified address spaceMapa de memoria único

Code, RAM and peripherals share one map.Código, RAM y periféricos comparten un solo mapa.

Little-endian

The low byte goes first in memory.El byte bajo se guarda primero en memoria.

Even alignmentAlineación par

Instructions live at even addresses. PC always advances by 2.Las instrucciones viven en direcciones pares. PC avanza de 2 en 2.

0xABCD
addr
CD
addr + 1
AB

The register file, in one picture.El banco de registros, de un vistazo.

R0–R3 carry special duties. R4–R15 are yours to use.R0–R3 tienen funciones especiales. R4–R15 son tuyos.

Start Module 3: Addressing ModesComenzar Módulo 3: Modos de direccionamiento arrow_forward