Instruction Set Architecture
� �
Recommended: See Links on Class Wiki�
Thanks to Mark Clement of
Brigham Young University for
most of this content.
Learning Objectives…
Learning Outcomes
After completing this section, you should be able to
ISA
2
Topics
Instruction Set Architecture
ISA
3
ISA
Harvard Architecture
ISA
4
Von Neumann vs. Harvard
DATA
MEMORY
INSTRUCTION
MEMORY
CLOCK
IN
OUT
Control
Status
Instruction
Control & Address
Data
ALU
CONTROL
Examples:
8051
Atmel AVR
ARM
The Von Neumann Computer
ISA
5
OUTPUT
* monitor
* printer
* LEDs
* D/A
* disk
INPUT
* keyboard
* mouse
* scanner
* A/D
* serial
* disk
MEMORY
Control
Von Neumann�proposed this model in 1946
The Von Neumann model:�Program instructions and Data are both stored as sequences�of bits in computer memory
Data Path
Address Bus
Data Bus
PROCESSING UNIT
Program Counter
Instruction Register
ALU
Registers
Clock
Control
Logic
Von Neumann vs. Harvard
Examples:
Cray
PC’s
MSP430
RISC / CISC Architecture
ISA
6
CISC
RISC
RISC vs. CISC
RISC/CISC Instruction Set
ISA
7
MSP430
(RISC)
IA-32 (CISC)
Logical
Arithmetic
Jump
Special
27 Instructions
RISC vs. CISC
MSP430 Architecture
ISA
8
Von Neumann
Instructions
and Data
Input / Output
RISC Processing
Unit (CPU)
Von Neumann
Bottleneck
Computer Instructions
Computer Instructions
ISA
10
Computer Instructions
Machine vs Assembly Code
ISA
11
Computer Instructions
Disassembler
0100000100111111
0000011000000000
0100000010110010
0100001100001110
0101001101011110
1111000001111110
0001001000110000
1000001110010001
0010001111111101
0100000000110001
0101101000011110
0000000100100000
0000000000001111
0000000000001110
0000000000000000
Machine Code
mov.w #0x0600,r1
mov.w #0x5a1e,&0x0120
mov.w #0,r14
add.b #1,r14
and.b #0x0f,r14
push #0x000e
sub.w #1,0(r1)
jne $-4
mov.w @r1+,r15
Assembly Code
Assembler
Anatomy of Machine Instruction
ISA
12
“Add the value in Register 4 to the value in Register 5”
Computer Instructions
2. 1st object – Source Operand
3. 2nd object – Destination Operand
1. Verb – Opcode (0, 1, or 2 operands)
0101010000000101
add r4,r5
How many
instructions are
possible with a
4-bit op-code?
How many
source/destination
registers can
selected with a
4-bit field?
Instruction Addressing Modes
ISA
13
Computer Instructions
MSP430 ISA
MSP430 Bus Architecture
ISA
15
memory locations (memory size)
MSP430 ISA
MSP430 Memory Architecture
ISA
16
(0x0000 - 0xFFFF) for most MSP430 (not F5529)
Flash (ROM)
RAM
I/O
0x0000
0xFFFF
MSP430 ISA
MSP430 Ports
ISA
17
MSP430 Ports
Quiz 3.1
1. What is an ISA?
2. What is a memory address space?
3. What is memory addressability?
4. What is a computer port?
5. List some distinctive properties of the MSP430 ISA.
ISA
18
Assembly Primer
MSP430 Assembler
ISA
20
start: | mov.w | #0x0280,sp | ; setup stack pointer |
Label: | Operation | Operands | Comment |
Assembler Primer
Assembler Coding Style
ISA
21
Assembler Primer
; blinky.asm: Software Toggle P1.0
;*************************************************************
.cdecls C,"msp430.h" ; MSP430 C header
DELAY .equ 0
.bss cnt,2 ; counter variable
.text ; begin code
reset: mov.w #0x0280,SP ; init stack ptr
mov.w #WDTPW+WDTHOLD,&WDTCTL ; stop WDT
bis.b #0x01,&P1DIR ; set P1.0 as output
mainloop: xor.b #0x01,&P1OUT ; toggle P1.0
mov.w #DELAY,cnt ; delay counter
delayloop: sub.w #1,cnt ; delay over?
jnz delayloop ; n
jmp mainloop ; y, repeat
.sect ".reset" ; RESET vector
.word reset ; start address
.end
Put start label here
Start executable code after .text directive
Put defines & variables here
MSP430 Instructions
MSP430 Instructions
ISA
23
Instruction Formats
MSP430 Instructions
ISA
24
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
Instruction Register
Memory | | |||||||||||||||
0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | |
0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | |
0 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | |
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | |
0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
mov.w r5,r4 |
rrc.w r5 |
jc main |
mov.w #0x0600,r1 |
Opcode | Instruction | Format |
0000 | Undefined | Single Operand |
0001 | RCC, SWPB, RRA, SXT, PUSH, CALL, RETI | |
0010 | JNE, JEQ, JNC, JC | Jumps |
0011 | JN, JGE, JL, JMP | |
0100 | MOV | Double Operand |
0101 | ADD | |
0110 | ADDC | |
0111 | SUBC | |
1000 | SUB | |
1001 | CMP | |
1010 | DADD | |
1011 | BIT | |
1100 | BIC | |
1101 | BIS | |
1110 | XOR | |
1111 | AND |
1111
1110
1101
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
0010
0001
0000
4 to 16 Decoder
Opcode
Program Counter
MSP430 Instructions
R0
1 cycle needed to
fetch instruction
MPS430 Instruction Formats
ISA
25
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
MSP430 Instructions
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Opcode (4 + 5 bits) | b/w | As | D/S-reg | ||||||||||||
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Opcode (4 + 2 bits) | 10-bit, 2’s complement PC offset | ||||||||||||||
Format I: Double Operand
ISA
26
Mnemonic | Operation | Description |
Arithmetic instructions | ||
ADD(.B or .W) src,dst | src+dst→dst | Add source to destination |
ADDC(.B or .W) src,dst | src+dst+C→dst | Add source and carry to destination |
DADD(.B or .W) src,dst | src+dst+C→dst (dec) | Decimal add source and carry to destination |
SUB(.B or .W) src,dst | dst+.not.src+1→dst | Subtract source from destination |
SUBC(.B or .W) src,dst | dst+.not.src+C→dst | Subtract source and not carry from destination |
Logical and register control instructions | ||
AND(.B or .W) src,dst | src.and.dst→dst | AND source with destination |
BIC(.B or .W) src,dst | .not.src.and.dst→dst | Clear bits in destination |
BIS(.B or .W) src,dst | src.or.dst→dst | Set bits in destination |
BIT(.B or .W) src,dst | src.and.dst | Test bits in destination |
XOR(.B or .W) src,dst | src.xor.dst→dst | XOR source with destination |
Data instructions | ||
CMP(.B or .W) src,dst | dst-src | Compare source to destination |
MOV(.B or .W) src,dst | src→dst | Move source to destination |
Double Operand Instructions
Format II: Single Operand
ISA
27
Mnemonic | Operation | Description | |
Logical and register control instructions | |||
RRA(.B or .W) dst | MSB→MSB→… LSB→C | Roll destination right | |
RRC(.B or .W) dst | C→MSB→…LSB→C | Roll destination right through carry | |
SWPB(.W) dst | Swap bytes | Swap bytes in destination | |
SXT(.W) dst | bit 7→bit 8…bit 15 | Sign extend destination | |
PUSH(.B or .W) src | SP-2→SP, src→@SP | Push source on stack | |
Program flow control instructions | |||
CALL dst | SP-2→SP, PC+2→@SP dst→PC | Subroutine call to destination | |
RETI | @SP+→SR, @SP+→SP | Return from interrupt | |
Single Operand Instructions
Format III: Jump Instruction
ISA
28
Jump Instructions
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Opcode + Condition | 10-bit, 2’s complement PC offset | ||||||||||||||
Quiz 3.2
ISA
29
MSP430 Addressing Modes
Addressing Modes
ISA
31
Addressing Modes
Register
Memory
Register
Register Indirect
Indirect Auto-increment
← +1,2
+
Indexed Register
Index
Addressing Modes (C, C++)
ISA
32
C, C++ | Addressing Mode | Assembly |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
char table[100]; cat = table[dog]; | Indexed Register | mov.b table(r4),r5 |
char* cow = table; cat = *cow; | Indirect Register | mov.b @r6,r5 |
cat = *cow++; | Indirect Auto-increment | mov.b @r6+,r5 |
cat = 100; | Immediate | mov.w #100,r5 |
cat = *100; | Absolute | mov.w &100,r5 |
cat = dog; | Symbolic | mov.w dog,r5 |
int dog, cat; cat = dog; | Register | mov.w r4,r5 |
Source Addressing Modes (As)
ISA
33
Addressing Modes
Destination Addressing Modes (Ad)
ISA
34
Addressing Modes
Instruction Length and Cycles
Instruction Length
ISA
36
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
Instruction Length
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Opcode | b/w | As | D/S-reg | ||||||||||||
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
Opcode | 10-bit, 2’s complement PC offset | ||||||||||||||
mov 10(r4),r5
mov cnt,r5
mov &P1IN,r5
(except constants -1, 0, 1, 2, 4, 8 which use S-reg = r2/r3)
mov #100,r5
mov r4,10(r5)
mov r4,cnt
mov r4,&P1OUT
Instruction Clock Cycles
ISA
37
MSP430 Clock Cycles
Quiz 3.3
ISA
38
Instruction | L | C | | Instruction | L | C |
add.w r5,r6 | | | | mov.w EDE,TONI | | |
add.w cnt(r5),r6 | | | | mov.b &MEM,&TCDAT | | |
add.w @r5,r6 | | | | mov.w @r10,r11 | | |
add.w @r5+,r6 | | | | mov.b @r10+,tab(r6) | | |
add.w cnt,r6 | | | | mov.w #45,TONI | | |
add.w &cnt,r6 | | | | mov.w #2,&MEM | | |
add.w #100,r6 | | | | mov.b #1,r11 | | |
mov.w r10,r11 | | | | mov.w #45,r11 | | |
mov.w @r5,6(r6) | | | | mov.b #-1,-1(r15) | | |
mov.w 0(r5),6(r6) | | | | mov.w @r10+,r10 | | |
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Instruction Operand Access
ISA
39
1 ;****************************************************
2 .cdecls C,"msp430.h" ; MSP430
3 000 .text
4
5 8000 540A reset: add.w r4,r10 ; r10 = r4 + r10
6 8002 541A add.w 6(r4),r10 ; r10 = M(r4+6) + r10
8004 0006
7 8006 542A add.w @r4,r10 ; r10 = M(r4) + r10
8 8008 543A add.w @r4+,r10 ; r10 = M(r4++) + r10
9 800a 501A add.w cnt,r10 ; r10 = M(cnt) + r10
800c 0012
10 800e 521A add.w &cnt,r10 ; r10 = M(cnt) + r10
8010 801E
11 8012 503A add.w #100,r10 ; r10 = 100 + r10
8014 0064
12 8016 531A add.w #1,r10 ; r10 = 1 + r10
13 8018 5090 add.w cnt,var ; var = M(cnt) + M(var)
801a 0004
801c 0004
14
15 801e 0000 cnt: .word 0
16 8020 0000 var: .word 0
Addressing Modes
Register
Indexed Register
Indirect Register
Indirect Auto-inc
Symbolic or PC relative
Absolute
Immediate
Constant
40
40
The Instruction Cycle
Not all instructions require all six phases
Instruction Cycle
00 = Register Mode
ISA
41
Memory
0x0000
0xFFFF
Addressing Modes
Registers
CPU
ADDER
add.w r4,r10 ;r10 = r4 + r10
PC
PC
R10
R4
IR
Data Bus (1 cycle)
0x540a
0x540a
PC
ALU
Address Bus
+2
opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 |
1 Cycle Instruction
01 = Indexed Mode
ISA
42
Memory
0x0000
0xFFFF
Addressing Modes
Registers
Address Bus
Data Bus (+1 cycle)
Data Bus (+1 cycle)
CPU
ADDER
add.w 6(r4),r10 ;r10 = M(r4+6) + r10
0x0006
PC
PC
PC
R10
R4
IR
Data Bus (1 cycle)
0x541a
0x541a
PC
ALU
Address Bus
+2
+2
opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
3 Cycle Instruction
10 = Indirect Register Mode
ISA
43
Memory
0x0000
0xFFFF
Addressing Modes
Registers
Address Bus
Data Bus (+1 cycle)
CPU
ADDER
add.w @r4,r10 ;r10 = M(r4) + r10
PC
PC
R10
R4
IR
Data Bus (1 cycle)
0x542a
Address Bus
0x542a
PC
ALU
+2
opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |
2 Cycle Instruction
ISA
44
Memory
0x0000
0xFFFF
Addressing Modes
Registers
Data Bus (+1 cycle)
CPU
ADDER
11 = Indirect Auto-increment Mode
add.w @r4+,r10 ;r10 = M(r4+) + r10
PC
PC
R10
R4
IR
Data Bus (1 cycle)
0x543a
Address Bus
PC
0x543a
Address Bus
0002
ALU
+2
opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 |
2 Cycle Instruction
Addressing Mode Variations
ISA
45
ISA
46
Memory
0x0000
0xFFFF
Addressing Modes
Registers
Address Bus
Data Bus (+1 cycle)
Data Bus (+1 cycle)
CPU
ADDER
01 w/R0 = Symbolic Mode (PC Relative)
cnt
add.w cnt,r10 ;r10 = M(cnt) + r10
0x000c
PC
PC
PC
PC
R10
IR
Data Bus (1 cycle)
0x501a
0x501a
PC
ALU
Address Bus
+2
+2
opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
3 Cycle Instruction
ISA
47
Memory
0x0000
0xFFFF
Addressing Modes
Registers
Address Bus
Data Bus (+1 cycle)
Data Bus (+1 cycle)
CPU
ADDER
cnt
01 w/R2 = Absolute Mode
0000
add.w &cnt,r10 ;r10 = M(cnt) + r10
0xc018
PC
PC
PC
R10
IR
Data Bus (1 cycle)
0x521a
0x521a
PC
ALU
Address Bus
+2
+2
opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
0 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
3 Cycle Instruction
ISA
48
Memory
0x0000
0xFFFF
Addressing Modes
Registers
CPU
ADDER
11 w/R0 = Immediate Mode
add.w #100,r10 ;r10 = 100 + r10
PC
PC
PC
R10
Data Bus (+1 cycle)
IR
Data Bus (1 cycle)
0x503a
PC
0x503a
0x0064
ALU
Address Bus
+2
+2
opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 |
2 Cycle Instruction
ISA
49
Memory
0x0000
0xFFFF
Addressing Modes
Registers
CPU
ADDER
Constant Generator
add.w #1,r10 ;r10 = #1 + r10
PC
PC
R10
0000
0001
0002
0004
0008
ffff
IR
Data Bus (1 cycle)
0x531a
Address Bus
PC
0x531a
ALU
+2
opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
1 Cycle Instruction
ISA
50
Memory
0x0000
0xFFFF
Addressing Modes
Registers
Address Bus
Data Bus (+1 cycle)
Data Bus (+1 cycle)
CPU
ADDER
Three Word Instruction
cnt
add.w cnt,var ;var = M(cnt) + M(var)
0x000c
PC
PC
PC
var
Address Bus
Data Bus (+1 cycle)
Data Bus (+1 cycle)
PC
Data Bus (+1 cycle)
0x0218
IR
Data Bus (1 cycle)
0x5090
0x5090
PC
PC
ALU
Address Bus
+2
+2
+2
opcode | S-reg | Ad | b/w | As | D-reg | ||||||||||
0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 |
6 Cycle Instruction
Processor Speed
ISA
51
Instruction Clock Cycles
MCLK = 2 MHz, CPI = 5, MIPS = 0.4
MCLK = 1 MHz, CPI = 2, MIPS = 0.5
Quiz 3.4
ISA
52
DELAY .equ
mov.w #DELAY,r12 ; 2 cycles
delay1: mov.w #1000,r15 ; 2 cycles
delay2: sub.w #1,r15 ; 1 cycle
jne delay2 ; 2 cycles
sub.w #1,r12 ; 1 cycle
jne delay1 ; 2 cycles
?
Disassembling Instructions
How to Disassemble MSP430 Code
1. Begin with a “PC” pointing to the first word in program memory.
2. Retrieve instruction word and increment PC by 2.
ISA
54
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
R0
How to Disassemble MSP430 Code
3. List the instruction mnemonic using the opcode (bits 12-15).
4. Append “.b” or “.w” using the b/w bit when appropriate (0=w, 1=b).
ISA
55
0100 0000 0011 0001
0100 0000 0011 0001
0100 0000 0 0 11 0001
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
.w
mov
How to Disassemble MSP430 Code
5. If double operand instruction, decode and list source operand. (If
necessary, fetch operand from memory and increment PC by 2.)
ISA
56
R0
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0 0 11 0001
.w
mov
0x0400
#
How to Disassemble MSP430 Code
6. If single or double operand instruction, decode and list destination
operand.
ISA
57
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0 0 11 0001
.w
mov
0x0400
#
,r1
How to Disassemble MSP430 Code
ISA
58
0100 0000 1011 0010
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
R0
…Retrieve instruction word, increment PC by 2, list mnemonic, and operand size.
0x0400
mov
.w
#
,r1
0100 0000 1 0 11 0010
mov
.w
How to Disassemble MSP430 Code
ISA
59
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
R0
0100 0000 1 0 11 0010
…Retrieve immediate source operand and increment PC by 2.
mov
.w
0x5a80
0x0400
mov
.w
#
,r1
#
How to Disassemble MSP430 Code
ISA
60
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
R0
0100 0000 1 0 11 0010
…Retrieve absolute destination operand and increment PC by 2.
mov
.w
0x120
0x5a80
#
0x0400
mov
.w
#
,r1
,&
How to Disassemble MSP430 Code
ISA
61
0100 0010 0111 1111
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
R0
0100 0000 1011 0010
…Retrieve instruction word, increment PC by 2, list mnemonic, and operand size.
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
0100 0010 0 1 11 1111
mov
.b
How to Disassemble MSP430 Code
ISA
62
0100 0010 0 1 11 1111
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
…Use constant generator R2 for source operand.
#8
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
mov
.b
How to Disassemble MSP430 Code
ISA
63
0100 0010 0 1 11 1111
mov
.b
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
…Use register mode for destination operand.
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
#8
,r15
How to Disassemble MSP430 Code
ISA
64
0001 0010 1011 0000
000100101 0 11 0000
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
R0
0100 0000 1011 0010
0100 0010 0111 1111
…Retrieve instruction word, increment PC by 2, list mnemonic, (but no operand size is used.)
call
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
mov
.b
#8
,r15
.w
How to Disassemble MSP430 Code
ISA
65
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
0100 0010 0111 1111
000100101 0 11 0000
…Retrieve immediate destination operand from memory and increment PC by 2.
call
0xc012
R0
R0
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
mov
.b
#8
,r15
#
.w
How to Disassemble MSP430 Code
ISA
66
.w
0011 1111 1111 1100
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
R0
0100 0000 1011 0010
0100 0010 0111 1111
…Retrieve instruction word, increment PC by 2, and list mnemonic.
call
#
0xc012
mov
.b
#8
,r15
0001 0010 1011 0000
001111 1111111100
jmp
How to Disassemble MSP430 Code
ISA
67
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
0100 0010 0111 1111
001111 1111111100
…Calculate destination address by sign extending the least significant 10 bits, multiplying by 2, and adding the current PC.
jmp
0xc00a
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
call
#
0xc012
mov
.b
#8
,r15
0001 0010 1011 0000
(-4 × 2) + 0xc012 = 0xc00a
.w
How to Disassemble MSP430 Code
ISA
68
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
0100 0010 0111 1111
1000 0011 0001 1111
…Retrieve instruction word, increment PC by 2, list mnemonic, and operand size.
0011 1111 1111 1100
jmp
0xc00a
R0
R0
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
call
#
0xc012
mov
.b
#8
,r15
0001 0010 1011 0000
1000 0011 0 0 01 1111
sub
.w
.w
How to Disassemble MSP430 Code
ISA
69
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
0100 0010 0111 1111
1000 0011 0001 1111
…Use constant generator R3 for immediate source operand.
0011 1111 1111 1100
jmp
0xc00a
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
call
#
0xc012
mov
.b
#8
,r15
0001 0010 1011 0000
1000 0011 0 0 01 1111
sub
.w
#1
.w
How to Disassemble MSP430 Code
ISA
70
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
0100 0010 0111 1111
1000 0011 0001 1111
…Use register mode for destination operand.
0011 1111 1111 1100
jmp
0xc00a
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
call
#
0xc012
mov
.b
#8
,r15
0001 0010 1011 0000
1000 0011 0 0 01 1111
sub
.w
,r15
#1
R0
.w
How to Disassemble MSP430 Code
ISA
71
.w
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
R0
0100 0000 1011 0010
0100 0010 0111 1111
1000 0011 0001 1111
0010 0011 1111 1110
…Retrieve instruction word, increment PC by 2, and list mnemonic.
jmp
0xc00a
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
call
#
0xc012
mov
.b
#8
,r15
0001 0010 1011 0000
0011 1111 1111 1100
sub
#1
,r15
.w
001000 1111111110
jne
How to Disassemble MSP430 Code
ISA
72
001000 1111111110
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
0100 0010 0111 1111
1000 0011 0001 1111
…Calculate destination address by sign extending the least significant 10 bits, multiplying by 2, and adding the current PC.
jmp
0xc00a
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
call
#
0xc012
mov
.b
#8
,r15
0001 0010 1011 0000
0011 1111 1111 1100
sub
#1
,r15
.w
jne
0xc012
(-2 × 2) + 0xc016 = 0xc012
.w
How to Disassemble MSP430 Code
ISA
73
0100 0001 0011 0000
0100 0001 0 0 11 0000
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
0100 0010 0111 1111
1000 0011 0001 1111
0010 0011 1111 1110
…Retrieve instruction word, increment PC by 2, and list mnemonic.
0001 0010 1011 0000
0011 1111 1111 1100
jmp
0xc00a
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
call
#
0xc012
mov
.b
#8
,r15
jne
sub
#1
,r15
.w
0xc012
mov
.w
R0
R0
.w
How to Disassemble MSP430 Code
ISA
74
0100 0001 0011 0000
0100 0001 0 0 11 0000
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
0100 0010 0111 1111
1000 0011 0001 1111
0010 0011 1111 1110
…Use indirect register auto-increment mode for source operand.
0001 0010 1011 0000
0011 1111 1111 1100
jmp
0xc00a
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
call
#
0xc012
mov
.b
#8
,r15
jne
sub
#1
,r15
.w
0xc012
mov
.w
@r1+
.w
How to Disassemble MSP430 Code
ISA
75
0100 0001 0011 0000
0100 0001 0 0 11 0000
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
0100 0010 0111 1111
1000 0011 0001 1111
0010 0011 1111 1110
…Use register mode for destination operand. (Pop the stack into the PC – “ret” instruction.)
0001 0010 1011 0000
0011 1111 1111 1100
jmp
0xc00a
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
call
#
0xc012
mov
.b
#8
,r15
jne
sub
#1
,r15
.w
0xc012
mov
.w
@r1+
,r0
.w
How to Disassemble MSP430 Code
ISA
76
0100 0001 0011 0000
R0
Instruction Disassembly
0xc000: 4031
0xc002: 0400
0xc004: 40b2
0xc006: 5a80
0xc008: 0120
0xc00a: 427f
0xc00c: 12b0
0xc00e: c012
0xc010: 3ffc
0xc012: 831f
0xc014: 23fe
0xc016: 4130
0100 0000 0011 0001
0100 0000 1011 0010
0100 0010 0111 1111
1000 0011 0001 1111
0010 0011 1111 1110
…Continue the disassembly process.
0001 0010 1011 0000
0011 1111 1111 1100
jmp
0xc00a
mov
.w
0x5a80
#
,&
0x120
0x0400
mov
.w
#
,r1
call
#
0xc012
mov
.b
#8
,r15
jne
sub
#1
,r15
.w
0xc012
mov
.w
@r1+
,r0
.w
(ret)
How to Disassemble MSP430 Code
ISA
77
Review
Quiz 3.5
ISA
78
Address Data
0x8010: 4031
0x8012: 0600
0x8014: 40B2
0x8016: 5A1E
0x8018: 0120
0x801a: 430E
0x801c: 535E
0x801e: F07E
0x8020: 000F
0x8022: 1230
0x8024: 000E
0x8026: 8391
0x8028: 0000
0x802a: 23FD
0x802c: 413F
0x802e: 3FF6
ISA
79