Professional Documents
Culture Documents
Digital IO ports
Data flow
PxOUT
Pin
PxIN
Data flow
PxDIR
Vcc
PxREN
Terminologies
• Opcode
⋄ What the instruction does - verb.
⋄ May or may not require operands – objects.
• Source Operand
⋄ 1st data object manipulated by the instruction.
• Destination Operand
⋄ 2nd data object manipulated by the instruction.
⋄ Also where results of operation are stored.
• Addressing Modes
Instruction format
• There are three formats used to encode instructions for
processing by the CPU core
⋄ Double operand.
15 12 11 8 7 6 5 4 3 0
Op-code S-reg Ad b/w As D-reg
Example:
mov.w r5,r4
Op-code S-reg Ad b/w As D-reg
move r5 Register 16-bits Register r4
0100 0101 0 0 00 0100
Instruction format
⋄ Single operand.
15 6 5 4 3 0
Op-code b/w Ad D-reg
Example:
rrc.w r 5
Op-code b/w Ad D-reg
rrc 16-bits Register r5
00100000 0 00 0101
Instruction code = 0x1005
Instruction format
⋄ Jumps.
15 13 12 10 9 0
Op-code Condition 10-bit, 2's complement PC offset
Example:
rrc.w r 5
Op-code Condition 10-bit, 2's complement PC offset
JC Carry set -28
001 011 1111100100
Instruction code = 0x1005
Instruction format
• The instructions for double and single operands, depend on the
suffix used, (.W) word or (.B) byte. These suffixes allow word or
byte data access.
• If the suffix is ignored, the instruction processes word data by
default.
• The source and destination of the data operated by an instruction
are defined by the following fields:
⋄ src: source operand address, as defined in As and S-reg.
⋄ dst: destination operand address, as defined in Ad and D-reg.
⋄ As: addressing bits used to define the addressing mode used by
the source operand.
⋄ S-reg: register used by the source operand.
⋄ Ad: Addressing bits used to define the addressing mode used by
the destination operand.
⋄ D-reg: register used by the destination operand.
⋄ b/w: word or byte access definition bit. Microcomputer principles and applications
3.5 Instruction Set Architecture (ISA)
Assembler sections
• A section is a block of code or data that occupies contiguous
space in the memory map.
• Each section has its own Location Counter.
• The assembler assembles into the current section.
• There are two types of sections:
⋄ Initialized sections containing data or code (modal): .sect,
.text
⋄ Uninitialized sections reserving space in the memory map
for uninitialized data (temporary): .bss, .usect
Assembler sections
.bss var,2
RAM
.usect "mySection"
.text
ROM (Flash)
.sect "reset"
Location counter
• The Location Counter holds the relative memory position of an
instruction within the current section.
⋄ Each section has a location counter used to assign storage
addresses to your program’s statements.
⋄ As the instructions of a source module are being assembled,
the location counter keeps track of the current location in
storage.
⋄ A $ (dollar sign) can be used as an operand to an instruction
to refer to the current value of the location counter.
Location counter
• The assembler assembles into the current section.
⋄ An initialized section directive instructs the assembler to stop
assembling in the current section and begin assembling in
the indicated section.
⋄ An uninitialized section directive does not end the current
section, but simply escape from the current section
temporarily. (Thus uninitialized directives .bss and .usect
can appear anywhere in an initialized section without
affecting its contents.).
Assembly process
The assembler translates 1-to-1 assembly language instructions
(.asm) into the machine language of the ISA (.obj).
• 1st Pass: store all labels/constants and their corresponding
addresses/values in the symbol table
⋄ Zero all Location Counters ($).
⋄ For each non-empty line in the .text section:
1. if line contains a label, add label and current LC to the
symbol table
2. if line contains an instruction, increment the LC
accordingly
⋄ Stop when .end directive is found.
Assembly process
Assembly process
Linker
The Linker program "links" two files together according to their
declared sections.
Double operand
Mnemonic Operation Description
Arithmetic instructions
ADD(.B or .W) src,dst src+dst → dst Add source to desti-
nation
ADDC(.B or .W) src+dst+C → dst Add source and
src,dst carry to destination
DADD(.B or .W) src+dst+C → dst Decimal add source
src,dst (dec) and carry to destina-
tion
SUB(.B or .W) src,dst dst+.not.src+1 → dst Subtract source from
destination
SUBC(.B or .W) dst+.not.src+C → dst Subtract source and
src,dst carry from destina-
tion
Double operand
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 → Clear bits in destina-
dst tion
BIS(.B or .W) src,dst src.or.dst → dst OR (set) bits in desti-
nation
BIT(.B or .W) src,dst src.and.dst Test bits in destina-
tion
XOR(.B or .W) src,dst src.xor.dst → dst XOR source with
destination
Double operand
Mnemonic Operation Description
Data instructions
CMP(.B or .W) dst-src Compare source to
src,dst destination
MOV(.B or .W) src → dst Move source to des-
src,dst tination
Single operand
Single operand
Used to specify:
• Starting addresses for programs.
• Starting values for memory locations.
• Specify the end of program text.
Example
A1 A2 A3
a f b
11
10
12
9
8
7
a
b
c
d
e h
f
5
6
1
2
3
4
g
A1
e d h c g A2
A3 A4
A4
Programming structure
• Sequential.
• Conditional.
• Iterative.
Flowchart
Flow line
Direction of logic flow
if-then-else structure
switch/case structure
for-loop structure
while-loop structure