Académique Documents
Professionnel Documents
Culture Documents
EE3376
Adapted
Topics to Cover
l
l
l
l
l
l
l
l
MSP430 ISA
MSP430 Registers, ALU, Memory
Instruction Formats
Addressing Modes
Double Operand Instructions
Single Operand Instructions
Jump Instructions
Emulated Instructions
http://en.wikipedia.org/wiki/TI_MSP430
Adapted
Levels of Transformation
Problems
Algorithms
C
Instructions
Assembly
MSP
Language
430 ISA
Language
Machine
(Program)
(ISA) Architecture
Microarchitecture
Programmable
Computer
Specific
Manufacturer
Specific
Circuits
Devices
Adapted
memory organization
l address space -- how may locations can be addressed?
l addressibility -- how many bits per location?
register set (a place to store a collection of bits)
l how many? what size? how are they used?
instruction set
l Opcodes (operation selection codes)
l data types (data types: byte or word)
l addressing modes (coding schemes to access data)
l
l
MSP430 Registers
l
MSP430 Registers
l
Adapted
MSP430 Registers
l
Adapted
SCG1
SCG0
10
GIE
11
As
Constant
Remarks
R2
00
Register mode
R2
(0)
R2
01
10
00004h
Absolute mode
+4, bit processing
R2
11
00008h
R3
00000h
R3
00
01
00001h
0, word processing
+1
R3
10
00002h
R3
11
0FFFFh
MSP430 Registers
l
12
Adapted
MSP430 ALU
l
13
Adapted
MSP430 Memory
14
Adapted
Anatomy of an Instruction
l
Opcode
Source Operand
15
Destination Operand
Addressing Modes
Adapted
Instruction Format
l
l
l
16
Double operand
Single operand
Jumps
Instruction Format
l
17
15
14
13
12
11
10
Op-code
S-reg
Ad
b/w
14
13
12
11
10
Op-code
As
D-reg
b/w
Ad
D/S-reg
14
Op-code
18
15
13
12
11
10
Condition
Adapted
3 Instruction Formats
19
Adapted
20
Adapted
21
Adapted
Jump Instructions
22
Adapted
23
Rs - Register
x(Rs) - Indexed Register
@Rs - Register Indirect
@Rs+ - Indirect Auto-increment
24
Rd - Register
x(Rd) - Indexed Register
Adapted
l
l
l
0
25
Op-code
S-reg
Ad
b/w
As
D-reg
Adapted
mov.b 3(r5),r6
l
l
l
0
26
Op-code
S-reg
Ad
b/w
As
D-reg
Adapted
l
l
Op-code
27
; move word
; M(Cnt+PC) to r6
S-reg
Ad
b/w
1
As
D-reg
Adapted
mov.w &Cnt,r6
l
l
l
28
; move word
; M(Cnt) to r6
Op-code
S-reg
Ad
b/w
As
D-reg
Adapted
mov.w @r5,r6
l
l
l
0
29
; move word
; M(r5) to r6
Op-code
S-reg
Ad
b/w
As
D-reg
Adapted
Example:
mov.w @r5+,r6
l
l
l
30
; move word
; M(r5) to r6
; increment r5 by 2
Op-code
S-reg
Ad
b/w
As
D-reg
Adapted
31
Op-code
S-reg
Ad
b/w
As
D-reg
Adapted
Constant Generators
l
32
Adapted
Addressing Summary
33
Adapted
Addressing Modes
34
Adapted
Mnemonic
Operation
Description
src+dstdst
src+dst+Cdst
src+dst+Cdst (dec)
dst+.not.src+1dst
dst+.not.src+Cdst
Arithmetic instructions
src.and.dstdst
.not.src.and.dstdst
src.or.dstdst
src.and.dst
src.xor.dstdst
dst-src
srcdst
Data instructions
35
Adapted
l
l
Assembly:
mov.w r5,r4
Instruction code: 0x4504
Op-code
mov
S-reg
r5
Ad
Register
b/w
16-bits
As
Register
D-reg
r4
0100
0101
00
0100
36
Adapted
Assembly:
mov.w r5,TONI
Instruction code: 0x4580
Op-code
mov
S-reg
r5
Ad
Symbolic
b/w
16-bits
As
Register
D-reg
PC
0100
0101
00
0000
37
Assembly:
mov.b EDEN,TONI
Instruction code: 0x40d0
Op-code
mov
0100
l
l
38
S-reg
PC
Ad
Symbolic
b/w
8-bits
As
Symbolic
0000
1
1
01
2s complement PC-relative source index
2s complement PC-relative destination index
D-reg
PC
0000
Mnemonic
Operation
Description
MSBMSB
LSBC
CMSBLSBC
Swap bytes
SXT dst
39
@SP+SR, @SP+SP
l
l
40
Assembly:
rrc.w r5
Instruction code: 0x1005
Op-code
rrc
b/w
16-bits
Ad
Register
D-reg
r5
000100000
00
0101
Assembly:
rra.b &P2OUT
Instruction code: 0x1152
Op-code
rra
b/w
8-bits
Ad
Indexed
D-reg
r2
000100010
01
0010
41
14
Op-code
l
l
12
11
10
Condition
42
13
Jump
Instructions
43
l
l
44
Assembly:
jc main
Instruction code: 0x2fe4
Op-code
JC
Condition
Carry Set
001
011
1111100100
Emulated Instructions
l
l
l
l
l
45
Emulated Instructions
Mnemonic
Operation
Emulation
Description
Arithmetic instructions
46
dst+Cdst
dst-1dst
Decrement destination
dst-2dst
dst+1dst
Increment destination
dst+2dst
dst+0FFFFh+Cdst
dst+0FFhdst
Adapted
Emulated Instructions
Mnemonic
Operation
Emulation
Description
.NOT.dstdst
XOR(.B or .W)
#0(FF)FFh,dst
CMSBMSB-1
LSB+1LSB0
CMSBMSB-1
LSB+1LSBC
BR dst
dstPC
MOV dst,PC
Branch to destination
DINT
0GIE
BIC #8,SR
EINT
1GIE
BIS #8,SR
NOP
None
MOV #0,R3
No operation
RET
@SPPC
SP+2SP
MOV @SP+,PC
47
Adapted
Emulated Instructions
Mnemonic
Operation
Emulation
Description
0dst
Clear destination
CLRC
0C
BIC #1,SR
CLRN
0N
BIC #4,SR
CLRZ
0Z
BIC #2,SR
@SPtemp
SP+2SP
tempdst
SETC
1C
BIS #1,SR
SETN
1N
BIS #4,SR
SETZ
1Z
BIS #2,SR
dst + 0FFFFh + 1
dst + 0FFh + 1
Test destination
Data instructions
48
Adapted
Op-code
mov
S-reg
r3
Ad
Register
b/w
16-bits
As
Register
D-reg
r5
0100
0011
00
0101
49
Op-code
add
S-reg
r3
Ad
Register
b/w
16-bits
As
Indexed
D-reg
r5
0101
0011
01
0101
50
Op-code
sub
S-reg
r3
Ad
Register
b/w
16-bits
As
Indexed
D-reg
r5
1000
0011
01
0101
51
Op-code
sub
S-reg
r3
1000
0011
52
b/w
16-bits
0
As
Indirect
D-reg
r5
10
0101
Op-code
mov
S-reg
r3
Ad
Register
b/w
16-bits
As
Register
D-reg
r5
0100
0011
00
0011
53
Emulated
Instructions
Op-code
addc
S-reg
r3
Ad
Register
b/w
16-bits
As
Register
D-reg
r5
0110
0011
00
0101
54
Location
0x8000:
0x8004:
0x800a:
0x8010:
0x8012:
0x8016:
0x8018:
0x801c:
0x8020:
0x8022:
0x8026:
0x8028:
0x802a:
55
0x802c:
Machine
code
instruction
4031
40B2
D0F2
430E
Mainloop:!
4EC2
531E
F03E
Wait:!
401F
120F
L1:!
8391
23FD
413F
3FF3
Delay:!
0002
Machine
code
information
Assembly
code
0300
5A80 0120
000F 0022
MOV.W
MOV.W
BIS.B
CLR.W
#0x0300,SP!
#0x5a80,&Watchdog_Timer_WDTCTL!
#0x000f,&Port_1_2_P1DIR!
R14!
0021
MOV.B
INC.W
AND.W
R14,&Port_1_2_P1OUT!
R14!
#0x000f,R14!
000E
MOV.W
PUSH
Delay,R15!
R15!
0000
DEC.W
JNE
POP.W
JMP
0x0000(SP)!
(L1)!
R15!
(Mainloop)!
.word
0x0002!
000F
Adapted
Require
Require
!
0x8000:
!4031
!
0x8002:
!0300!
Memory
!
0x8004:
!40B2
Location
!
0x8006:
!5A80 !
0x8008: !0120!
!
0x800a:
!D0F2
# for immediate
!
0x800c:
!000F !
value
!
0x800e:
!0022
!
0x8010:
!430E
Mainloop:0x8012:
!4EC2
!
0x8014:
!0021!
& for absolute
!
0x8016:
!531E
address
0x8018: !F03E
0x801a: !000F!
Symbo
Wait:
!0x801c: !401F
l
!
0x801e:
!000E!
Index
!
0x8020:
!120F
value
L1:
!0x8022: !8391
!
0x8024:
!0000!
Label
!
0x8026:
!23FD
!
0x8028:
!413F
!
0x802a:
!3FF3
Delay:
!0x802c: !0002
56
!MOV.W
#0x0300,SP!
!MOV.W
#0x5a80,&Watchdog_Timer_WDTCTL
!BIS.B
#0x000f,&Port_1_2_P1DIR
!
!CLR.W
!MOV.B
R14!
R14,&Port_1_2_P1OUT!
!INC.W
!AND.W
R14!
#0x000f,R14
!MOV.W
Delay,R15
!PUSH
!DEC.W
R15!
0x0000(SP) !
Require
!JNE
L1!
!POP.W
R15!
!JMP
Mainloop!
.word
0x0002!
!
!
1 extra word to
store the immediate value
0x000F
Require
1 extra word to
store the symbolic info to get
Delay
Require 1 extra word to
store the index value
0x0000
Adapted
57
!
0x8000:
!4031
!
0x8002:
!0300!
!
0x8004:
!40B2
!
0x8006:
!5A80 !
0x8008: !0120!
!
0x800a:
!D0F2
!
0x800c:
!000F !
!
0x800e:
!0022
!
0x8010:
!430E
Mainloop:0x8012:
!4EC2
!
0x8014:
!0021!
!
0x8016:
!531E
0x8018: !F03E
0x801a: !000F!
Wait:
!0x801c: !401F
!
0x801e:
!000E
0x000E !
!
0x8020:
!120F
L1:
!0x8022: !8391
!
0x8024:
!0000!
!
0x8026:
!23FD
!
0x8028:
!413F
!
0x802a:
!3FF3
Delay:
!0x802c: !0002
!MOV.W
#0x0300,SP!
!MOV.W
#0x5a80,&Watchdog_Timer_WDTCTL
!
0x8028-0x8022=0x0006
!BIS.B
jump -6 bytes or -3
words)!
#0x000f,&Port_1_2_P1DIR J!NE 0000 0011 1111 1101
!
!CLR.W
!MOV.B
R14!
R14,&Port_1_2_P1OUT!
!INC.W
!AND.W
R14!
#0x000f,R14
!MOV.W
!
Delay,R15
!
N
!
!ew PC
!PUSH
!DEC.W
R15!
0x0000(SP)N!ew PC
value
PC value
value
!JNE
L1!
!POP.W
R15!
!JMP
Mainloop
.word
0x0002!
New
! (14) 0x802c-0x801e =
0x802c-0x8012=0x001a
!
0x8002:
!0300!
!
0x8004:
!
!
0x8006:
!5A80!
0x8008: !0120 !
!
0x800a:
!
!
0x800c:
!000F!
!
0x800e:
!0022!
!
0x8010:
!
Mainloop:0x8012:
!
!
0x8014:
!0021 !
!
0x8016:
!
0x8018: !
0x801a: !000F!
Wait:
!0x801c: !
!
0x801e:
!000E!
!
0x8020:
!
L1:
!0x8022: !
!
0x8024:
!0000!
!
0x8026:
!
!
0x8028:
!
!
0x802a:
!
Delay:
!0x802c: !0002
58
MOV.W
#0x0300,SP!
!MOV.W
#0x5a80,&Watchdog_Timer_WDTCTL
!BIS.B
#0x000f,&Port_1_2_P1DIR
!
!
!
!
!CLR.W
!MOV.B
R14!
R14,&Port_1_2_P1OUT!
!
!
!
!
!INC.W
!AND.W
R14!
#0x000f,R14
!MOV.W
Delay,R15
!
!
!
!
!PUSH
!DEC.W
R15!
0x0000(SP) !
!
!
!
!
!
!
!
!
!JNE
!POP.W
!JMP
!.word
L1!
R15!
Mainloop!
0x0002!
!
!
Adapted
!
0x8002:
!0300 0000 0011 0000 0000!
!
0x8004:
!40B2 0100 0000 1011 0010
#0x5a80,&Watchdog_Timer_WDTCTL
!
!
0x8006:
!5A80 0101 1010 1000 0000!
0x8008: !0120 0000 0001 0010 0000!
!
0x800a:
!D0F2 1101 0000 1111 0010
!
0x800c:
!000F 0000 0000 0000 1111!
!
0x800e:
!0022 0000 0000 0010 0010
!
0x8010:
!430E 0100 0011 0000 1110
Mainloop:0x8012:
!4EC2 0100 1110 1100 0010
!
0x8014:
!0021 0000 0000 0010 0001!
!
0x8016:
!531E 0101 0011 0001 1110
0x8018: !F03E 1111 0000 0011 1110
0x801a: !000F 0000 0000 0000 1111!
Wait:
!0x801c: !401F 0100 0000 0001 1111
!
0x801e:
!000E 0000 0000 0000 1110!
!
0x8020:
!120F 0001 0010 0000 1111
L1:
!0x8022: !8391 1000 0011 1001 0001
!
0x8024:
!0000 0000 0000 0000 0000!
!
0x8026:
!23FD 0010 0011 1111 1101
!
0x8028:
!413F 0100 0001 0011 1111
!
0x802a:
!3FF3 0011 1111 1111 0011
Delay:
!0x802c: !0002 0000 0000 0000 0010
59
!
0x8000:
MOV.W
#0x0300,SP!
!MOV.W
!BIS.B
#0x000f,&Port_1_2_P1DIR
!CLR.W
!MOV.B
R14
;(MOV.W #0X0000, R14)!
R14, &Port_1_2_P1OUT!
!INC.W
!AND.W
R14
;(ADD.W #0X01, R14)!
#0x000f,R14
!
!MOV.W
Delay,R15
!PUSH
!DEC.W
R15!
0(SP) ;(SUB.W #0X01, 0(SP)
!JNE
L1!
!POP.W
R15
;(MOV.W @SP+, R15)!
!JMP
Mainloop!
.word
0x0002!
Adapted
Practice:
l
60
0x802e:
Data
4031 0100 0000 0011 0001
0600
40B2 0100 0000 1011 0010
5A1E
0120
430E 0100 0011 0000 1110
535E 0101 0011 0101 1110
F07E 1111 0000 0111 1110
000F
1230 0001 0010 0011 0000
000E
8391 1000 0011 1001 0001
0000
23FD 0010 0011 1111 1101
413F 0100 0001 0011 1111
3FF6 0011 1111 1111 0110
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
0x8026 (0x802C-3x2)
mov.w @r1+,r15 (pop.w r15
jmp
0x801c (0x8030-2x10)
Adapted