E91 (3) Assembly Language
E91 (3) Assembly Language
E91 (3) Assembly Language
Assembly Language
The basics
Anatomy of a simple program
Anything after “;” is comment Make PROGSTART available to linker.
PC, SP, SR, and R15
used in our program
Status Register
Recall Memory Addresses
P1IN : 0x20
P1OUT: 0x21
P1DIR: 0x22
DEMO…
Instruction Set
Dual Operand Instructions
Instruction Set
Single Operand Instructions
Instruction Set
Jumps
Note, there are 8 possible jump instructions. This will come up later.
Sources & Destinations
Addressing Modes Introduction (1)
What are some of the things we can use for sources and destinations?
The Source Operand
• “Immediate” – the value of the source operand is stored immediately after the
instruction (i.e., the source operand is a constant). The immediate value is
prefixed with “#” :
fi d i h “#”
0xF81C: 403F 123A MOV.W #0x123a,R15
• “Register” – the source operand is in a register:
0xF81E: 4F0E MOV.W R15,R14
• “Absolute” – the address of the source operand is stored immediately after the
instruction. The absolute value (address) is prefixed by “&”:
instruction. The absolute value (address) is prefixed by & :
0xF820: 425F 0020 MOV.B &P1IN,R15
• “Symbolic” , Similar to “Absolute” but uses offset from Program Counter.
• Also … “Indexed”, “Indirect Register”, “Indirect Autoincrement” … we’ll do these
next week.
Destinations
Addressing Modes Introduction (2)
The Destination Operand
• “Register” – the destination operand is in a register:
0xF81E: 4F0E MOV.W R15,R14
• “Absolute”
Absolute – the address of the destination operand is stored immediately after
the address of the destination operand is stored immediately after
the instruction:
0xF822: 40F2 00F3 0021 MOV.B #0x00f3,&P1OUT
• “Symbolic”
Symbolic , Similar to
Similar to “Absolute”
Absolute but uses offset from Program Counter.
but uses offset from Program Counter
• It makes no sense to have an “Immediate” mode for the destination (you can’t
change a constant value) – so this address mode isn’t available.
•Also … “Symbolic” , “Indexed”, are available for destination… we’ll do these next
week.
• “Indirect Register”, “Indirect Autoincrement” are not available for destination.
Addressing Mode Examples
Pertinent section of code
PROGSTART mov.w #0280h,SP ; Initialize stackpointer
mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
Code Detail
0xF80A: 4290 F83C 09F2 MOV.W &myWord,myWordVar1
mov.w &myWord, myWordVar1 0xF810: 4292 F83C 0200 MOV.W &myWord,&myWordVar1
mov w &myWord, &myWordVar1
mov.w 0xF816: 4292 F83C 0202 MOV.W
MOV W &myWord
&myWord,&myWordVar2
&myWordVar2
mov.w &myWord, &myWordVar2
0xF81C: 40F2 0033 0204 MOV.B #0x0033,&myByteVar1
mov.b #33h, &myByteVar1 0xF822: 40F2 0033 0205 MOV.B #0x0033,&myByteVar2
mov.b #33h, &myByteVar2 0xF828: 40F2 0033 0206 MOV.B #0x0033,&myByteVar3
mov.b #33h, &myByteVar3 0xF82E: 40F2 0033 0208 MOV.B #0x0033,&myByteVar4
y y
mov.b #33h, &myByteVar4
0xF834: 4090 0006 0002 MOV.W myWord,myBytes
mov.w myWord, myBytes
Ruh‐Roh!
; Define data in flash (after code)
myBytes
B t .byte
b t 05ah,
05 h 03ch
03 h myBytes:
B t
myWord .word 0f2h 0xF83A: 3C5A JMP (0xf8f0)
myWord:
0xF83C: 00F2 .word 0x00F2
Note: Some instructions are longer than others (these will be slower)
Let’s see how we get the machine code from the assembly language.
Aside (2): Machine Code
Let’s look at JNE
ASIDE (3): Machine Code
Things to know:
Opcode C OFFSET
0x23FE= 0 0 1 0 0 0 1 1 1 1 1 1 1 1 1 0
Offset = 11 1111 1110binary = ‐2decimal.
PCnew = PC
PCold + 2
2 + PC
PCoffsetx2
x2 = 0xf818
0xf818 + 2
2 + ((‐2)x2
2)x2
= 0xf818‐2 = 0xf816
What if we need to jump farther than allowed with a 10 bit offset?