Presentation is loading. Please wait.

Presentation is loading. Please wait.

Architecture of the MSP430 Processor. Central Processing Unit Program Counter (PC) - Contains the address of the next instruction to be executed. The.

Similar presentations


Presentation on theme: "Architecture of the MSP430 Processor. Central Processing Unit Program Counter (PC) - Contains the address of the next instruction to be executed. The."— Presentation transcript:

1 Architecture of the MSP430 Processor

2 Central Processing Unit Program Counter (PC) - Contains the address of the next instruction to be executed. The lsb of the PC is hardwired to 0 Stack Pointer (SP) - The stack is heavily used for temporary variables, passing parameters to subroutines and returning the result, particularly for compiled languages. The stack pointer holds the address of the top of the stack. The lsb of the stack pointer is hardwired to 0 in the MSP430, which guarantees that it always points to valid words.

3 Operation of the stack

4 Status Register (SR) This contains a set of flags (single bits). Result of Arithmetic or Logic Operations: The C, Z, N, and V bits are affected by many of the operations performed by the ALU. The carry bit C is to flag that the result of an arithmetic operation is too large to fit in the space allocated. The zero flag Z is set when the result of an operation is 0. The negative flag N is made equal to the msb of the result, which indicates a negative number if the values are signed. The signed over flow flag V is set when the result of a signed operation has overflowed, even though a carry may not be generated.

5 Status Register (SR) Enable Interrupts - Setting the general interrupt enable or GIE bit enables maskable interrupts, provided that the individual sources of interrupts have themselves been enabled. Control of Low-Power Modes - The CPUOFF, OSCOFF, SCG0 (system clk generator), and SCG1 bits control the mode of operation of the MCU.

6 Constant Generators Both R2 and R3 are used to provide the 6 most commonly used constants. This saves storing the values in the program and having to fetch them each time.

7 General-Purpose Registers The remaining 12 registers R4–R15 have no dedicated purpose and may be used as general working registers. They may be used for either data or addresses because both are 16-bit values, which simplifies the operation significantly.

8 Addressing Modes The ways in which operands can be specified. Double operand (Format I): Arithmetic and logical operations with two operands such as add.w src, dst. accumulator-based architectures, where an accumulator or working register is used automatically as the destination and one operand. Single operand (Format II): instructions for control or to manipulate a single operand. Jumps: The jump to the destination rather than its absolute address, in other words the offset that must be added to the program counter. The “return from interrupt” instruction reti is unique in requiring no operands. This would usually be described as inherent addressing but TI classifies it as Format II without data. ;

9 Register Mode This uses one or two of the registers in the CPU. It is the most straightforward addressing mode and is available for both source and destination. The registers are specified in the instruction word; no further data are needed. It is also the fastest mode and this instruction takes only 1 cycle. Any of the 16 registers can be used for either source or destination. For byte instructions, ◦ Operands are taken from the lower byte; the upper byte is not affected. ◦ The result is written to the lower byte of the register and the upper byte is cleared. ◦ The upper byte of a register in the CPU cannot be used as a source. If this is needed, the 2 bytes in a word must first be swapped with swpb.

10 Indexed Mode The address is formed by adding a constant base address to the contents of a CPU register; the value in the register is not changed. Suppose that R5 contains the value 4 before this instruction:

11 Symbolic Mode (PC Relative) 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. TI calls this the symbolic mode although it is usually described as PC-relative addressing. It is used by writing the symbol for a memory location without any prefix. Instruction stores the value of LoopCtr in R6 using symbolic mode. The assembler replaces this by the indexed form, Where X = LoopCtr − PC is the offset that needs to be added to PC to get the address of LoopCtr. PC-relative addressing is essential to produce position-independent code.

12 Absolute Mode The constant in this form of indexed addressing is the absolute address of the data. Absolute addressing is shown by the prefix & and should be used for special function and peripheral registers, whose addresses are fixed in the memory map. The assembler replaces this by the indexed form, Where P1IN is the absolute address of the register.

13 SP-Relative Mode TI does not claim this as a distinct mode of addressing. The stack pointer SP can be used as the register in indexed mode like any other. This type of manipulation is important in subroutines and interrupts.

14 Indirect Register Mode Shown by the symbol @ in front of a register, such as @R5. The contents of R5 are used as the address of the operand. In other words, R5 holds a pointer rather than a value (the contents of R5 would be the operand itself if the @ were omitted). Suppose that R5 contains the value 4, A word is loaded from address 4 into R6. Saves a word of program memory, which also makes it faster. Thus the reverse of the preceding move must be done like this:

15 Indirect Autoincrement Register Mode Shown by the symbol @ in front of a register with a + sign after it, such as @R5+. It uses the value in R5 as a pointer and automatically increments it afterward by 1 if a byte has been fetched or by 2 for a word. Suppose that R5 contains the value 4, A word is loaded from address 4 into R6 and the value in R5 is incremented to 6 because a word (2 bytes) was fetched. The reverse of this move needs two instructions,

16 Indirect Autoincrement Register Mode Autoincrement is usually called postincrement addressing because many processors have a complementary predecrement addressing mode but the MSP430 does not. An important feature of the addressing modes is that all operations on the first address are fully completed before the second address is evaluated. The move itself might be done by a line, Suppose that R5 initially contains the value 4. The contents of address 4 is read and R5 is double-incremented to 6 because a word is involved. The address for the destination calculated as 0x0100 + 0x0006=0x0106. Thus a word is copied from address 0x0004 to 0x0106; the offset is not just the value of 0x0100 used as the base address for the destination. The compiler takes care of these details if you write in C, but you are on your own with assembly language.

17 Immediate Mode This is a special case of autoincrement addressing that uses the program counter PC. The instruction loads this word into R6 and increments PC to point to the next word, which in this case is the next instruction. The word that followed the original instruction has been loaded into R6. It is the equivalent of R6 = constant.

18 Constant Generator and Emulated Instructions A complex instruction set computer (CISC) has special instructions for performing many common operations. In contrast, a reduced instruction set computer (RISC) uses general instructions for these operations. To improve efficiency, most RISCs therefore have one or more registers that are “hardwired” to commonly used values. Dedicated constant generator R3/CG2. The status register R2/SR/CG1 acts as constant generator CG1 when it is used as a source in the other three addressing modes. These provide the base of 0 for absolute addressing, and the six immediate values 0, 1, 2, 4, 8, and 0xFFFF= − 1 for signed values.

19 Constant Generator and Emulated Instructions The chosen values are frequently used in comparison, arithmetic, and logic operations and for masks to pick out bits 0–3. Direct (register) addressing of R3/CG2 returns the value 0, so mov.w R3, R5 clears R5. Similarly, mov.w @R2, R5 uses indirect addressing on R2/SR/CG1, which returns the value 8 and this will be stored in R5. These constants are combined with many of the 27 native instructions to provide a further 24 emulated instructions.

20 Instruction Set The instruction set is orthogonal, meaning that all addressing modes can be used with all instructions and registers..w form for operations that can use either bytes or words. Movement Instructions: There is only the one mov instruction to move data. Stack Operations: These push data onto the stack and pop them off. The SP is fixed to be even, so a word of stack space is always consumed, even if only a byte is added.

21 Arithmetic and Logic Instructions with Two Operands Binary Arithmetic Instructions with Two Operands The compare operation cmp is the same as subtraction sub except that only the bits in SR are affected; the result is not written back to the destination.

22 Arithmetic Instructions with One Operand All these are emulated, which means that the operand is always a destination, Decimal Arithmetic: These instructions are used when operands are binary-coded decimal (BCD) rather than ordinary binary values.

23 Logic Instructions with Two Operands The and and bitwise test operations are identical except that bit is only a test and does not change its destination. Logic Instructions with One Operand: There is only one of these, the invert inv instruction, aka ones complement, which changes all bits of 0 to 1 and those of 1 to 0.

24 Byte Manipulation Operations on Bits in Status Register: There is a set of emulated instructions to set or clear the four lowest bits in the status register.

25 Shift and Rotate Instructions Logical shift inserts zeroes for both right and left shifts. Arithmetic shift inserts zeroes for left shifts but the most significant bit, which carries the sign, is replicated for right shifts. Rotation does not introduce or lose any bits; bits that are moved out of one end of the register are passed around to the other.

26 Shift and Rotate Instructions Usually the carry bit is included in rotations and it may gain the bit that is shifted out by arithmetic or logical shifts. The MSP430 has arithmetic shifts and rotations, all of which use the carry bit. The right-shifts are native instructions but the left shifts are emulated, so the left- and right-shifts have different addressing modes available,

27 Flow of Control Subroutines, Interrupts, and Branches: Both br and call can use the full range of addressing modes for a source. The most common use of call is for a subroutine that begins at a particular label. This label is translated by the assembler to the address of the first instruction in the subroutine: direct addressing. This is the value that should be loaded into the PC to call the subroutine and is therefore like immediate data. It must consequently be given the prefix # like any other immediate value. For example, call #DelayTenths. Jump instructions use offsets rather than full addresses and the compiler or assembler calculates these automatically.

28 Jumps, Unconditional and Conditional jmp fits in a single word, including the offset, but its range is limited to about ±1KB from the current location. br can go anywhere in the address space and use any addressing mode but is slower and requires an extra word of program storage. The symbol $ stands for the current value of the program counter in the assembler so jmp $ is a concise way of getting an empty, infinite loop. The conditional jumps are the “decision-making” instructions and test certain bits or combinations in the status register. It is not possible to jump according to the value of any other bits in SR or those in any other register. Typically a bit test instruction bit is used to detect the bit(s) of interest and set up the flags in SR before a jump.

29 Jumps, Unconditional and Conditional Many branches have two names to reflect different usage. It is clearer to use jc if the carry bit is used explicitly—after a rotation, for instance—but jhs is more appropriate after a comparison:

30 Cycle-by-cycle operation of typical instructions

31 Breakdown of a Format I (double operand) instruction Machine Code: opcode (4 bits) is the operation code. The highest 12 values are used for Format I instructions, the remainder for jumps and Format II. S-Reg and D-Reg (4 bits each) specify the CPU registers associated with the source and destination; the registers either contain the operands themselves or their contents are used to form the addresses. As (2 bits) gives the mode of addressing for the source, which has four basic modes. Ad (1 bit) similarly gives mode of addressing for the destination, which has only two basic modes. B/W (1 bit) chooses whether the operand is a byte (1) or a word (0).

32 Machine Code The instruction can be broken into its fields of opcode = 4, The opcode of 4 represents a move S-reg = 5, The register is S-reg = 5, which is R5 as expected. Ad = 0, The addressing mode for the destination is Ad = 0, which is register. B/W = 0, The bit B/W = 0 shows that the operand is a word. As = 0, The addressing mode for the source is As =0. D-reg = 6. The register is D-reg = 6 = R6.

33 Machine Code The opcode is 5.


Download ppt "Architecture of the MSP430 Processor. Central Processing Unit Program Counter (PC) - Contains the address of the next instruction to be executed. The."

Similar presentations


Ads by Google