How well this is checked
llvm cannot decode the MSP430X (the extension word and every address instruction are “invalid” to it), so the 20-bit forms are checked against two other sources.
GNU binutils 2.47 (objdump -m MSP430X): all 65,536 first words were compared with the decoder, with no unexplained difference (the explained ones are GNU spellings, GNU’s refusal of R3 as a destination, and the reserved size combinations the decoder follows TI on), and 97,920 extension word and instruction pairs were compared by mnemonic and size.
TI’s user’s guide SLAU367P (the CPUX chapter, sections 4.5.2 and 4.6) is the source of every pattern and cycle count here, read as text; the manual’s tables for the older CPUX in SLAU144K differ in some cycle counts and are noted where they do.
What was not done: no MSP430X program or emulator ran the instructions, and the decoder was never compared with silicon.
What the MSP430X adds
- 20-bit registers (R0 to R15) and addresses: a 1 MB address space. PC and SP are 20 bits; the instructions without an extension word still work on 16 bits and clear the upper four bits of a register they write.
- The extension word: a word in front of a core instruction that makes it a 20-bit (
.A), 16-bit (.W) or 8-bit (.B) operation with 20-bit offsets and addresses, or makes it repeat. - Address instructions that always work on 20 bits (
MOVA,CMPA,ADDA,SUBA), multi-bit shifts,PUSHMandPOPM, andCALLA.
The extension word
An extension word is any word from 0x1800 to 0x1FFF (0001 1 in bits 15 to 11) followed by a core instruction of format I or II. It comes in two forms, chosen by the instruction that follows:
when every operand is in register mode it is the register-mode form; otherwise the non-register form.
| Bits | Register-mode form | Non-register form |
|---|---|---|
| 15 to 11 | 00011 | |
| 10 to 9 | 0 (reserved) | bits 19 to 16 of the source operand’s offset, address or immediate (bits 10 to 7) |
| 8 | ZC: 1 = the carry is not used (taken as zero) by ADDC, SUBC, DADD and the rotates | |
| 7 | #: 0 = the repeat count is in bits 3 to 0, 1 = it is in the low four bits of the register named there | (bit 7 of the source bits above) |
| 6 | A/L, which together with the instruction’s B/W bit gives the size: A/L = 0 and B/W = 1: 20 bits (.A); A/L = 1 and B/W = 0: 16 bits (.W); A/L = 1 and B/W = 1: 8 bits (.B); A/L = 0 and B/W = 0: reserved. This is the general rule, not a universal one: SWPBX and SXTX read the two bits differently (below). | |
| 5 to 4 | 0 (reserved) | |
| 3 to 0 | the repeat count minus one, or the register that holds it | bits 19 to 16 of the destination operand’s offset or address |
With the extension word the instruction gets an x in its name: movx.a, addx.w, rrax.a, pushx.b. The extra words that hold offsets, absolute addresses and immediates are the same as before, with the 16 bits that
follow and the four bits from the extension word making 20. The repeat is written rpt #n { rrax.a r5 (or rpt r6 { … for a count in a register).
There is no extended CALL (CALLA is the 20-bit call); the extended instructions are in the table below, one anchor each.
| Core instruction | Extended | Notes |
|---|---|---|
MOV | MOVX.A, .W, .B | |
ADD | ADDX | |
ADDC | ADDCX | ZC applies in register mode. |
SUBC | SUBCX | ZC applies in register mode. |
SUB | SUBX | |
CMP | CMPX | |
DADD | DADDX | ZC applies in register mode. |
BIT | BITX | |
BIC | BICX | |
BIS | BISX | |
XOR | XORX | |
AND | ANDX | |
RRC | RRCX | The repeat count applies in register mode. |
RRA | RRAX | The repeat count applies in register mode. |
SWPB | SWPBX | .A swaps the bytes of the low word of a 20-bit value. Size bits (TI SLAU367P 4.5.2.2, NOTE “B/W and A/L bit settings for SWPBX and SXTX”): A/L = 0, B/W = 0 is .A; A/L = 1, B/W = 0 is .W; B/W = 1 (A/L 0 or 1) is not applicable and the decoder shows it as reserved. GNU binutils reads them the same way. |
SXT | SXTX | .A sign-extends bit 7 into bits 8 to 19. The size bits are read as for SWPBX. |
PUSH | PUSHX | .A pushes 20 bits in two words. |
The address instructions
The words 0x0000 to 0x0FFF, which are no instruction on the 16-bit CPU. They need no extension word and work on 20 bits. In the patterns sss is the source register, ddd the destination register, and x bits 19 to 16 of an address or immediate whose low 16 bits follow in the next word.
| Instruction | Pattern (bits 15 to 0) | Words |
|---|---|---|
MOVA @Rs,Rd | 0000 ssss 0000 dddd | 1 |
MOVA @Rs+,Rd | 0000 ssss 0001 dddd | 1 |
MOVA &abs20,Rd | 0000 xxxx 0010 dddd + low 16 bits | 2 |
MOVA x(Rs),Rd | 0000 ssss 0011 dddd + signed 16-bit offset | 2 |
MOVA Rs,&abs20 | 0000 ssss 0110 xxxx + low 16 bits | 2 |
MOVA Rs,x(Rd) | 0000 ssss 0111 dddd + signed 16-bit offset | 2 |
MOVA #imm20,Rd | 0000 xxxx 1000 dddd + low 16 bits | 2 |
CMPA #imm20,Rd | 0000 xxxx 1001 dddd + low 16 bits | 2 |
ADDA #imm20,Rd | 0000 xxxx 1010 dddd + low 16 bits | 2 |
SUBA #imm20,Rd | 0000 xxxx 1011 dddd + low 16 bits | 2 |
MOVA Rs,Rd | 0000 ssss 1100 dddd | 1 |
CMPA Rs,Rd | 0000 ssss 1101 dddd | 1 |
ADDA Rs,Rd | 0000 ssss 1110 dddd | 1 |
SUBA Rs,Rd | 0000 ssss 1111 dddd | 1 |
MOVA does not change flags; CMPA, ADDA and SUBA set V, N, Z and C on the 20-bit result (SLAU367P Table 4-16).
Rotates and shifts by several bits
0000 nn kk 010w dddd: nn (bits 11 to 10) is the shift count minus one (1 to 4), kk (bits 9 to 8) the kind, w (bit 4) is 1 for .W (16 bits) and 0 for .A (20 bits), and dddd the register. N, Z and C are set from the result; V is cleared by RRCM, RRAM and RRUM, and only RLAM changes V by the result (SLAU367P Table 4-14: V = 0 for the rotates, * for RLAM).
kk | Instruction | Operation |
|---|---|---|
| 00 | RRCM.A, .W #n,Rd | Rotate right through the carry n times. |
| 01 | RRAM | Arithmetic shift right n times. |
| 10 | RLAM | Shift left n times. |
| 11 | RRUM | Logical shift right n times (zeros into the top bit). |
PUSHM, POPM and CALLA
| Instruction | Pattern | Operation |
|---|---|---|
PUSHM.A, .W #n,Rd | 0001 010w nnnn dddd | Pushes n registers (n = field + 1, 1 to 16), Rd first and then the registers below it, as 20-bit (.A, w = 0) or 16-bit (.W, w = 1) values. |
POPM.A, .W #n,Rd | 0001 011w nnnn dddd | Pops n registers (n = field + 1) into Rd−n+1 up to Rd. The dddd field holds the FIRST register restored, Rd−n+1, so the assembly operand Rd is the field plus n−1 (TI SLAU367 example: POPM.A #5,R13 restores R9 to R13; GNU binutils 2.47 prints the same). |
CALLA | 0001 0011 01as dddd (register, x(Rn), @Rn, @Rn+), 0001 0011 1000 xxxx (&abs20), 1001 (symbolic), 1011 (#imm20), each of the last three followed by the low 16 bits | Pushes the 20-bit return address (two words) and jumps to the 20-bit operand. The words 0x1340 to 0x13BF are CALLA: 0x1340 to 0x137F register, x(Rn), @Rn, @Rn+ and 0x1380 to 0x13BF &abs20 (0x138x), symbolic (0x139x), #imm20 (0x13Bx). 0x13A0 to 0x13AF (0001 0011 1010 xxxx) is reserved, and so are 0x13C0 to 0x13FF (0001 0011 11xx xxxx) and 0x1301 to 0x133F (SLAU367P 4.6.1, the instruction map and the CALLA opcode rows). |
RETI on the 20-bit CPU pops SR (with PC bits 19 to 16 in its top four bits) and then PC bits 15 to 0, so the 20-bit PC is restored; its encoding is that of the 16-bit CPU, 0x1300. The flags V, N, Z and C come back from the stack, and so do OSCOFF, CPUOFF and GIE (SLAU367P 4.6.2.37). The interrupt entry pushes the PC the same way (interrupts).
Emulated instructions of the 20-bit CPU, and RPT
TI lists these emulated forms for the extension (SLAU367P Table 4-15). They are one encoding each; the decoder writes the core name (movx, addx, mova …) and does not apply these aliases to the extended instructions (the 16-bit aliases on the emulated page are applied to the 16-bit encodings only).
| Emulated | Meaning | Core instruction |
|---|---|---|
ADCX(.B,.A) dst | add carry to dst | ADDCX(.B,.A) #0,dst |
BRA dst | branch indirect | MOVA dst,PC |
RETA | return from subroutine (20-bit) | MOVA @SP+,PC |
CLRA Rdst | clear Rdst | MOV #0,Rdst (as printed in SLAU367P) |
CLRX(.B,.A) dst | clear dst | MOVX(.B,.A) #0,dst |
DADCX(.B,.A) dst | add carry decimally | DADDX(.B,.A) #0,dst |
DECX(.B,.A) dst | decrement by 1 | SUBX(.B,.A) #1,dst |
DECDA Rdst | decrement Rdst by 2 | SUBA #2,Rdst |
DECDX(.B,.A) dst | decrement by 2 | SUBX(.B,.A) #2,dst |
INCX(.B,.A) dst | increment by 1 | ADDX(.B,.A) #1,dst |
INCDA Rdst | increment Rdst by 2 | ADDA #2,Rdst |
INCDX(.B,.A) dst | increment by 2 | ADDX(.B,.A) #2,dst |
INVX(.B,.A) dst | invert dst | XORX(.B,.A) #-1,dst |
RLAX(.B,.A) dst | shift left arithmetically | ADDX(.B,.A) dst,dst |
RLCX(.B,.A) dst | shift left through carry | ADDCX(.B,.A) dst,dst |
SBCX(.B,.A) dst | subtract carry | SUBCX(.B,.A) #0,dst |
TSTA Rdst | test Rdst | CMPA #0,Rdst |
TSTX(.B,.A) dst | test dst | CMPX(.B,.A) #0,dst |
POPX dst | pop to dst | MOVX(.B,.A) @SP+,dst |
TI also lists RRUX(.B,.A) Rdst, a register-only rotate right unsigned (Table 4-14): it is RRCX with the extension word’s ZC bit set, which makes the carry count as 0; GNU objdump prints that encoding as rrux, the decoder as rrcx with a note.
Repeat. An extension word in register mode repeats the instruction n times, with n − 1 in bits 3:0 or, when the # bit is set, in the four low bits of a register (Table 4-11). The assembler’s spelling is RPT #n or RPT Rn in front of the instruction; the decoder writes rpt #n { … . TI’s manual does not give a repeat for memory operands: the extension word’s register-mode form belongs to register-to-register instructions, and the decoder applies a repeat only there. When the count is 1 and the register field is 0 the decoder writes rpt r0 { (R0 is the PC; TI says nothing and GNU prints no repeat).
Cycles
From SLAU367P (the user’s guide for the MSP430F5xx/6xx and FR families, section 4.5.2.7). The counts are in MCLK cycles; n is the number of repeats or shifts, and a register-mode repeat takes n + 1 cycles (Table 4-18, note 1). These counts belong to that CPUX. The 2xx guide (SLAU144K) prints other figures for some forms of the older CPUX, for example CALLA 4, 5, 5, 4, 6, 6, 6 and RETI 3, and notes where the MSP430 CPU differs; the decoder uses SLAU367P for the msp430x variant.
| Instruction | Rn | @Rn | @Rn+ | #N | X(Rn) | EDE | &EDE |
|---|---|---|---|---|---|---|---|
RRAM, RRCM, RRUM, RLAM | n | – | – | – | – | – | – |
PUSHM / POPM (.W) | 2 + n | – | – | – | – | – | – |
PUSHM.A / POPM.A | 2 + 2n | – | – | – | – | – | – |
CALLA | 5 | 6 | 6 | 5 | 5 (+1 if Rn = SP) | 7 | 7 |
RRAX, RRCX (.B, .W) | 1 + n | 4 | 4 | – | 5 | 5 | 5 |
RRAX.A, RRCX.A | 1 + n | 6 | 6 | – | 7 | 7 | 7 |
PUSHX (.B, .W) | 4 | 4 | 4 | 4 | 5 (+1 if Rn = SP) | 5 | 5 |
PUSHX.A | 5 | 6 | 6 | 5 | 7 (+1 if Rn = SP) | 7 | 7 |
POPX (.B, .W) | 3 | – | – | – | 5 | 5 | 5 |
POPX.A | 4 | – | – | – | 7 | 7 | 7 |
SWPBX and SXTX are not in the table. For the double-operand extended forms (Table 4-18), per source row and destination Rm / PC / memory (x(Rm), EDE, &EDE), the .B/.W count is first and the .A count second:
| Source | to Rm | to PC | to memory |
|---|---|---|---|
Rn | 2 / 2 | 4 / 4 | 5 / 7 |
@Rn, @Rn+ | 3 / 4 | 5 / 6 | 6 / 9 |
#N | 3 / 3 | 4 / 4 | 6 / 8 |
X(Rn), EDE, &EDE | 4 / 5 | 6 / 7 | 7 / 10 |
Adjustments: a memory destination takes one cycle less (.B/.W) or two less (.A) for MOVX, BITX and CMPX; a PC destination from #N, X(Rn), EDE or &EDE takes one less for MOVX, ADDX and SUBX. The address instructions (Table 4-19): MOVA Rn to Rn 1 (to PC 3), @Rn or @Rn+ to Rm 3 (PC 5), #N to Rm 2 (PC 3), X(Rn), EDE or &EDE to Rm 4 (PC 6), Rn to memory 4; CMPA, ADDA, SUBA register to register 1 (to PC 3) and #N 3. RETI takes 5 cycles on this CPUX (Table 4-8). The memory-destination and PC-destination counts of the 16-bit instruction formats are on the formats page.
Not described
- What happens to the upper four bits of a register in each 16-bit operation beyond TI’s rule (a byte write clears bits 19:8, a word write clears bits 19:16), and how the repeat count interacts with the flags beyond the manual’s tables.
- The extension word’s reserved bits 10 to 9 (register mode): the decoder rejects an extension word with bits 5 or 4 set, and does not check bits 10 to 9.
- The emulated
Xforms above are documented, but the decoder does not apply the aliases to the extended instructions. - The cycle counts of
SWPBXandSXTX, and of repeats from memory operands: TI’s tables do not give them.