MPMC ASSIGNMENT
by Sibani Sembun Sudhakaran -108123118
MSP430 addressing modes-
Indexed Mode- The effective address of the operand is computed by adding a value in a
register to an index value.
Example- CMP.B 1(R5), R15 ; Compare byte at address R5+1 with R15
MOV 2(R6), R7 ; Move the 16-bit value at address (R6 + 2) into R7
Indirect Register Addressing- The register used contains the address of the operand. The
operand can be located anywhere in the entire memory space (64K)
Example- ADD.B @R8,R9 ; ((R8)) + (R9) → (R9)
MOV @R1, R2 ; Move the 16-bit data from memory at address in R1 to R2
Indirect Register Addressing with Autoincrement- the register contains the address of the
operand, and the register is incremented after accessing the operand.
MOV.B @R2+, R3 ; Move the byte at address in R2 to R3, then increment R2
ADD @R5+, R6 ; Add the value at address in R5 to R6, then increment R5
Indexed Addressing- The address of the operand is the sum of the index and the contents of
the register used. The index is contained in an additional word located after the instruction
word.
CMP.B 1(R5), R15 ; Compare byte at address R5+1 with R15
MOV 5(R2), R5 ; Move the 16-bit value at address (R2 + 5) into R5
Immediate Addressing- Any 16-bit or 8-bit constant can be used with an instruction. The PC
points to the following word after reading the instruction word. By using the register indirect
autoincrement addressing mode, the immediate value (which is a word) can be read, and
the Program Counter (PC) is automatically incremented by two after accessing the
immediate value. This allows the word following the instruction to be treated as an
immediate value, either 8-bit or 16-bit, depending on the instruction's requirements.
MOV #5, R8 ; Move the immediate value 5 into R8
ADD #10, R9 ; Add the immediate value 10 to R9
Symbolic Addressing- In this case the program counter PC is used as the base address, so
the constant is the offset to the data from the PC. It is used by writing the symbol for a
memory location without any prefix.
SUB EDE, TONI ; Subtract the value at symbol EDE from the value at symbol TONI
MOV X(PC), R2 ; Move the value at the address X relative to the PC into R2
Absolute Addressing- the operand is accessed directly at a fixed memory address.It is often
used for hardware peripherals.
BIS #PD, &ACTL ; Set the Power Down bit in the ADC control register at address ACTL
MOV #0x200, &P1DIR ; Move immediate value 0x200 to the address of P1DIR (port 1
direction register)
INSTRUCTION SET
The MSP430 has 27 native instructions, and a further 24 emulated instructions.
There are three formats of instruction.
Double operand :Arithmetic and logical operations with two operands such as add.w src,dst,
Both operands must be specified in the instruction. This contrasts with accumulator-based
architectures, where an accumulator or working register is used automatically as the
destination and one operand.
Single operand -A mixture of instructions for control or to manipulate a single operand,
which is effectively the source for the addressing modes.
Register Addressing- This uses one or two of the registers in the CPU. It is is available for
both source and destination. Any of the 16 registers can be used for either source or
destination
Example- mov.w R1,R2 ; move word from R1 to R2
mov.w R5,R6 ; move word from R5 to R6
Two-Operand Instructions
Two-operand instructions take both a source and a destination operand. The result of the
operation is stored in the destination operand.The most common two-operand instructions
include:
ADD: Adds the source operand to the destination.
ADDC: Adds the source operand and the carry bit to the destination.
AND: Performs a bitwise AND between source and destination and stores the result
in the destination.
BIC: Clears selected bits in the destination using the inverse of the source.
BIS: Sets selected bits in the destination using the source.
BIT: Performs a bitwise AND but only affects the status bits without changing the
operands.
CMP: Compares the source and destination operands and updates status bits
accordingly.
DADD: Performs decimal addition including the carry bit.
MOV: Copies the source operand to the destination.
SUB: Subtracts the source from the destination.
SUBC: Subtracts the source and the carry bit from the destination.
XOR: Performs a bitwise exclusive OR between source and destination.
Single-Operand Instructions
Single-operand instructions operate on only one operand, which can be either the source or
destination. These also support several addressing modes. Some examples include:
CALL: Calls a subroutine at the given address.
PUSH: Pushes the operand onto the stack.
RETI: Returns from an interrupt and restores the previous CPU state.
RRA: Rotates the operand right arithmetically (preserves the sign).
RRC: Rotates the operand right through the carry bit.
SWPB: Swaps the upper and lower bytes of the operand.
SXT: Sign-extends the lower byte of a word to the full word.
Conditional Jump Instructions
Conditional jumps are used for decision-making in programs. They alter the program flow
based on the values of status register bits.The main conditional jump instructions are:
JC / JHS: Jump if carry bit is set.
JNC / JLO: Jump if carry bit is clear.
JEQ / JZ: Jump if zero bit is set (equal).
JNE / JNZ: Jump if zero bit is clear (not equal).
JN: Jump if negative bit is set.
JGE: Jump if greater than or equal to (signed comparison using overflow and negative
bits).
JLT: Jump if less than (signed comparison).
JMP: Unconditional jump to the specified address.
Emulated Instructions
Emulated instructions are not directly built into the hardware but are synthesized using
existing instructions and constants provided by the constant generator. These instructions
simplify programming and make the code more readable. Common emulated instructions
include:
ADC: Adds the carry bit to the destination.
BR: Branches to the address in the operand.
CLR: Clears the operand by setting it to zero.
CLRC, CLRN, CLRZ: Clear specific bits in the status register.
DADC: Decimal add with carry.
DEC, DECD: Decrement by one or by two.
INC, INCD: Increment by one or by two.
INV: Inverts all bits in the operand.
NOP: No operation; used for timing or alignment.
POP: Pops the top of the stack into the operand.
RET: Returns from a subroutine.
RLA: Rotates the operand left arithmetically.
RLC: Rotates the operand left through the carry.
SBC: Subtracts the carry bit from the operand.
SETC, SETN, SETZ: Set specific status bits.
TST: Tests the operand for zero or negative value and sets flags accordingly.