ECE 2560 The MSP 430 Instruction Set Department

  • Slides: 26
Download presentation
ECE 2560 The MSP 430 Instruction Set Department of Electrical and Computer Engineering The

ECE 2560 The MSP 430 Instruction Set Department of Electrical and Computer Engineering The Ohio State University ECE 3561 - Lecture 1 1

The MSP 430 Instruction Set l What is an Instruction Set l The MSP

The MSP 430 Instruction Set l What is an Instruction Set l The MSP 430 Instruction Set l Instruction Formats l Assemblers ECE 3561 - Lecture 1 2

Assembly Language l Assembler Language Instructions l l l The core instruction set of

Assembly Language l Assembler Language Instructions l l l The core instruction set of a processor Allow programming in pneumonics and symbols versus direct machine language. Assembler language instruction l l Machine language instruction l l l MOV R 4, R 3 $9 A 42 1 Assembler Instr 1 Machine Instr A machine instruction specifies exactly what functions will be taken by the processor. l l Example – move the contents of R 1 to R 2 Decoded and causes generation of control signals that cause the movement of data ECE 3561 - Lecture 1 3

The MSP 430 Instruction Set Consists of 27 core instructions and 24 emulated instructions.

The MSP 430 Instruction Set Consists of 27 core instructions and 24 emulated instructions. l Core instructions have unique op-codes l Emulated instructions – instructions made easier to write and read. When assembled they are replaced by the assembler with an equivalent core instruction. l Note: There is no code or performance penalty for using emulated instructions. l See manual for instructions l ECE 3561 - Lecture 1 4

What is an assembler? l It is a software program that has, as input,

What is an assembler? l It is a software program that has, as input, assembler language code and produces, as output, the machine language for a specific processor, i. e. , the binary coding of instrcutions. l Typically assemblers work with a group of processor targets in the same family. ECE 3561 - Lecture 1 5

Core Instruction Formats l l l Single operand Dual operand Jump Single and dual

Core Instruction Formats l l l Single operand Dual operand Jump Single and dual operand instructions can be byte or word instructions by using the. B or. W extension. l Byte instructions – used for byte data or byte peripherals l Word instructions – used for word data or word peripherals l No. B or. W ? – defaults to a word instruction l ECE 3561 - Lecture 1 6

Notation l In instruction description l l l l src – The source operand

Notation l In instruction description l l l l src – The source operand – As and S-reg dst – The destination operand – Ad and D-reg As – The addressing bits responsible for the addressing mode used for the source S-reg – The register used for the source Ad – The addressing bits used for the destination D-reg – The register used for the destination Note on destination l Destination addresses can be anywhere in the memory map, but they must be writeable to be effective. ECE 3561 - Lecture 1 7

Double Operand Instructions l The format of the two operand instruction is l The

Double Operand Instructions l The format of the two operand instruction is l The fields are almost self explanatory l The assembler language instruction looks like l MOV src, dst ECE 3561 - Lecture 1 8

Single Operand Instruction l The format of the single operand instruction is l Again,

Single Operand Instruction l The format of the single operand instruction is l Again, the fields are self explanatory l Example l SXT dst ECE 3561 - Lecture 1 9

Jump Instruction l The format of jump instructions is Modifies the Program Counter, PC,

Jump Instruction l The format of jump instructions is Modifies the Program Counter, PC, to alter control flow. l Example l l JNE label represents an address Action is to transfer execution to label if zero bit of condition code register set. Otherwise execution continues with the next instruction. ECE 3561 - Lecture 1 10

The Program Counter l The Program Counter always points to the memory location of

The Program Counter l The Program Counter always points to the memory location of the next instruction word to be fetched. l Instructions are 1 to 3 words in length. l As the PC points to words, the lsb is always 0. ECE 3561 - Lecture 1 11

The instruction set l The full instruction set is shown to the right. l

The instruction set l The full instruction set is shown to the right. l How to learn instruction set? l Break down into groups ECE 3561 - Lecture 1 12

Data movement l The MOV instruction Moves data to and from memory (or an

Data movement l The MOV instruction Moves data to and from memory (or an I/O port) to a destination. l The source can use any addressing mode l The destination can use any addressing mode. l Addressing modes l l Register, immediate, absolute, indexed, symbolic, indirect register, indirect autoincrement ECE 3561 - Lecture 1 13

The MOV instruction l Examples l of the move instruction Load a specific value

The MOV instruction l Examples l of the move instruction Load a specific value into a register src – use immediate mode l dst – use register mode l MOV #024 h, R 9 l l l Set the contents of R 9 to $0024 MOV #6511 h, R 2 l Set the contents of R 2 to $6511 l MOV(. B) is the only instruction for movement of data ECE 3561 - Lecture 1 14

Arithmetic instructions l l l ADC dst Add C to destination ADD src, dst

Arithmetic instructions l l l ADC dst Add C to destination ADD src, dst Add source to destination ADDC src, dst Add source and C to destination DADC dst Add C to decimally to dst DADD src, dst Add src and C decimally to dst DEC dst Decrement destination DECD dst Double-decrement destination INC dst Increment destination INCD dst Double-increment destination SUB src, dst Subtract source from destination SUBC src, dst Subtract source and not(C) from dst SBC dst Subtract not(C) from destination l All have. B mode for byte data ECE 3561 - Lecture 1 15

Logical Instructions l l l l AND src, dst Logical AND source and destination

Logical Instructions l l l l AND src, dst Logical AND source and destination INV dst Logical invert destination RLA dst Rotate left arithmetically RLC dst Rotate left through C RRA dst Rotate right arithmetically RRC dst Rotate right through C XOR src, dst Exclusive OR source and destination CLR dst Clear the destination to 0’s l l l ALL ABOVE HAVE. B to operate on byte data SWPB dst Swap bytes SXT dst Sign extend low byte through high byte ECE 3561 - Lecture 1 16

Compare and Test CMP(. B) src, dst Compare source and destination l TST(. B)

Compare and Test CMP(. B) src, dst Compare source and destination l TST(. B) dst Test destination l BIT(. B) src, dst src and dst are logically ANDed l l N is msb, Z set if 0, C is NOT Z, V reset l These instructions do not modify the contents of src or dst. l They do however, set the bits of the condition code register (CC) l Used to set bits for branching ECE 3561 - Lecture 1 17

Set and clear bits l Masked l BIC(. B) src, dst Clear bits in

Set and clear bits l Masked l BIC(. B) src, dst Clear bits in destination l l set and clear - data Result: NOT. src AND dst -> dst BIS(. B) src, dst Set bits in destination l l Set Result: src OR dst -> dst and clear bits of CC register CLRC Clear C l CLRN Clear N l CLRZ Clear Z l SETC Set C SETN Set N SETZ Set Z ECE 3561 - Lecture 1 18

Transfer of control flow Normal operation has the next instruction in memory executed next

Transfer of control flow Normal operation has the next instruction in memory executed next (PC+2 or 3) l Control flow instructions can modify were the next instruction is fetched from. l The Jump instructions (conditional) l l l l l JC/JHS label Jump if C set/Jump if higher or same JEQ/JZ label Jump if equal/Jump if Z set JGE label Jump if greater or equal JL label Jump if less JN label Jump is N set JNC/JLO label Jump if C not set/Jump if lower JNE/JNZ label Jump if not equal/Jump if Z not set Unconditional l l JMP label BR dst This is an unconditional jump ( (label)->PC ) Branch to destination (dst-> PC) ECE 3561 - Lecture 1 19

Subroutine support l Support l for subroutine instrcutions CALL dst Call destintion ACTION: l

Subroutine support l Support l for subroutine instrcutions CALL dst Call destintion ACTION: l SP-2 -> SP, l l RET PC+2 -> @SP, dst->PC Return from subroutine ACTION: l @SP-> PC, SP+2 -> SP l ECE 3561 - Lecture 1 20

Stacks l The stack – an area of memory for storage of data accessed

Stacks l The stack – an area of memory for storage of data accessed through the PUSH and POP instructions ECE 3561 - Lecture 1 21

Stac. K instructions l Two instructions l PUSH(. B) src Push the source onto

Stac. K instructions l Two instructions l PUSH(. B) src Push the source onto stack l l Action is SP-2 -> SP POP(. B) dst l src->@SP Pop item from stack to destination Action is @SP-> dst SP+2 -> SP Convention is that the stack grows down in memory l The MSP 430 s : SP points to TOS and valid data l l NOTE: in some processor chips (microcontrollers and processors) the SP points to a free location l ACTIONS to push and pop? ECE 3561 - Lecture 1 22

Interrupts l. A pin on the MSP 430 is the Non. Maskable Interrupt (NMI)

Interrupts l. A pin on the MSP 430 is the Non. Maskable Interrupt (NMI) input pin. l Interrupts allow an external device to call for attention. l The current instruction is completed and then the device is “serviced”. l There are 3 instructions for managing this pin. ECE 3561 - Lecture 1 23

Interrupt instructions l Permitting and not permitting interrupts l l EINT DINT Enable interrupts

Interrupt instructions l Permitting and not permitting interrupts l l EINT DINT Enable interrupts Disable interrupts When an interrupt occurs, control flow is automatically transferred to the program that will deal with it. But first the PC and status register are pushed to the Stack. l How to get back to where your program was at the time the interrupt occurred? l l RETI l Return from interrupt Will pop the status register and PC from the Stack. ECE 3561 - Lecture 1 24

The last instruction l The final instruction in the instruction set is l NOP

The last instruction l The final instruction in the instruction set is l NOP No Operation ECE 3561 - Lecture 1 25

Summary - Assignment The MSP 430 Users Guide has been added to the course

Summary - Assignment The MSP 430 Users Guide has been added to the course webpage. l The information in this lecture is a summary of the information of Table 3 -17. l Next – Using CCS for assembler language programming. If you want to get a jump on this you can watch Dr. Khan’s 2560 screencast 07 and 08. l l Quiz – see web page l l Will cover some initial aspects of instruction Example: Write the assembler instruction that will copy the contents of R 4 to R 8. ECE 3561 - Lecture 1 26