# MSP430 - how to check addressing types

I'm programming a MSP430 in C language as a simulation of real microcontroller. I got stuck in addressing modes (https://en.wikipedia.org/wiki/TI_MSP430#MSP430_CPU), especially:

• Addressing modes using R0 (PC)
• Addressing modes using R2 (SR) and R3 (CG), special-case decoding

1. I don't understand what does mean 0(PC), 2(SR) and 3(CG). What they are?
2. How to check these values?
• The Wiki article explains : R0(PC) is the program counter, R1(SP) the stack pointer, R2(SR) the status register(carry flag, and power saving modes) - and R3 (CG) generates constant values without requiring the space they would require as literal values. As these are register addresses, not modes, I can't really understand what you're asking. Perhaps explain a bit more what you don't understand? – Brian Drummond Jan 14 '16 at 0:03
• Do I understand correctly that you are trying to write an MSP430 Emulator in C? – brhans Jan 14 '16 at 0:25
• Duplicate of same question on Stack Overflow. – CL. Jan 14 '16 at 7:41

so for the source if the as bits are 01 and the source register bits are a 0 which is the pc for reference then

ADDR Symbolic. Equivalent to x(PC). The operand is in memory at address PC+x.

if the ad bit is a 1 and the destination is a 0 then also

ADDR Symbolic. Equivalent to x(PC). The operand is in memory at address PC+x.

x is going to be another word that follows this instruction so the cpu will fetch the next word, add it to the pc and that is the source

if the as bits are 11 and the source is register 0, the source is an immediate value which is in the next word after the instruction.

if the as bits are 01 and the source is a 2 which happens to be the SR register for reference then the address is x the next word after the instruction (&ADDR)

if the ad bit is a 1 and the destination register is a 2 then it is also an &ADDR

if the as bits are 10 the source bits are a 2, then the source is the constant value 4 and we dont have to burn a word in flash after the instruction for that 4.

it doesnt make sense to have a destination be a constant 4 so that isnt a real combination.

repeat for the rest of the table.

you can have both of these addressing modes at the same time

mov #0x5A80,&0x0120


generates

c000:   b2 40 80 5a     mov #23168, &0x0120 ;#0x5a80
c004:   20 01


which is

0x40b2 0x5a80 0x0120

0100000010110010
0100 opcode mov
0000 source
0 b/w
11 as
0010 destination


so we have an as of 11 with source of 0 the immediate #x, an ad of 1 with a destination 2 so the destination is &ADDR. this is an important experiment because when you have 2 x values, a three word instruction basically which one goes with the source and which the destination

0x40b2 0x5a80 0x0120


so the address 0x5a80 which is the destination is the first x to follow the instruction then the source 0x0120 an immediate comes after that.

if it were just an immediate and a register then

c006:   31 40 ff 03     mov #1023,  r1  ;#0x03ff

0x4031 0x03FF

0100000000110001
0100 mov
0000 source

Register direct. The operand is the contents of Rn