Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications,
enhancements, improvements, and other changes to its products and services at any time and to discontinue
any product or service without notice. Customers should obtain the latest relevant information before placing
orders and should verify that such information is current and complete. All products are sold subject to TI’s terms
and conditions of sale supplied at the time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of sale in
accordance with TI’s standard warranty. Testing and other quality control techniques are used to the extent TI
deems necessary to support this warranty. Except where mandated by government requirements, testing of all
parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are responsible for
their products and applications using TI components. To minimize the risks associated with customer products
and applications, customers should provide adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right,
copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process
in which TI products or services are used. Information published by TI regarding third-party products or services
does not constitute a license from TI to use such products or services or a warranty or endorsement thereof.
Use of such information may require a license from a third party under the patents or other intellectual property
of the third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of information in TI data books or data sheets is permissible only if reproduction is without
alteration and is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction
of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for
such altered documentation.
Resale of TI products or services with statements different from or beyond the parameters stated by TI for that
product or service voids all express and any implied warranties for the associated TI product or service and
is an unfair and deceptive business practice. TI is not responsible or liable for any such statements.
Following are URLs where you can obtain information on other Texas Instruments products and application
solutions:
ProductsApplications
Amplifiersamplifier.ti.comAudiowww.ti.com/audio
Data Convertersdataconverter.ti.comAutomotivewww.ti.com/automotive
This manual discusses modules and peripherals of the MSP430x1xx family of
devices. Each discussion presents the module or peripheral in a general
sense. Not all features and functions of all modules or peripherals are present
on all devices. In addition, modules or peripherals may differ in their exact
implementation between device families, or may not be fully implemented on
an individual device or device family.
Pin functions, internal signal connections and operational paramenters differ
from device-to-device. The user should consult the device-specific datasheet
for these details.
Related Documentation From Texas Instruments
For related documentation see the web site http://www.ti.com/msp430.
FCC Warning
This equipment is intended for use in a laboratory test environment only. It generates, uses, and can radiate radio frequency energy and has not been tested
for compliance with the limits of computing devices pursuant to subpart J of
part 15 of FCC rules, which are designed to provide reasonable protection
against radio frequency interference. Operation of this equipment in other environments may cause interference with radio communications, in which case
the user at his own expense will be required to take whatever measures may
be required to correct this interference.
Notational Conventions
Program examples, are shown in a special typeface.
iii
Glossary
Glossary
ACLKAuxiliary ClockSee Basic Clock Module
ADCAnalog-to-Digital Converter
BORBrown-Out ResetSee System Resets, Interrupts, and Operating Modes
BSLBootstrap LoaderSee www.ti.com/msp430 for application reports
CPUCentral Processing UnitSee RISC 16-Bit CPU
DACDigital-to-Analog Converter
DCODigitally Controlled OscillatorSee Basic Clock Module
dstDestinationSee RISC 16-Bit CPU
FLLFrequency Locked LoopSee FLL+ in MSP430x4xx Family User’s Guide
GIEGeneral Interrupt EnableSee System Resets Interrupts and Operating Modes
INT(N/2)Integer portion of N/2
I/OInput/OutputSee Digital I/O
ISRInterrupt Service Routine
LSBLeast-Significant Bit
LSDLeast-Significant Digit
LPMLow-Power ModeSee System Resets Interrupts and Operating Modes
MABMemory Address Bus
MCLKMaster ClockSee Basic Clock Module
MDBMemory Data Bus
MSBMost-Significant Bit
MSDMost-Significant Digit
NMI(Non)-Maskable InterruptSee System Resets Interrupts and Operating Modes
PCProgram CounterSee RISC 16-Bit CPU
PORPower-On ResetSee System Resets Interrupts and Operating Modes
PUCPower-Up ClearSee System Resets Interrupts and Operating Modes
RAMRandom Access Memory
SCGSystem Clock GeneratorSee System Resets Interrupts and Operating Modes
SFRSpecial Function Register
SMCLKSub-System Master ClockSee Basic Clock Module
SPStack PointerSee RISC 16-Bit CPU
SRStatus RegisterSee RISC 16-Bit CPU
srcSourceSee RISC 16-Bit CPU
TOSTop-of-StackSee RISC 16-Bit CPU
WDTWatchdog TimerSee Watchdog Timer
iv
Register Bit Conventions
Each register is shown with a key indicating the accessibility of the each
individual bit, and the initial condition:
Register Bit Accessibility and Initial Condition
KeyBit Accessibility
rwRead/write
rRead only
r0Read as 0
r1Read as 1
wWrite only
w0Write as 0
w1Write as 1
(w)No register bit implemented; writing a 1 results in a pulse.
The MSP430 incorporates a 16-bit RISC CPU, peripherals, and a flexible clock
system that interconnect using a von-Neumann common memory address
bus (MAB) and memory data bus (MDB). Partnering a modern CPU with
modular memory-mapped analog and digital peripherals, the MSP430 offers
solutions for demanding mixed-signal applications.
Key features of the MSP430x1xx family include:
- Ultralow-power architecture extends battery life
J0.1-µA RAM retention
J0.8-µA real-time clock mode
J250-µA / MIPS active
- High-performance analog ideal for precision measurement
J12-bit or 10-bit ADC — 200 ksps, temperature sensor, V
12-bit dual-DAC
J
JComparator-gated timers for measuring resistive elements
JSupply voltage supervisor
- 16-bit RISC CPU enables new applications at a fraction of the code size.
JLarge register file eliminates working file bottleneck
JCompact core design reduces power consumption and cost
JOptimized for modern high-level programming
JOnly 27 core instructions and seven addressing modes
JExtensive vectored-interrupt capability
- In-system programmable Flash permits flexible code changes, field
upgrades and data logging
1.2Flexible Clock System
The clock system is designed specifically for battery-powered applications. A
low-frequency auxiliary clock (ACLK) is driven directly from a common 32-kHz
watch crystal. The ACLK can be used for a background real-time clock self
wake-up function. An integrated high-speed digitally controlled oscillator
(DCO) can source the master clock (MCLK) used by the CPU and high-speed
peripherals. By design, the DCO is active and stable in less than 6 µs.
MSP430-based solutions effectively use the high-performance 16-bit RISC
CPU in very short bursts.
- High-speed master clock = High performance signal processing
Introduction
Figure 1−1.MSP430 Architecture
Embedded Emulation
MCLK
ACLK
SMCLK
ACLK
SMCLK
Flash/
ROM
MAB 16-Bit
JTAG/Debug
MDB 16-Bit
Watchdog
Clock
System
RISC CPU
16-Bit
JTAG
1.3Embedded Emulation
Dedicated embedded emulation logic resides on the device itself and is
accessed via JTAG using no additional system resources.
The benefits of embedded emulation include:
RAM
Peripheral
PeripheralPeripheralPeripheral
Bus
Conv.
Peripheral
MDB 8-Bit
PeripheralPeripheral
- Unobtrusive development and debug with full-speed execution,
breakpoints, and single-steps in an application are supported.
- Development is in-system subject to the same characteristics as the final
application.
- Mixed-signal integrity is preserved and not subject to cabling interference.
Introduction
1-3
Address Space
1.4Address Space
The MSP430 von-Neumann architecture has one address space shared with
special function registers (SFRs), peripherals, RAM, and Flash/ROM memory
as shown in Figure 1−2. See the device-specific data sheets for specific
memory maps. Code access are always performed on even addresses. Data
can be accessed as bytes or words.
The addressable memory space is 64 KB with future expansion planned.
Figure 1−2.Memory Map
Access
0FFFFh
0FFE0h
0FFDFh
0200h
01FFh
0100h
0FFh
010h
1.4.1Flash/ROM
Word/Byte
Word/Byte
Word/Byte
Word
Byte
Byte
0Fh
0h
Interrupt Vector Table
Flash/ROM
RAM
16-Bit Peripheral Modules
8-Bit Peripheral Modules
Special Function Registers
The start address of Flash/ROM depends on the amount of Flash/ROM
present and varies by device. The end address for Flash/ROM is 0FFFFh.
Flash can be used for both code and data. Word or byte tables can be stored
and used in Flash/ROM without the need to copy the tables to RAM before
using them.
1.4.2RAM
1-4
Introduction
The interrupt vector table is mapped into the upper 16 words of Flash/ROM
address space, with the highest priority interrupt vector at the highest
Flash/ROM word address (0FFFEh).
RAM starts at 0200h. The end address of RAM depends on the amount of RAM
present and varies by device. RAM can be used for both code and data.
1.4.3Peripheral Modules
Peripheral modules are mapped into the address space. The address space
from 0100 to 01FFh is reserved for 16-bit peripheral modules. These modules
should be accessed with word instructions. If byte instructions are used, only
even addresses are permissible, and the high byte of the result is always 0.
The address space from 010h to 0FFh is reserved for 8-bit peripheral modules.
These modules should be accessed with byte instructions. Read access of
byte modules using word instructions results in unpredictable data in the high
byte. If word data is written to a byte module only the low byte is written into
the peripheral register, ignoring the high byte.
1.4.4Special Function Registers (SFRs)
Some peripheral functions are configured in the SFRs. The SFRs are located
in the lower 16 bytes of the address space, and are organized by byte. SFRs
must be accessed using byte instructions only. See the device-specific data
sheets for applicable SFR bits.
1.4.5Memory Organization
Address Space
Bytes are located at even or odd addresses. Words are only located at even
addresses as shown in Figure 1−3. When using word instructions, only even
addresses may be used. The low byte of a word is always an even address.
The high byte is at the next odd address. For example, if a data word is located
at address xxx4h, then the low byte of that data word is located at address
xxx4h, and the high byte of that word is located at address xxx5h.
Figure 1−3.Bits, Bytes, and Words in a Byte-Organized Memory
xxxAh
157146. . Bits . .
. . Bits . .9180
Byte
Byte
Word (High Byte)
Word (Low Byte)
xxx9h
xxx8h
xxx7h
xxx6h
xxx5h
xxx4h
xxx3h
Introduction
1-5
Chapter 2
This chapter describes the MSP430x1xx system resets, interrupts, and
operating modes.
The system reset circuitry shown in Figure 2−1 sources both a power-on reset
(POR) and a power-up clear (PUC) signal. Different events trigger these reset
signals and different initial conditions exist depending on which signal was
generated.
Figure 2−1.Power-On Reset and Power-Up Clear Schematic
V
V
CC
V
CC
CC
V
CC
Brownout
‡
Reset
0 V
0 V
EQU
KEYV
§
†
†
†
†
†
SVS_POR
RST/NMI
WDTNMI
WDTSSEL
WDTQn
WDTIFG
(from flash module)
† From watchdog timer peripheral module
‡ Devices with BOR only
# Devices without BOR only
§ Devices with SVS only
POR
POR
Detect
Detect
0 V
0 V
#
~ 50us
A POR is a device reset. A POR is only generated by the following three
events:
POR
Delay
0 V
#
Resetwd1
Resetwd2
S
S
R
S
S
S
S
S
R
POR
Latch
Delay
PUC
Latch
MCLK
POR
PUC
2-2
- Powering up the device
- A low signal on the RST/NMI pin when configured in the reset mode
- An SVS low condition when PORON = 1.
A PUC is always generated when a POR is generated, but a POR is not
generated by a PUC. The following events trigger a PUC:
- A POR signal
- Watchdog timer expiration when in watchdog mode only
- Watchdog timer security key violation
- A Flash memory security key violation
System Resets, Interrupts, and Operating Modes
2.1.1Power-On Reset (POR)
When the VCC rise time is slow, the POR detector holds the POR signal active
until VCC has risen above the V
supply provides a fast rise time the POR delay, t
V
CC
active time on the POR signal to allow the MSP430 to initialize.
On devices with no brownout-reset circuit, If power to the MSP430 is cycled,
the supply voltage V
when VCC is powered up again. If VCC does not fall below V
or a glitch, a POR may not be generated and power-up conditions may not be
set correctly. In this case, a low level on RST
a full power-cycle will be required. See device-specific datasheet for
parameters.
Figure 2−2.POR Timing
POR
must fall below V
CC
System Reset and Initialization
level, as shown in Figure 2−2. When the
(POR_DELAY)
to ensure that a POR signal occurs
min
min
, provides
during a cycle
/NMI may not cause a POR and
V
V
CC(min)
V
POR
V
min
Set Signal for
POR circuitry
V
CC
t
(POR_DELAY)
PORPOR
No POR
t
(POR_DELAY)
System Resets, Interrupts, and Operating Modes
2-3
System Reset and Initialization
2.1.2Brownout Reset (BOR)
Some devices have a brownout reset circuit (see device-specific datasheet)
that replaces the POR detect and POR delay circuits. The brownout reset
circuit detects low supply voltages such as when a supply voltage is applied
to or removed from the V
device by triggering a POR signal when power is applied or removed. The
operating levels are shown in Figure 2−3.
terminal. The brownout reset circuit resets the
CC
The POR signal becomes active when V
remains active until V
elapses. The delay t
hysteresis V
V
(B_IT−)
Figure 2−3.Brownout Timing
V
V
(B_IT+)
V
(B_IT−)
V
CC(start)
Set Signal for
POR circuitry
hys(B_IT−)
level. It
(BOR)
The
CC.
CC
(BOR)
hys(B_ IT−)
crosses the V
crosses the V
CC
(B_IT+)
threshold and the delay t
CC(start)
is adaptive being longer for a slow ramping V
ensures that the supply voltage must drop below
to generate another POR signal from the brownout reset circuitry.
V
CC
2-4
t
(BOR)
As the V
level is significantly above the V
(B_IT−)
BOR provides a reset for power failures where V
See device-specific datasheet for parameters.
System Resets, Interrupts, and Operating Modes
level of the POR circuit, the
min
does not fall below V
CC
min.
2.1.3Device Initial Conditions After System Reset
After a POR, the initial MSP430 conditions are:
- The RST/NMI pin is configured in the reset mode.
- I/O pins are switched to input mode as described in the Digital I/O chapter.
- Other peripheral modules and registers are initialized as described in their
respective chapters in this manual.
- Status register (SR) is reset.
- The watchdog timer powers up active in watchdog mode.
- Program counter (PC) is loaded with address contained at reset vector
location (0FFFEh). CPU execution begins at that address.
Software Initialization
After a system reset, user software must initialize the MSP430 for the
application requirements. The following must occur:
System Reset and Initialization
- Initialize the SP, typically to the top of RAM.
- Initialize the watchdog to the requirements of the application.
- Configure peripheral modules to the requirements of the application.
Additionally, the watchdog timer, oscillator fault, and flash memory flags can
be evaluated to determine the source of the reset.
System Resets, Interrupts, and Operating Modes
2-5
System Reset and Initialization
2.2Interrupts
The interrupt priorities are fixed and defined by the arrangement of the
modules in the connection chain as shown in Figure 2−4. The nearer a module
is to the CPU/NMIRS, the higher the priority. Interrupt priorities determine what
interrupt is taken when more than one interrupt is pending simultaneously.
There are three types of interrupts:
- System reset
- (Non)-maskable NMI
- Maskable
Figure 2−4.Interrupt Priority
CPU
PUC
PUC
Circuit
WDT Security Key
Flash Security Key
Priority
GMIRS
GIE
NMIRS
OSCfault
Flash ACCV
Reset/NMI
MAB − 5LSBs
High
Module
1
Low
Module
2
121212121
Bus
Grant
WDT
Timer
Module
m
Module
n
2-6
System Resets, Interrupts, and Operating Modes
2.2.1(Non)-Maskable Interrupts (NMI)
(Non)-maskable NMI interrupts are not masked by the general interrupt enable
bit (GIE), but are enabled by individual interrupt enable bits (NMIIE, ACCVIE,
OFIE). When a NMI interrupt is accepted, all NMI interrupt enable bits are
automatically reset. Program execution begins at the address stored in the
(non)-maskable interrupt vector , 0FFFCh. User software must set the required
NMI interrupt enable bits for the interrupt to be re-enabled. The block diagram
for NMI sources is shown in Figure 2−5.
A (non)-maskable NMI interrupt can be generated by three sources:
- An edge on the RST/NMI pin when configured in NMI mode
- An oscillator fault occurs
- An access violation to the flash memory
Reset/NMI Pin
At power-up, the RST/NMI pin is configured in the reset mode. The function
of the RST/NMI pins is selected in the watchdog control register WDTCTL. If
the RST
as long as the RST
the CPU starts program execution at the word address stored in the reset
vector, 0FFFEh.
/NMI pin is set to the reset function, the CPU is held in the reset state
/NMI pin is held low. After the input changes to a high state,
System Reset and Initialization
If the RST
/NMI pin is configured by user software to the NMI function, a signal
edge selected by the WDTNMIES bit generates an NMI interrupt if the NMIIE
bit is set. The RST
/NMI flag NMIIFG is also set.
Note:Holding RST/NMI Low
When configured in the NMI mode, a signal generating an NMI event should
not hold the RST
/NMI pin low. If a PUC occurs from a dif ferent source while
the NMI signal is low, the device will be held in the reset state because a PUC
changes the RST
/NMI pin to the reset function.
Note:Modifying WDTNMIES
When NMI mode is selected and the WDTNMIES bit is changed, an NMI can
be generated, depending on the actual level at the RST
/NMI pin. When the
NMI edge select bit is changed before selecting the NMI mode, no NMI is
generated.
System Resets, Interrupts, and Operating Modes
2-7
System Reset and Initialization
Figure 2−5.Block Diagram of (Non)-Maskable Interrupt Sources
ACCV
ACCVIFG
S
FCTL1.1
ACCVIE
IE1.5
Clear
PUC
RST/NMI
IFG1.4
PUC
IE1.4
PUC
OSCFault
IFG1.1
IE1.1
PUC
S
Clear
Clear
S
Clear
NMIIFG
NMIIE
OFIFG
OFIE
NMI_IRQA
WDTTMSEL
WDTNMIES
Counter
WDTNMI
WDT
WDTTMSEL
KEYV
WDTQnEQU
S
IFG1.0
Clear
POR
IRQA
IE1.0
Clear
Flash Module
PORPUC
System Reset
Generator
WDTIFG
WDTIE
V
CC
PUCPOR
PUC
POR
NMIRS
IRQ
2-8
IRQA: Interrupt Request Accepted
Watchdog Timer Module
System Resets, Interrupts, and Operating Modes
PUC
Flash Access Violation
The flash ACCVIFG flag is set when a flash access violation occurs. The flash
access violation can be enabled to generate an NMI interrupt by setting the
ACCVIE bit. The ACCVIFG flag can then be tested by NMI the interrupt service
routine to determine if the NMI was caused by a flash access violation.
Oscillator Fault
The oscillator fault signal warns of a possible error condition with the crystal
oscillator. The oscillator fault can be enabled to generate an NMI interrupt b y
setting the OFIE bit. The OFIFG flag can then be tested by NMI the interrupt
service routine to determine if the NMI was caused by an oscillator fault.
A PUC signal can trigger an oscillator fault, because the PUC switches the
LFXT1 to LF mode, therefore switching off the HF mode. The PUC signal also
switches off the XT2 oscillator.
System Reset and Initialization
System Resets, Interrupts, and Operating Modes
2-9
System Reset and Initialization
Example of an NMI Interrupt Handler
The NMI interrupt is a multiple-source interrupt. An NMI interrupt automatically
resets the NMIIE, OFIE and ACCVIE interrupt-enable bits. The user NMI
service routine resets the interrupt flags and re-enables the interrupt-enable
bits according to the application needs as shown in Figure 2−6.
Figure 2−6.NMI Interrupt Handler
Start of NMI Interrupt Handler
Reset by HW:
OFIE, NMIIE, ACCVIE
OFIFG=1
User’s Software,
Oscillator Fault
Optional
yes
Handler
End of NMI Interrupt
no
ACCVIFG=1
yes
Reset ACCVIFG
User’s Software,
Flash Access
Violation Handler
RETI
Handler
no
User’s Software,
NMIIFG=1
yes
Reset NMIIFGReset OFIFG
External NMI
Handler
no
Note:Enabling NMI Interrupts with ACCVIE, NMIIE, and OFIE
To prevent nested NMI interrupts, the ACCVIE, NMIIE, and OFIE enable bits
should not be set inside of an NMI interrupt service routine.
2.2.2Maskable Interrupts
Maskable interrupts are caused by peripherals with interrupt capability
including the watchdog timer overflow in interval-timer mode. Each maskable
interrupt source can be disabled individually by an interrupt enable bit, or all
maskable interrupts can be disabled by the general interrupt enable (GIE) bit
in the status register (SR).
Each individual peripheral interrupt is discussed in the associated peripheral
module chapter in this manual.
2-10
System Resets, Interrupts, and Operating Modes
2.2.3Interrupt Processing
Before
After
When an interrupt is requested from a peripheral and the peripheral interrupt
enable bit and GIE bit are set, the interrupt service routine is requested. Only
the individual enable bit must be set for (non)-maskable interrupts to be
requested.
Interrupt Acceptance
The interrupt latency is 6 cycles, starting with the acceptance of an interrupt
request, and lasting until the start of execution of the first instruction of the
interrupt-service routine, as shown in Figure 2−7. The interrupt logic executes
the following:
1) Any currently executing instruction is completed.
2) The PC, which points to the next instruction, is pushed onto the stack.
3) The SR is pushed onto the stack.
4) The interrupt with the highest priority is selected if multiple interrupts
occurred during the last instruction and are pending for service.
System Reset and Initialization
5) The interrupt request flag resets automatically on single-source flags.
Multiple source flags remain set for servicing by software.
6) The SR is cleared. This terminates any low-power mode. Because the GIE
bit is cleared, further interrupts are disabled.
7) The content of the interrupt vector is loaded into the PC: the program
continues with the interrupt service routine at that address.
Figure 2−7.Interrupt Processing
Interrupt
Item1
SPTOS
Item2
Interrupt
Item1
Item2
PC
SPTOS
SR
System Resets, Interrupts, and Operating Modes
2-11
System Reset and Initialization
Return From Interrupt
The interrupt handling routine terminates with the instruction:
RETI (return from an interrupt service routine)
The return from the interrupt takes 5 cycles to execute the following actions
and is illustrated in Figure 2−8.
1) The SR with all previous settings pops from the stack. All previous settings
of GIE, CPUOFF, etc. are now in effect, regardless of the settings used
during the interrupt service routine.
2) The PC pops from the stack and begins execution at the point where it was
interrupted.
Figure 2−8.Return From Interrupt
BeforeAfter
Return From Interrupt
Interrupt Nesting
Item1
Item2
PC
SPTOS
SR
SPTOS
Item1
Item2
PC
SR
Interrupt nesting is enabled if the GIE bit is set inside an interrupt service
routine. When interrupt nesting is enabled, any interrupt occurring during an
interrupt service routine will interrupt the routine, regardless of the interrupt
priorities.
2-12
System Resets, Interrupts, and Operating Modes
2.2.4Interrupt Vectors
The interrupt vectors and the power-up starting address are located in the
address range 0FFFFh − 0FFE0h as described in Table 2−1. A vector is
programmed by the user with the 16-bit address of the corresponding interrupt
service routine. See the device-specific data sheet for the complete interrupt
vector list.
Some module enable bits, interrupt enable bits, and interrupt flags are located
in the SFRs. The SFRs are located in the lower address range and are
implemented in byte format. SFRs must be accessed using byte instructions.
See the device-specific datasheet for the SFR configuration.
System Resets, Interrupts, and Operating Modes
2-13
Operating Modes
2.3Operating Modes
The MSP430 family is designed for ultralow-power applications and uses
different operating modes shown in Figure 2−10.
The operating modes take into account three different needs:
- Ultralow-power
- Speed and data throughput
- Minimization of individual peripheral current consumption
The MSP430 typical current consumption is shown in Figure 2−9.
Figure 2−9.Typical Current Consumption of 13x and 14x Devices vs Operating Modes
90
45
340
225
VCC = 3 V
VCC = 2.2 V
70
65
17
0
AM
LPM0LPM2LPM3LPM4
11
Operating Modes
2
1
0.1 0.1
A @ 1 MHzµ
ICC/
315
270
225
180
135
The low-power modes 0−4 are configured with the CPUOFF , OSCOFF, SCG0,
and SCG1 bits in the status register The advantage of including the CPUOFF,
OSCOFF, SCG0, and SCG1 mode-control bits in the status register is that the
present operating mode is saved onto the stack during an interrupt service
routine. Program flow returns to the previous operating mode if the saved SR
value is not altered during the interrupt service routine. Program flow can be
returned to a d i fferent operating mode by manipulating the saved SR value on
the stack inside of the interrupt service routine. The mode-control bits and the
stack can be accessed with any instruction.
When setting any of the mode-control bits, the selected operating mode takes
effect immediately. Peripherals operating with any disabled clock are disabled
until the clock becomes active. The peripherals may also be disabled with their
individual control register settings. All I/O port pins and RAM/registers are
unchanged. Wake up is possible through all enabled interrupts.
2-14
System Resets, Interrupts, and Operating Modes
Figure 2−10. MSP430x1xx Operating Modes For Basic Clock System
Operating Modes
Time Expired, Overflow
WDT
WDT Active,
Security Key Violation
CPUOFF = 1
SCG0 = 0
SCG1 = 0
LPM0
CPU Off, MCLK Off,
SMCLK On, ACLK On
CPUOFF = 1
SCG0 = 1
SCG1 = 0
LPM1
CPU Off, MCLK Off,
SMCLK On, ACLK On
DC Generator Off if DCO
not used in active mode
RST/NMI
Reset Active
WDTIFG = 1
WDTIFG = 1
Active Mode
CPU Is Active
Peripheral Modules Are Active
CPUOFF = 1
SCG0 = 0
SCG1 = 1
LPM2
CPU Off, MCLK Off, SMCLK
Off, DCO Off, ACLK On
POR
WDTIFG = 0
PUC
CPUOFF = 1
VCC On
RST
/NMI is Reset Pin
WDT is Active
SCG0 = 1
SCG1 = 1
CPU Off, MCLK Off, SMCLK
RST/NMI
NMI Active
CPUOFF = 1
OSCOFF = 1
SCG0 = 1
SCG1 = 1
LPM4
CPU Off, MCLK Off, DCO
Off, ACLK Off
DC Generator Off
LPM3
Off, DCO Off, ACLK On
DC Generator Off
SCG1SCG0 OSCOFFCPUOFFModeCPU and Clocks Status
0000ActiveCPU is active, all enabled clocks are active
0001LPM0CPU, MCLK are disabled
SMCLK , ACLK are active
0101LPM1CPU, MCLK, DCO osc. are disabled
DC generator is disabled if the DCO is not used for
MCLK or SMCLK in active mode
SMCLK , ACLK are active
1001LPM2CPU, MCLK, SMCLK, DCO osc. are disabled
DC generator remains enabled
ACLK is active
1101LPM3CPU, MCLK, SMCLK, DCO osc. are disabled
DC generator disabled
ACLK is active
1
111LPM4CPU and all clocks disabled
System Resets, Interrupts, and Operating Modes
2-15
Operating Modes
2.3.1Entering and Exiting Low-Power Modes
An enabled interrupt event wakes the MSP430 from any of the low-power
operating modes. The program flow is:
- Enter interrupt service routine:
JThe PC and SR are stored on the stack
JThe CPUOFF, SCG1, and OSCOFF bits are automatically reset
- Options for returning from the interrupt service routine:
JThe original SR is popped from the stack, restoring the previous
operating mode.
JThe SR bits stored on the stack can be modified within the interrupt
service routine returning to a d i fferent operating mode when the RETI
instruction is executed.
; Enter LPM0 Example
BIS#GIE+CPUOFF,SR; Enter LPM0
;...; Program stops here
;
; Exit LPM0 Interrupt Service Routine
BIC#CPUOFF,0(SP); Exit LPM0 on RETI
RETI
; Enter LPM3 Example
BIS#GIE+CPUOFF+SCG1+SCG0,SR ; Enter LPM3
;...; Program stops here
;
; Exit LPM3 Interrupt Service Routine
BIC#CPUOFF+SCG1+SCG0,0(SP); Exit LPM3 on RETI
RETI
Extended Time in Low-Power Modes
The negative temperature coefficient of the DCO should be considered when
the DCO is disabled for extended low-power mode periods. If the temperature
changes significantly, the DCO frequency at wake-up may be significantly
different from when the low-power mode was entered and may be out of the
specified operating range. To avoid this, the DCO can be set to it lowest value
before entering the low-power mode for extended periods of time where
temperature can change.
; Enter LPM4 Example with lowest DCO Setting
BIC#RSEL2+RSEL1+RSEL0,&BCSCTL1; Lowest RSEL
BIS#GIE+CPUOFF+OSCOFF+SCG1+SCG0,SR ; Enter LPM4
;...; Program stops
;
; Interrupt Service Routine
BIC#CPUOFF+OSCOFF+SCG1+SCG0,0(SR); Exit LPM4 on RETI
RETI
2-16
System Resets, Interrupts, and Operating Modes
2.4Principles for Low-Power Applications
Often, the most important factor for reducing power consumption is using the
MSP430’s clock system to maximize the time in LPM3. LPM3 power
consumption is less than 2 µA typical with both a real-time clock function and
all interrupts active. A 32-kHz watch crystal is used for the ACLK and the CPU
is clocked from the DCO (normally off) which has a 6-µs wake-up.
- Use interrupts to wake the processor and control program flow.
- Peripherals should be switched on only when needed.
- Use low-power integrated peripheral modules in place of software driven
functions. For example Timer_A and Timer_B can automatically generate
PWM and capture external timing, with no CPU resources.
- Calculated branching and fast table look-ups should be used in place of
flag polling and long software calculations.
- Avoid frequent subroutine and function calls due to overhead.
- For longer software routines, single-cycle CPU registers should be used.
Principles for Low-Power Applications
2.5Connection of Unused Pins
The correct termination of all unused pins is listed in Table 2−2.
Table 2−2.Connection of Unused Pins
PinPotentialComment
AV
CC
AV
SS
V
REF+
Ve
REF+
V
/Ve
REF−
XINDV
XOUTOpen
XT2INDV
XT2OUTOpen13x, 14x, 15x and 16x devices
Px.0 to Px.7OpenSwitched to port function, output direction
/NMIDVCC or V
RST
Test/V
PP
TestDV
TDOOpen
TDIOpen
TMSOpen
TCKOpen
DV
DV
Open
DV
DV
REF−
DV
Open11x1A, 11x2, 12x, 12x2 devices
CC
SS
SS
SS
CC
SS
SS
SS
13x, 14x, 15x and 16x devices
Pullup resistor 47 kΩ
CC
P11x devices
Pulldown resistor 30K 11x1 devices
System Resets, Interrupts, and Operating Modes
2-17
Chapter 3
!
This chapter describes the MSP430 CPU, addressing modes, and instruction
set.
The CPU incorporates features specifically designed for modern
programming techniques such as calculated branching, table processing and
the use of high-level languages such as C. The CPU can address the complete
address range without paging.
The CPU features include:
- RISC architecture with 27 instructions and 7 addressing modes.
- Orthogonal architecture with every instruction usable with every
- Full register access including program counter, status registers, and stack
- Single-cycle register operations.
- Large 16-bit register file reduces fetches to memory.
- 16-bit address bus allows direct access and branching throughout entire
addressing mode.
pointer.
memory range.
- 16-bit data bus allows direct manipulation of word-wide arguments.
- Constant generator provides six most used immediate values and
reduces code size.
- Direct memory-to-memory transfers without intermediate register holding.
- Word and byte addressing and instruction formats.
The block diagram of the CPU is shown in Figure 3−1.
3-2
RISC 16-Bit CPU
Figure 3−1.CPU Block Diagram
MDB − Memory Data BusMemory Address Bus − MAB
CPU Introduction
015
R0/PC Program Counter 0
R1/SP Stack Pointer
R2/SR/CG1 Status
R3/CG2 Constant Generator
R4 General Purpose
R5 General Purpose
R6 General Purpose
R7 General Purpose
R8 General Purpose
R9 General Purpose
R10 General Purpose
R11 General Purpose
R12 General Purpose
R13 General Purpose
0
16
Zero, Z
Carry, C
Overflow, V
Negative, N
R14 General Purpose
R15 General Purpose
dstsrc
16−bit ALU
16
MCLK
RISC 16-Bit CPU
3-3
CPU Registers
3.2CPU Registers
The CPU incorporates sixteen 16-bit registers. R0, R1, R2 and R3 have
dedicated functions. R4 to R15 are working registers for general use.
3.2.1Program Counter (PC)
The 16-bit program counter (PC/R0) points to the next instruction to be
executed. Each instruction uses an even number of bytes (two, four, or six),
and the PC is incremented accordingly. Instruction accesses in the 64-KB
address space are performed on word boundaries, and the PC is aligned to
even addresses. Figure 3−2 shows the program counter.
Figure 3−2.Program Counter
150
1
Program Counter Bits 15 to 1
0
The PC can be addressed with all instructions and addressing modes. A few
examples:
MOV#LABEL,PC ; Branch to address LABEL
MOVLABEL,PC ; Branch to address contained in LABEL
MOV@R14,PC; Branch indirect to address in R14
3-4
RISC 16-Bit CPU
3.2.2Stack Pointer (SP)
The stack pointer (SP/R1) is used by the CPU to store the return addresses
of subroutine calls and interrupts. It uses a predecrement, postincrement
scheme. In addition, the SP can be used by software with all instructions and
addressing modes. Figure 3−3 shows the SP. The SP is initialized into RAM
by the user, and is aligned to even addresses.
Figure 3−4 shows stack usage.
Figure 3−3.Stack Pointer
150
CPU Registers
1
Figure 3−4.Stack Usage
0xxxh
0xxxh − 2
0xxxh − 4
0xxxh − 6
0xxxh − 8
The special cases of using the SP as an argument to the PUSH and POP
instructions are described and shown in Figure 3−5.
Stack Pointer Bits 15 to 1
MOV2(SP),R6 ; Item I2 −> R6
MOVR7,0(SP) ; Overwrite TOS with R7
PUSH#0123h; Put 0123h onto TOS
POPR8; R8 = 0123h
SP
POP R8Address
I1
I2
I3
0123h
PUSH #0123h
I1
I2
I3
SP
I1
I2
I3
0123h
0
SP
Figure 3−5.PUSH SP - POP SP Sequence
PUSH SP
SP
old
SP
1
The stack pointer is changed after
a PUSH SP instruction.
SP
1
POP SP
SP
2
The stack pointer is not changed after a POP SP
instruction. The POP SP instruction places SP1 into the
stack pointer SP (SP2=SP1)
SP
1
RISC 16-Bit CPU
3-5
CPU Registers
3.2.3Status Register (SR)
The status register (SR/R2), used as a source or destination register, can be
used in the register mode only addressed with word instructions. The remaining combinations of addressing modes are used to support the constant generator. Figure 3−6 shows the SR bits.
Figure 3−6.Status Register Bits
150
Reserved
Table 3−1 describes the status register bits.
Table 3−1.Description of Status Register Bits
BitDescription
VOverflow bit. This bit is set when the result of an arithmetic operation
overflows the signed-variable range.
ADD(.B),ADDC(.B)Set when:
SUB(.B),SUBC(.B),CMP(.B)Set when:
SCG1System clock generator 1. This bit, when set, turns off the SMCLK.
SCG0System clock generator 0. This bit, when set, turns off the DCO dc
generator, if DCOCLK is not used for MCLK or SMCLK.
OSCOFFOscillator Off. This bit, when set, turns off the LFXT1 crystal oscillator,
when LFXT1CLK is not use for MCLK or SMCLK
CPUOFFCPU off. This bit, when set, turns off the CPU.
GIEGeneral interrupt enable. This bit, when set, enables maskable
interrupts. When reset, all maskable interrupts are disabled.
NNegative bit. This bit is set when the result of a byte or word operation
is negative and cleared when the result is not negative.
Word operation:N is set to the value of bit 15 of the
Byte operation:N is set to the value of bit 7 of the
ZZero bit. This bit is set when the result of a byte or word operation is 0
and cleared when the result is not 0.
C
Carry bit. This bit is set when the result of a byte or word operation
produced a carry and cleared when no carry occurred.
Six commonly-used constants are generated with the constant generator
registers R2 and R3, without requiring an additional 16-bit word of program
code. The constants are selected with the source-register addressing modes
(As), as described in Table 3−2.
Table 3−2.Values of Constant Generators CG1, CG2
RegisterAsConstantRemarks
R200− − − − −Register mode
R201(0)Absolute address mode
R21000004h+4, bit processing
R21100008h+8, bit processing
R30000000h0, word processing
R30100001h+1
R31000002h+2, bit processing
R3110FFFFh−1, word processing
The constant generator advantages are:
CPU Registers
- No special instructions required
- No additional code word for the six constants
- No code memory access required to retrieve the constant
The assembler uses the constant generator automatically if one of the six
constants is used as an immediate source operand. Registers R2 and R3,
used in the constant mode, cannot be addressed explicitly; they act as
source-only registers.
Constant Generator − Expanded Instruction Set
The RISC instruction set of the MSP430 has only 27 instructions. However, the
constant generator allows the MSP430 assembler to support 24 additional,
emulated instructions. For example, the single-operand instruction:
CLRdst
is emulated by the double-operand instruction with the same length:
MOVR3,dst
where the #0 is replaced by the assembler, and R3 is used with As=00.
INCdst
is replaced by:
ADD0(R3),dst
RISC 16-Bit CPU
3-7
CPU Registers
3.2.5General−Purpose Registers R4 - R15
The twelve registers, R4−R15, are general-purpose registers. All of these
registers can be used as data registers, address pointers, or index values and
can be accessed with byte or word instructions as shown in Figure 3−7.
Figure 3−7.Register-Byte/Byte-Register Operations
Register-Byte Operation
High ByteLow Byte
Unused
Byte
Example Register-Byte OperationExample Byte-Register Operation
Mem (0203h) = 0A1hR5 = 00061h
C = 0, Z = 0, N = 1C = 0, Z = 0, N = 0
Register
Memory
Byte-Register Operation
High ByteLow Byte
Byte
0h
00061h
Memory
Register
3-8
+ (Addressed byte)+ (Low byte of register)
−>(Addressed byte)
RISC 16-Bit CPU
(Low byte of register)(Addressed byte)
−>(Low byte of register, zero to High byte)
3.3Addressing Modes
Seven addressing modes for the source operand and four addressing modes
for the destination operand can address the complete address space with no
exceptions. The bit numbers in Table 3−3 describe the contents of the As
(source) and Ad (destination) mode bits.
00/0Register modeRnRegister contents are operand
01/1Indexed modeX(Rn)(Rn + X) points to the operand. X
01/1Symbolic modeADDR(PC + X) points to the operand. X
01/1Absolute mode&ADDRThe word following the instruction
10/−Indirect register
mode
11/−Indirect
autoincrement
11/−
Immediate mode#NThe word following the instruction
@RnRn is used as a pointer to the
@Rn+Rn is used as a pointer to the
Addressing Modes
is stored in the next word.
is stored in the next word. Indexed
mode X(PC) is used.
contains the absolute address. X
is stored in the next word. Indexed
mode X(SR) is used.
operand.
operand. Rn is incremented
afterwards by 1 for .B instructions
and by 2 for .W instructions.
contains the immediate constant
N. Indirect autoincrement mode
@PC+ is used.
The seven addressing modes are explained in detail in the following sections.
Most of the examples show the same addressing mode for the source and
destination, but any valid combination of source and destination addressing
modes is possible in an instruction.
Note:Use of Labels EDE, TONI, TOM, and LEO
Throughout MSP430 documentation EDE, TONI, TOM, and LEO are used
as generic labels. They are only labels. They have no special meaning.
RISC 16-Bit CPU
3-9
Addressing Modes
Before:After:
3.3.1Register Mode
The register mode is described in Table 3−4.
Table 3−4.Register Mode Description
Assembler CodeContent of ROM
MOV R10,R11MOV R10,R11
Length:One or two words
Operation:Move the content of R10 to R11. R10 is not affected.
Comment:Valid for source and destination
Example:MOV R10,R11
R11
PC
0A023hR10
0FA15h
PC
old
R11
PCPC
0A023hR10
0A023h
+ 2
old
Note:Data in Registers
The data in the register can be accessed using word or byte instructions. If
byte instructions are used, the high byte is always 0 in the result. The status
bits are handled according to the result of the byte instruction.
3-10
RISC 16-Bit CPU
3.3.2Indexed Mode
Before:
After:
The indexed mode is described in Table 3−5.
Table 3−5.Indexed Mode Description
Assembler CodeContent of ROM
MOV 2(R5),6(R6)MOV X(R5),Y(R6)
Length:Two or three words
Operation:Move the contents of the source address (contents of R 5 + 2)
Comment:Valid for source and destination
Addressing Modes
X = 2
Y = 6
to the destination address (contents of R6 + 6). The source
and destination registers (R5 and R6) are not affected. In
indexed mode, the program counter is incremented
automatically so that program execution continues with the
next instruction.
Example:MOV 2(R5),6(R6);
0FF16h
0FF14h
0FF12h
01094h
01092h
01090h
01084h
01082h
01080h
Address
Space
00006h
00002h
04596hPC
0xxxxh
05555h
0xxxxh
0xxxxh
01234h
0xxxxh
Register
R5
R6
01080h
0108Ch
0108Ch
+0006h
01092h
01080h
+0002h
01082h
0FF16h
0FF14h
0FF12h
01094h
01092h
01090h
01084h
01082h
01080h
Address
Space
0xxxxh
00006h
00002h
04596h
0xxxxh
01234h
0xxxxh
0xxxxh
01234h
0xxxxh
PC
Register
R5
R6
01080h
0108Ch
RISC 16-Bit CPU
3-11
Addressing Modes
Before:
After:
3.3.3Symbolic Mode
The symbolic mode is described in Table 3−6.
Table 3−6.Symbolic Mode Description
Assembler CodeContent of ROM
MOV EDE,TONIMOV X(PC),Y(PC)
Length:Two or three words
Operation:Move the contents of the source address EDE (contents of
X = EDE − PC
Y = TONI − PC
PC + X) to the destination address TONI (contents of PC + Y).
The words after the instruction contain the differences
between the PC and the source or destination addresses.
The assembler computes and inserts offsets X and Y
automatically. With symbolic mode, the program counter (PC)
is incremented automatically so that program execution
continues with the next instruction.
Comment:Valid for source and destination
Example:MOV EDE,TONI ;Source address EDE = 0F016h
;Dest. address TONI=01114h
Register
PC
0FF16h
0FF14h
0FF12h
0F018h
0F016h
0F014h
01116h
01114h
01112h
Address
Space
011FEh
0F102h
04090hPC
0xxxxh
0A123h
0xxxxh
0xxxxh
05555h
0xxxxh
Register
0FF14h
+0F102h
0F016h
0FF16h
+011FEh
01114h
0FF16h
0FF14h
0FF12h
0F018h
0F016h
0F014h
01116h
01114h
01112h
Address
Space
0xxxxh
011FEh
0F102h
04090h
0xxxxh
0A123h
0xxxxh
0xxxxh
0A123h
0xxxxh
3-12
RISC 16-Bit CPU
3.3.4Absolute Mode
The absolute mode is described in Table 3−7.
Table 3−7.Absolute Mode Description
Assembler CodeContent of ROM
MOV &EDE,&TONIMOV X(0),Y(0)
Length:Two or three words
Operation:Move the contents of the source address EDE to the
Comment:Valid for source and destination
Example:MOV &EDE,&TONI ;Source address EDE=0F016h,
Addressing Modes
X = EDE
Y = TONI
destination address TONI. The words after the instruction
contain the absolute address of the source and destination
addresses. With absolute mode, the PC is incremented
automatically so that program execution continues with the
next instruction.
;dest. address TONI=01114h
Before:
0FF16h
0FF14h
0FF12h
0F018h
0F016h
0F014h
01116h
01114h
01112h
Address
Space
01114h
0F016h
04292hPC
0xxxxh
0A123h
0xxxxh
0xxxxh
01234h
0xxxxh
Register
After:
0FF16h
0FF14h
0FF12h
0F018h
0F016h
0F014h
01116h
01114h
01112h
Address
Space
0xxxxh
01114h
0F016h
04292h
0xxxxh
0A123h
0xxxxh
0xxxxh
0A123h
0xxxxh
Register
PC
This address mode is mainly for hardware peripheral modules that are located
at an absolute, fixed address. These are addressed with absolute mode to
ensure software transportability (for example, position-independent code).
RISC 16-Bit CPU
3-13
Addressing Modes
Before:
After:
3.3.5Indirect Register Mode
The indirect register mode is described in Table 3−8.
Table 3−8.Indirect Mode Description
Assembler CodeContent of ROM
MOV @R10,0(R11)MOV @R10,0(R11)
Length:One or two words
Operation:Move the contents of the source address (contents of R10) to
Comment:Valid only for source operand. The substitute for destination
Example:MOV.B @R10,0(R11)
the destination address (contents of R11). The registers are
not modified.
operand is 0(Rd).
0FF16h
0FF14h
0FF12h
0FA34h
0FA32h
0FA30h
002A8h
002A7h
002A6h
Address
Space
0xxxxh
0000h
04AEBh
0xxxxh
0xxxxh
05BC1h
0xxxxh
0xxh
012h
0xxh
PC
R10
R11
Register
0FA33h
002A7h
0FF16h
0FF14h
0FF12h
0FA34h
0FA32h
0FA30h
002A8h
002A7h
002A6h
Address
Space
0xxxxh
0000h
04AEBh
0xxxxh
0xxxxh
05BC1h
0xxxxh
0xxh
05Bh
0xxh
PC
R10
R11
Register
0FA33h
002A7h
3-14
RISC 16-Bit CPU
3.3.6Indirect Autoincrement Mode
Before:
After:
The indirect autoincrement mode is described in Table 3−9.
Table 3−9.Indirect Autoincrement Mode Description
Assembler CodeContent of ROM
MOV @R10+,0(R11)MOV @R10+,0(R11)
Length:One or two words
Operation:Move the contents of the source address (contents of R10) to
the destination address (contents of R11). Register R10 is
incremented by 1 for a byte operation, or 2 for a word
operation after the fetch; it points to the next address without
any overhead. This is useful for table processing.
Comment:Valid only for source operand. The substitute for destination
operand is 0(Rd) plus second instruction INCD Rd.
Example:MOV @R10+,0(R11)
Addressing Modes
0FF18h
0FF16h
0FF14h
0FF12h
0FA34h
0FA32h
0FA30h
010AAh
010A8h
010A6h
Address
Space
0xxxxh
00000h
04ABBh
0xxxxh
0xxxxh
05BC1h
0xxxxh
0xxxxh
01234h
0xxxxh
PC
R10
R11
Register
0FA32h
010A8h
0FF18h
0FF16h
0FF14h
0FF12h
0FA34h
0FA32h
0FA30h
010AAh
010A8h
010A6h
Address
Space
0xxxxh
00000h
04ABBh
0xxxxh
0xxxxh
05BC1h
0xxxxh
0xxxxh
05BC1h
0xxxxh
PC
R11
Register
0FA34hR10
010A8h
The autoincrementing of the register contents occurs after the operand is
fetched. This is shown in Figure 3−8.
Figure 3−8.Operand Fetch Operation
InstructionAddressOperand
+1/ +2
RISC 16-Bit CPU
3-15
Addressing Modes
Before:
r
After:
3.3.7Immediate Mode
The immediate mode is described in Table 3−10.
Table 3−10.Immediate Mode Description
Assembler CodeContent of ROM
MOV #45h,TONIMOV @PC+,X(PC)
Length:Two or three words
It is one word less if a constant of CG1 or CG2 can be used.
Operation:Move the immediate constant 45h, which is contained in the
word following the instruction, to destination address TONI.
When fetching the source, the program counter points to the
word following the instruction and moves the contents to the
destination.
Comment:Valid only for a source operand.
45
X = TONI − PC
Example:MOV #45h,TONI
0FF16h
0FF14h
0FF12h
010AAh
010A8h
010A6h
Address
Space
01192h
00045h
040B0hPC
0xxxxh
01234h
0xxxxh
Register
0FF16h
+01192h
010A8h
0FF18h
0FF16h
0FF14h
0FF12h
010AAh
010A8h
010A6h
Address
Space
0xxxxh
01192h
00045h
040B0h
0xxxxh
00045h
0xxxxh
Registe
PC
3-16
RISC 16-Bit CPU
3.4Instruction Set
Instruction Set
The complete MSP430 instruction set consists of 27 core instructions and 24
emulated instructions. The core instructions are instructions that have unique
op-codes decoded by the CPU. The emulated instructions are instructions that
make code easier to write and read, but do not have op-codes themselves,
instead they are replaced automatically by the assembler with an equivalent
core instruction. There is no code or performance penalty for using emulated
instruction.
There are three core-instruction formats:
- Dual-operand
- Single-operand
- Jump
All single-operand and dual-operand instructions can be byte or word
instructions by using .B or .W extensions. Byte instructions are used to access
byte data or byte peripherals. Word instructions are used to access word data
or word peripherals. If no extension is used, the instruction is a word
instruction.
The source and destination of an instruction are defined by the following fields:
srcThe source operand defined by As and S-reg
dstThe destination operand defined by Ad and D-reg
AsThe addressing bits responsible for the addressing mode used
for the source (src)
S-regThe working register used for the source (src)
AdThe addressing bits responsible for the addressing mode used
for the destination (dst)
D-regThe working register used for the destination (dst)
B/WByte or word operation:
0: word operation
1: byte operation
Note:Destination Address
Destination addresses are valid anywhere in the memory map. However,
when using an instruction that modifies the contents of the destination, the
user must ensure the destination address is writable. For example, a
masked-ROM location would be a valid destination address, but the contents
are not modifiable, so the results of the instruction would be lost.
RISC 16-Bit CPU
3-17
Instruction Set
Mnemonic
S-Reg,
3.4.1Double-Operand (Format I) Instructions
Figure 3−9 illustrates the double-operand instruction format.
Figure 3−9.Double Operand Instruction Format
150
Op-code
Table 3−11 lists and describes the double operand instructions.
−The status bit is not affected
0The status bit is cleared
1The status bit is set
All addressing modes are possible for the CALL instruction. If the symbolic
mode (ADDRESS), the immediate mode (#N), the absolute mode (&EDE) or
the indexed mode x(RN) is used, the word that follows contains the address
information.
RISC 16-Bit CPU
3-19
Instruction Set
3.4.3Jumps
Figure 3−11 shows the conditional-jump instruction format.
Figure 3−11. Jump Instruction Format
150
Op-code
Table 3−13 lists and describes the jump instructions.
Table 3−13.Jump Instructions
MnemonicS-Reg, D-RegOperation
JEQ/JZLabelJump to label if zero bit is set
JNE/JNZLabelJump to label if zero bit is reset
JCLabelJump to label if carry bit is set
JNCLabelJump to label if carry bit is reset
JNLabelJump to label if negative bit is set
JGELabelJump to label if (N .XOR. V) = 0
JLLabelJump to label if (N .XOR. V) = 1
JMP
Conditional jumps support program branching relative to the PC and do not
affect the status bits. The possible jump range is from − 511 to +512 words
relative to the PC value at the jump instruction. The 10-bit program-counter
offset is treated as a signed 10-bit value that is doubled and added to the
program counter:
8714131211109654321
C10-Bit PC Offset
LabelJump to label unconditionally
3-20
RISC 16-Bit CPU
PC
new
= PC
+ 2 + PC
old
offset
× 2
Instruction Set
*ADC[.W] Add carry to destination
*ADC.B Add carry to destination
SyntaxADCdst or ADC.W dst
ADC.Bdst
Operationdst + C −> dst
EmulationADDC#0,dst
ADDC.B#0,dst
DescriptionThe carry bit (C) is added to the destination operand. The previous contents
of the destination are lost.
Status BitsN: Set if result is negative, reset if positive
Z: Set if result is zero, reset otherwise
C: Set if dst was incremented from 0FFFFh to 0000, reset otherwise
Set if dst was incremented from 0FFh to 00, reset otherwise
V: Set if an arithmetic overflow occurs, otherwise reset
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe 16-bit counter pointed to by R13 is added to a 32-bit counter pointed to
by R12.
ADD@R13,0(R12); Add LSDs
ADC2(R12); Add carry to MSD
ExampleThe 8-bit counter pointed to by R13 is added to a 16-bit counter pointed to by
R12.
ADD.B@R13,0(R12); Add LSDs
ADC.B1(R12); Add carry to MSD
RISC 16−Bit CPU
3-21
Instruction Set
ADD[.W]Add source to destination
ADD.B Add source to destination
SyntaxADDsrc,dst orADD.Wsrc,dst
ADD.Bsrc,dst
Operationsrc + dst −> dst
DescriptionThe source operand is added to the destination operand. The source operand
is not affected. The previous contents of the destination are lost.
Status BitsN: Set if result is negative, reset if positive
Z: Set if result is zero, reset otherwise
C: Set if there is a carry from the result, cleared if not
V: Set if an arithmetic overflow occurs, otherwise reset
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleR5 is increased by 10. The jump to TONI is performed on a carry.
ADD#10,R5
JCTONI; Carry occurred
......; No carry
ExampleR5 is increased by 10. The jump to TONI is performed on a carry.
ADD.B#10,R5; Add 10 to Lowbyte of R5
JCTONI; Carry occurred, if (R5) ≥ 246 [0Ah+0F6h]
......; No carry
3-22
RISC 16−Bit CPU
Instruction Set
ADDC[.W]Add source and carry to destination
ADDC.BAdd source and carry to destination
SyntaxADDCsrc,dst orADDC.Wsrc,dst
ADDC.Bsrc,dst
Operationsrc + dst + C −> dst
DescriptionThe source operand and the carry bit (C) are added to the destination operand.
The source operand is not affected. The previous contents of the destination
are lost.
Status BitsN: Set if result is negative, reset if positive
Z: Set if result is zero, reset otherwise
C: Set if there is a carry from the MSB of the result, reset otherwise
V: Set if an arithmetic overflow occurs, otherwise reset
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe 32-bit counter pointed to by R13 is added to a 32-bit counter, eleven words
(20/2 + 2/2) above the pointer in R13.
ADD@R13+,20(R13); ADD LSDs with no carry in
ADDC@R13+,20(R13); ADD MSDs with carry
...; resulting from the LSDs
ExampleThe 24-bit counter pointed to by R13 is added to a 24-bit counter, eleven words
above the pointer in R13.
ADD.B@R13+,10(R13); ADD LSDs with no carry in
ADDC.B@R13+,10(R13); ADD medium Bits with carry
ADDC.B@R13+,10(R13); ADD MSDs with carry
...; resulting from the LSDs
RISC 16−Bit CPU
3-23
Instruction Set
AND[.W]Source AND destination
AND.BSource AND destination
SyntaxANDsrc,dst or AND.W src,dst
AND.Bsrc,dst
Operationsrc .AND. dst −> dst
DescriptionThe source operand and the destination operand are logically ANDed. The
result is placed into the destination.
Status BitsN: Set if result MSB is set, reset if not set
Z: Set if result is zero, reset otherwise
C: Set if result is not zero, reset otherwise ( = .NOT. Zero)
V: Reset
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe bits set in R5 are used as a mask (#0AA55h) for the word addressed by
TOM. If the result is zero, a branch is taken to label TONI.
MOV#0AA55h,R5; Load mask into register R5
ANDR5,TOM; mask word addressed by TOM with R5
JZTONI;
......; Result is not zero
;
;
;or
;
;
AND#0AA55h,TOM
JZTONI
ExampleThe bits of mask #0A5h are logically ANDed with the low byte TOM. If the result
is zero, a branch is taken to label TONI.
AND.B#0A5h,TOM; mask Lowbyte TOM with 0A5h
JZTONI;
......; Result is not zero
3-24
RISC 16−Bit CPU
Instruction Set
BIC[.W]Clear bits in destination
BIC.BClear bits in destination
SyntaxBICsrc,dst or BIC.W src,dst
BIC.Bsrc,dst
Operation.NOT.src .AND. dst −> dst
DescriptionThe inverted source operand and the destination operand are logically
ANDed. The result is placed into the destination. The source operand is not
affected.
Status BitsStatus bits are not affected.
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe six MSBs of the RAM word LEO are cleared.
BIC#0FC00h,LEO; Clear 6 MSBs in MEM(LEO)
ExampleThe five MSBs of the RAM byte LEO are cleared.
BIC.B#0F8h,LEO; Clear 5 MSBs in Ram location LEO
RISC 16−Bit CPU
3-25
Instruction Set
BIS[.W]Set bits in destination
BIS.BSet bits in destination
SyntaxBISsrc,dst orBIS.Wsrc,dst
BIS.Bsrc,dst
Operationsrc .OR. dst −> dst
DescriptionThe source operand and the destination operand are logically ORed. The
result is placed into the destination. The source operand is not affected.
Status BitsStatus bits are not affected.
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe six LSBs of the RAM word TOM are set.
BIS#003Fh,TOM; set the six LSBs in RAM location TOM
ExampleThe three MSBs of RAM byte TOM are set.
BIS.B#0E0h,TOM; set the 3 MSBs in RAM location TOM
3-26
RISC 16−Bit CPU
Instruction Set
BIT[.W]Test bits in destination
BIT.BTest bits in destination
SyntaxBITsrc,dst or BIT.W src,dst
Operationsrc .AND. dst
DescriptionThe source and destination operands are logically ANDed. The result affects
only the status bits. The source and destination operands are not affected.
Status BitsN: Set if MSB of result is set, reset otherwise
Z: Set if result is zero, reset otherwise
C: Set if result is not zero, reset otherwise (.NOT. Zero)
V: Reset
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleIf bit 9 of R8 is set, a branch is taken to label TOM.
BIT#0200h,R8; bit 9 of R8 set?
JNZTOM; Yes, branch to TOM
...; No, proceed
ExampleIf bit 3 of R8 is set, a branch is taken to label TOM.
BIT.B#8,R8
JCTOM
ExampleA serial communication receive bit (RCV) is tested. Because the carry bit is
equal to the state of the tested bit while using the BIT instruction to test a single
bit, the carry bit is used by the subsequent instruction; the read information is
shifted into register RECBUF.
;
; Serial communication with LSB is shifted first:
; xxxxxxxxxxxxxxxx
BIT.B#RCV,RCCTL; Bit info into carry
RRCRECBUF; Carry −> MSB of RECBUF
; cxxx xxxx
......; repeat previous two instructions
......; 8 times
; cccc cccc
; ^ ^
; MSB LSB
; Serial communication with MSB shifted first:
BIT.B#RCV,RCCTL; Bit info into carry
RLC.BRECBUF; Carry −> LSB of RECBUF
; xxxxxxxc
......; repeat previous two instructions
......; 8 times
; cccccccc
; | LSB
; MSB
RISC 16−Bit CPU
3-27
Instruction Set
* BR, BRANCHBranch to .......... destination
SyntaxBRdst
Operationdst −> PC
EmulationMOVdst,PC
DescriptionAn unconditional branch is taken to an address anywhere in the 64K address
space. All source addressing modes can be used. The branch instruction is
a word instruction.
Status BitsStatus bits are not affected.
ExampleExamples for all addressing modes are given.
BR#EXEC;Branch to label EXEC or direct branch (e.g. #0A4h)
BR@R5; Branch to the address contained in the word
; pointed to by R5.
; Core instruction MOV @R5,PC
; Indirect, indirect R5
BR@R5+; Branch to the address contained in the word pointed
; to by R5 and increment pointer in R5 afterwards.
; The next time—S/W flow uses R5 pointer—it can
; alter program execution due to access to
; next address in a table pointed to by R5
; Core instruction MOV @R5,PC
; Indirect, indirect R5 with autoincrement
BRX(R5); Branch to the address contained in the address
; pointed to by R5 + X (e.g. table with address
; starting at X). X can be an address or a label
; Core instruction MOV X(R5),PC
; Indirect, indirect R5 + X
3-28
RISC 16−Bit CPU
Instruction Set
CALL Subroutine
SyntaxCALLdst
Operationdst −> tmpdst is evaluated and stored
SP − 2 −> SP
PC −> @SPPC updated to TOS
tmp −> PCdst saved to PC
DescriptionA subroutine call is made to an address anywhere in the 64K address space.
All addressing modes can be used. The return address (the address of the
following instruction) is stored on the stack. The call instruction is a word
instruction.
Status BitsStatus bits are not affected.
ExampleExamples for all addressing modes are given.
CALL#EXEC; Call on label EXEC or immediate address (e.g. #0A4h)
CALL@R5; Call on the address contained in the word
; pointed to by R5
; SP−2 → SP, PC+2 → @SP, @R5 → PC
; Indirect, indirect R5
CALL@R5+; Call on the address contained in the word
; pointed to by R5 and increment pointer in R5.
; The next time—S/W flow uses R5 pointer—
; it can alter the program execution due to
; access to next address in a table pointed to by R5
; SP−2 → SP, PC+2 → @SP, @R5 → PC
; Indirect, indirect R5 with autoincrement
CALLX(R5); Call on the address contained in the address pointed
; to by R5 + X (e.g. table with address starting at X)
; X can be an address or a label
; SP−2 → SP, PC+2 → @SP, X(R5) → PC
; Indirect, indirect R5 + X
DescriptionThe destination operand is cleared.
Status BitsStatus bits are not affected.
ExampleRAM word TONI is cleared.
CLRTONI; 0 −> TONI
ExampleRegister R5 is cleared.
CLRR5
ExampleRAM byte TONI is cleared.
CLR.BTONI; 0 −> TONI
3-30
RISC 16−Bit CPU
Instruction Set
* CLRCClear carry bit
SyntaxCLRC
Operation0 −> C
EmulationBIC#1,SR
DescriptionThe carry bit (C) is cleared. The clear carry instruction is a word instruction.
Status BitsN: Not affected
Z: Not affected
C: Cleared
V: Not affected
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe 16-bit decimal counter pointed to by R13 is added to a 32-bit counter
pointed to by R12.
CLRC; C=0: defines start
DADD@R13,0(R12) ; add 16-bit counter to low word of 32-bit counter
DADC2(R12); add carry to high word of 32-bit counter
RISC 16−Bit CPU
3-31
Instruction Set
* CLRNClear negative bit
SyntaxCLRN
Operation0 → N
or
(.NOT.src .AND. dst −> dst)
EmulationBIC#4,SR
DescriptionThe constant 04h is inverted (0FFFBh) and is logically ANDed with the
destination operand. The result is placed into the destination. The clear
negative bit instruction is a word instruction.
Status BitsN: Reset to 0
Z: Not affected
C: Not affected
V: Not affected
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe Negative bit in the status register is cleared. This avoids special treatment
with negative numbers of the subroutine called.
CLRN
CALLSUBR
......
......
SUBRJNSUBRET; If input is negative: do nothing and return
......
......
......
SUBRETRET
3-32
RISC 16−Bit CPU
Instruction Set
* CLRZClear zero bit
SyntaxCLRZ
Operation0 → Z
or
(.NOT.src .AND. dst −> dst)
EmulationBIC#2,SR
DescriptionThe constant 02h is inverted (0FFFDh) and logically ANDed with the
destination operand. The result is placed into the destination. The clear zero
bit instruction is a word instruction.
Status BitsN: Not affected
Z: Reset to 0
C: Not affected
V: Not affected
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe zero bit in the status register is cleared.
CLRZ
RISC 16−Bit CPU
3-33
Instruction Set
CMP[.W]Compare source and destination
CMP.BCompare source and destination
SyntaxCMPsrc,dst orCMP.Wsrc,dst
CMP.Bsrc,dst
Operationdst + .NOT.src + 1
or
(dst − src)
DescriptionThe source operand is subtracted from the destination operand. This is
accomplished by adding the 1s complement of the source operand plus 1. The
two operands are not affected and the result is not stored; only the status bits
are affected.
Status BitsN: Set if result is negative, reset if positive (src >= dst)
Z: Set if result is zero, reset otherwise (src = dst)
C: Set if there is a carry from the MSB of the result, reset otherwise
V: Set if an arithmetic overflow occurs, otherwise reset
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleR5 and R6 are compared. If they are equal, the program continues at the label
EQUAL.
CMPR5,R6; R5 = R6?
JEQEQUAL; YES, JUMP
ExampleTwo RAM blocks are compared. If they are not equal, the program branches
to the label ERROR.
MOV#NUM,R5; number of words to be compared
MOV#BLOCK1,R6; BLOCK1 start address in R6
MOV#BLOCK2,R7; BLOCK2 start address in R7
L$1CMP@R6+,0(R7); Are Words equal? R6 increments
JNZERROR; No, branch to ERROR
INCDR7; Increment R7 pointer
DECR5; Are all words compared?
JNZL$1; No, another compare
ExampleThe RAM bytes addressed by EDE and TONI are compared. If they are equal,
* DADC[.W]Add carry decimally to destination
* DADC.BAdd carry decimally to destination
SyntaxDADCdst or DADC.W src,dst
DADC.Bdst
Operationdst + C −> dst (decimally)
EmulationDADD#0,dst
DADD.B#0,dst
DescriptionThe carry bit (C) is added decimally to the destination.
Status BitsN: Set if MSB is 1
Z: Set if dst is 0, reset otherwise
C: Set if destination increments from 9999 to 0000, reset otherwise
Set if destination increments from 99 to 00, reset otherwise
V: Undefined
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe four-digit decimal number contained in R5 is added to an eight-digit deci-
mal number pointed to by R8.
CLRC; Reset carry
; next instruction’s start condition is defined
DADDR5,0(R8); Add LSDs + C
DADC2(R8); Add carry to MSD
ExampleThe two-digit decimal number contained in R5 is added to a four-digit decimal
number pointed to by R8.
CLRC; Reset carry
; next instruction’s start condition is defined
DADD.BR5,0(R8); Add LSDs + C
DADC1(R8); Add carry to MSDs
RISC 16−Bit CPU
3-35
Instruction Set
DADD[.W]Source and carry added decimally to destination
DADD.B Source and carry added decimally to destination
SyntaxDADDsrc,dstor DADD.Wsrc,dst
DADD.Bsrc,dst
Operationsrc + dst + C −> dst (decimally)
DescriptionThe source operand and the destination operand are treated as four binary
coded decimals (BCD) with positive signs. The source operand and the carry
bit (C) are added decimally to the destination operand. The source operand
is not affected. The previous contents of the destination are lost. The result is
not defined for non-BCD numbers.
Status BitsN: Set if the MSB is 1, reset otherwise
Z: Set if result is zero, reset otherwise
C: Set if the result is greater than 9999
Set if the result is greater than 99
V: Undefined
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe eight-digit BCD number contained in R5 and R6 is added decimally to an
eight-digit BCD number contained in R3 and R4 (R6 and R4 contain the
MSDs).
CLRC; clear carry
DADDR5,R3; add LSDs
DADDR6,R4 ; add MSDs with carry
JCOVERFLOW ; If carry occurs go to error handling routine
ExampleThe two-digit decimal counter in the RAM byte CNT is incremented by one.
EmulationSUB.B#1,dst
DescriptionThe destination operand is decremented by one. The original contents are
lost.
Status BitsN: Set if result is negative, reset if positive
Z: Set if dst contained 1, reset otherwise
C: Reset if dst contained 0, set otherwise
V: Set if an arithmetic overflow occurs, otherwise reset.
Set if initial value of destination was 08000h, otherwise reset.
Set if initial value of destination was 080h, otherwise reset.
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleR10 is decremented by 1
DECR10; Decrement R10
; Move a block of 255 bytes from memory location starting with EDE to memory location starting with
;TONI. Tables should not overlap: start of destination address TONI must not be within the range EDE
; to EDE+0FEh
;
MOV#EDE,R6
MOV#255,R10
L$1MOV.B@R6+,TONI−EDE−1(R6)
DECR10
JNZL$1
; Do not transfer tables using the routine above with the overlap shown in Figure 3−12.
EmulationSUB.B#2,dst
DescriptionThe destination operand is decremented by two. The original contents are lost.
Status BitsN: Set if result is negative, reset if positive
Z: Set if dst contained 2, reset otherwise
C: Reset if dst contained 0 or 1, set otherwise
V: Set if an arithmetic overflow occurs, otherwise reset.
Set if initial value of destination was 08001 or 08000h, otherwise reset.
Set if initial value of destination was 081 or 080h, otherwise reset.
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleR10 is decremented by 2.
DECDR10; Decrement R10 by two
; Move a block of 255 words from memory location starting with EDE to memory location
; starting with TONI
; Tables should not overlap: start of destination address TONI must not be within the
; range EDE to EDE+0FEh
;
MOV#EDE,R6
MOV#510,R10
L$1MOV@R6+,TONI−EDE−2(R6)
DECDR10
JNZL$1
ExampleMemory at location LEO is decremented by two.
DECD.BLEO; Decrement MEM(LEO)
Decrement status byte STATUS by two.
DECD.BSTATUS
3-38
RISC 16−Bit CPU
Instruction Set
* DINTDisable (general) interrupts
SyntaxDINT
Operation0 → GIE
or
(0FFF7h .AND. SR → SR/.NOT.src .AND. dst −> dst)
EmulationBIC#8,SR
DescriptionAll interrupts are disabled.
The constant 08h is inverted and logically ANDed with the status register (SR).
The result is placed into the SR.
Status BitsStatus bits are not affected.
Mode BitsGIE is reset. OSCOFF and CPUOFF are not affected.
ExampleThe general interrupt enable (GIE) bit in the status register is cleared to allow
a nondisrupted move of a 32-bit counter. This ensures that the counter is not
modified during the move by any interrupt.
DINT; All interrupt events using the GIE bit are disabled
NOP
MOVCOUNTHI,R5; Copy counter
MOVCOUNTLO,R6
EINT; All interrupt events using the GIE bit are enabled
Note:Disable Interrupt
If any code sequence needs to be protected from interruption, the DINT
should be executed at least one instruction before the beginning of the
uninterruptible sequence, or should be followed by a NOP instruction.
RISC 16−Bit CPU
3-39
Instruction Set
* EINTEnable (general) interrupts
SyntaxEINT
Operation1 → GIE
or
(0008h .OR. SR −> SR / .src .OR. dst −> dst)
EmulationBIS#8,SR
DescriptionAll interrupts are enabled.
The constant #08h and the status register SR are logically ORed. The result
is placed into the SR.
Status BitsStatus bits are not affected.
Mode BitsGIE is set. OSCOFFand CPUOFF are not affected.
ExampleThe general interrupt enable (GIE) bit in the status register is set.
; Interrupt routine of ports P1.2 to P1.7
; P1IN is the address of the register where all port bits are read. P1IFG is the address of
; the register where all interrupt events are latched.
;
PUSH.B&P1IN
BIC.B@SP,&P1IFG; Reset only accepted flags
EINT; Preset port 1 interrupt flags stored on stack
; other interrupts are allowed
BIT#Mask,@SP
JEQMaskOK; Flags are present identically to mask: jump
......
MaskOKBIC#Mask,@SP
......
INCDSP; Housekeeping: inverse to PUSH instruction
; at the start of interrupt subroutine. Corrects
; the stack pointer.
RETI
3-40
Note:Enable Interrupt
The instruction following the enable interrupt instruction (EINT) is always
executed, even if an interrupt service request is pending when the interrupts
are enable.
Operationdst + 1 −> dst
EmulationADD#1,dst
DescriptionThe destination operand is incremented by one. The original contents are lost.
Status BitsN: Set if result is negative, reset if positive
Z: Set if dst contained 0FFFFh, reset otherwise
Set if dst contained 0FFh, reset otherwise
C: Set if dst contained 0FFFFh, reset otherwise
Set if dst contained 0FFh, reset otherwise
V: Set if dst contained 07FFFh, reset otherwise
Set if dst contained 07Fh, reset otherwise
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe status byte, STATUS, of a process is incremented. When it is equal to 11,
EmulationADD.B#2,dst
ExampleThe destination operand is incremented by two. The original contents are lost.
Status BitsN: Set if result is negative, reset if positive
Z: Set if dst contained 0FFFEh, reset otherwise
Set if dst contained 0FEh, reset otherwise
C: Set if dst contained 0FFFEh or 0FFFFh, reset otherwise
Set if dst contained 0FEh or 0FFh, reset otherwise
V: Set if dst contained 07FFEh or 07FFFh, reset otherwise
Set if dst contained 07Eh or 07Fh, reset otherwise
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe item on the top of the stack (TOS) is removed without using a register.
.......
PUSHR5; R5 is the result of a calculation, which is stored
; in the system stack
INCDSP; Remove TOS by double-increment from stack
; Do not use INCD.B, SP is a word-aligned
; register
RET
ExampleThe byte on the top of the stack is incremented by two.
EmulationXOR.B#0FFh,dst
DescriptionThe destination operand is inverted. The original contents are lost.
Status BitsN: Set if result is negative, reset if positive
Z: Set if dst contained 0FFFFh, reset otherwise
Set if dst contained 0FFh, reset otherwise
C: Set if result is not zero, reset otherwise ( = .NOT. Zero)
Set if result is not zero, reset otherwise ( = .NOT. Zero)
V: Set if initial destination operand was negative, otherwise reset
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleContent of R5 is negated (twos complement).
MOV#00AEh,R5 ; R5 = 000AEh
INVR5; Invert R5,R5 = 0FF51h
INCR5; R5 is now negated,R5 = 0FF52h
DescriptionThe status register carry bit (C) is tested. If it is set, the 10-bit signed offset
contained in the instruction LSBs is added to the program counter. If C is reset,
the next instruction following the jump is executed. JC (jump if carry/higher or
same) is used for the comparison of unsigned numbers (0 to 65536).
Status BitsStatus bits are not affected.
ExampleThe P1IN.1 signal is used to define or control the program flow.
BIT#01h,&P1IN; State of signal −> Carry
JCPROGA; If carry=1 then execute program routine A
......; Carry=0, execute program here
ExampleR5 is compared to 15. If the content is higher or the same, branch to LABEL.
CMP#15,R5
JHSLABEL; Jump is taken if R5 ≥ 15
......; Continue here if R5 < 15
3-44
RISC 16−Bit CPU
Instruction Set
JEQ, JZJump if equal, jump if zero
SyntaxJEQlabel,JZlabel
OperationIf Z = 1: PC + 2 × offset −> PC
If Z = 0: execute following instruction
DescriptionThe status register zero bit (Z) is tested. If it is set, the 10-bit signed offset
contained in the instruction LSBs is added to the program counter. If Z is not
set, the instruction following the jump is executed.
Status BitsStatus bits are not affected.
ExampleJump to address TONI if R7 contains zero.
TSTR7; Test R7
JZTONI; if zero: JUMP
ExampleJump to address LEO if R6 is equal to the table contents.
CMPR6,Table(R5); Compare content of R6 with content of
; MEM (table address + content of R5)
JEQLEO; Jump if both data are equal
......; No, data are not equal, continue here
ExampleBranch to LABEL if R5 is 0.
TSTR5
JZLABEL
......
RISC 16−Bit CPU
3-45
Instruction Set
JGEJump if greater or equal
SyntaxJGElabel
OperationIf (N .XOR. V) = 0 then jump to label: PC + 2 × offset −> PC
If (N .XOR. V) = 1 then execute the following instruction
DescriptionThe status register negative bit (N) and overflow bit (V) are tested. If both N
and V are set or reset, the 10-bit signed offset contained in the instruction LSBs
is added to the program counter. If only one is set, the instruction following the
jump is executed.
This allows comparison of signed integers.
Status BitsStatus bits are not affected.
ExampleWhen the content of R6 is greater or equal to the memory pointed to by R7,
the program continues at label EDE.
CMP@R7,R6; R6 ≥ (R7)?, compare on signed numbers
JGEEDE; Yes, R6 ≥ (R7)
......; No, proceed
......
......
3-46
RISC 16−Bit CPU
Instruction Set
JLJump if less
SyntaxJLlabel
OperationIf (N .XOR. V) = 1 then jump to label: PC + 2 × offset −> PC
If (N .XOR. V) = 0 then execute following instruction
DescriptionThe status register negative bit (N) and overflow bit (V) are tested. If only one
is set, the 10-bit signed offset contained in the instruction LSBs is added to the
program counter. If both N and V are set or reset, the instruction following the
jump is executed.
This allows comparison of signed integers.
Status BitsStatus bits are not affected.
ExampleWhen the content of R6 is less than the memory pointed to by R7, the program
continues at label EDE.
CMP@R7,R6; R6 < (R7)?, compare on signed numbers
JLEDE; Yes, R6 < (R7)
......; No, proceed
......
......
RISC 16−Bit CPU
3-47
Instruction Set
JMPJump unconditionally
SyntaxJMPlabel
OperationPC + 2 × offset −> PC
DescriptionThe 10-bit signed offset contained in the instruction LSBs is added to the
program counter.
Status BitsStatus bits are not affected.
Hint:This one-word instruction replaces the BRANCH instruction in the range of
−511 to +512 words relative to the current program counter.
3-48
RISC 16−Bit CPU
Instruction Set
JNJump if negative
SyntaxJNlabel
Operationif N = 1: PC + 2 × offset −> PC
if N = 0: execute following instruction
DescriptionThe negative bit (N) of the status register is tested. If it is set, the 10-bit signed
offset contained in the instruction LSBs is added to the program counter. If N
is reset, the next instruction following the jump is executed.
Status BitsStatus bits are not affected.
ExampleThe result of a computation in R5 is to be subtracted from COUNT. If the result
is negative, COUNT is to be cleared and the program continues execution in
another path.
SUBR5,COUNT; COUNT − R5 −> COUNT
JNL$1; If negative continue with COUNT=0 at PC=L$1
......; Continue with COUNT≥0
......
......
......
L$1CLRCOUNT
......
......
......
RISC 16−Bit CPU
3-49
Instruction Set
JNCJump if carry not set
JLOJump if lower
SyntaxJNClabel
JLOlabel
Operationif C = 0: PC + 2 × offset −> PC
if C = 1: execute following instruction
DescriptionThe status register carry bit (C) is tested. If it is reset, the 10-bit signed offset
contained in the instruction LSBs is added to the program counter. If C is set,
the next instruction following the jump is executed. JNC (jump if no carry/lower)
is used for the comparison of unsigned numbers (0 to 65536).
Status BitsStatus bits are not affected.
ExampleThe result in R6 is added in BUFFER. If an overflow occurs, an error handling
routine at address ERROR is used.
ADDR6,BUFFER; BUFFER + R6 −> BUFFER
JNCCONT; No carry, jump to CONT
ERROR......; Error handler start
......
......
......
CONT......; Continue with normal program flow
......
......
ExampleBranch to STL2 if byte STA TUS contains 1 or 0.
CMP.B#2,STATUS
JLOSTL2; STATUS < 2
......; STATUS ≥ 2, continue here
3-50
RISC 16−Bit CPU
Instruction Set
JNEJump if not equal
JNZJump if not zero
SyntaxJNElabel
JNZlabel
OperationIf Z = 0: PC + 2 × offset −> PC
If Z = 1: execute following instruction
DescriptionThe status register zero bit (Z) is tested. If it is reset, the 10-bit signed offset
contained in the instruction LSBs is added to the program counter. If Z is set,
the next instruction following the jump is executed.
Status BitsStatus bits are not affected.
ExampleJump to address TONI if R7 and R8 have different contents.
CMPR7,R8; COMP ARE R7 WITH R8
JNETONI; if different: jump
......; if equal, continue
RISC 16−Bit CPU
3-51
Instruction Set
MOV[.W]Move source to destination
MOV.B Move source to destination
SyntaxMOVsrc,dst or MOV.W src,dst
MOV.Bsrc,dst
Operationsrc −> dst
DescriptionThe source operand is moved to the destination.
The source operand is not affected. The previous contents of the destination
are lost.
Status BitsStatus bits are not affected.
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe contents of table EDE (word data) are copied to table TOM. The length
of the tables must be 020h locations.
MOV#EDE,R10; Prepare pointer
MOV#020h,R9; Prepare counter
LoopMOV@R10+,TOM−EDE−2(R10); Use pointer in R10 for both tables
* NOPNo operation
SyntaxNOP
OperationNone
EmulationMOV#0, R3
DescriptionNo operation is performed. The instruction may be used for the elimination of
instructions during the software check or for defined waiting times.
Status BitsStatus bits are not affected.
The NOP instruction is mainly used for two purposes:
- To fill one, two, or three memory words
- To adjust software timing
Note:Emulating No-Operation Instruction
Other instructions can emulate the NOP function while providing different
numbers of instruction cycles and code words. Some examples are:
Examples:
MOV#0,R3; 1 cycle, 1 word
MOV0(R4),0(R4); 6 cycles, 3 words
MOV@R4,0(R4); 5 cycles, 2 words
BIC#0,EDE(R4); 4 cycles, 2 words
JMP$+2; 2 cycles, 1 word
BIC#0,R5; 1 cycle, 1 word
However, care should be taken when using these examples to prevent
unintended results. For example, if MOV 0(R4), 0(R4) is used and the value
in R4 is 120h, then a security violation will occur with the watchdog timer
(address 120h) because the security key was not used.
RISC 16−Bit CPU
3-53
Instruction Set
* POP[.W]Pop word from stack to destination
* POP.BPop byte from stack to destination
SyntaxPOPdst
POP.Bdst
Operation@SP −> temp
SP + 2 −> SP
temp −> dst
EmulationMOV@SP+,dst or MOV.W @SP+,dst
EmulationMOV.B@SP+,dst
DescriptionThe stack location pointed to by the stack pointer (TOS) is moved to the
destination. The stack pointer is incremented by two afterwards.
Status BitsStatus bits are not affected.
ExampleThe contents of R7 and the status register are restored from the stack.
POPR7; Restore R7
POPSR; Restore status register
ExampleThe contents of RAM byte LEO is restored from the stack.
POP.BLEO; The low byte of the stack is moved to LEO.
ExampleThe contents of R7 is restored from the stack.
POP.BR7; The low byte of the stack is moved to R7,
; the high byte of R7 is 00h
ExampleThe contents of the memory pointed to by R7 and the status register are
restored from the stack.
POP.B0(R7); The low byte of the stack is moved to the
; the byte which is pointed to by R7
: Example: R7 = 203h
; Mem(R7) = low byte of system stack
: Example:R7 = 20Ah
;Mem(R7) = low byte of system stack
POPSR; Last word on stack moved to the SR
Note:The System Stack Pointer
The system stack pointer (SP) is always incremented by two, independent
of the byte suffix.
3-54
RISC 16−Bit CPU
Instruction Set
PUSH[.W]Push word onto stack
PUSH.BPush byte onto stack
SyntaxPUSHsrc or PUSH.W src
PUSH.Bsrc
OperationSP − 2 → SP
src → @SP
DescriptionThe stack pointer is decremented by two, then the source operand is moved
to the RAM word addressed by the stack pointer (TOS).
Status BitsStatus bits are not affected.
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleThe contents of the status register and R8 are saved on the stack.
PUSHSR; save status register
PUSHR8; save R8
ExampleThe contents of the peripheral TCDAT is saved on the stack.
PUSH.B&TCDAT; save data from 8-bit peripheral module,
; address TCDAT, onto stack
Note:The System Stack Pointer
The system stack pointer (SP) is always decremented by two, independent
of the byte suffix.
RISC 16−Bit CPU
3-55
Instruction Set
* RETReturn from subroutine
SyntaxRET
Operation@SP→ PC
SP + 2 → SP
EmulationMOV@SP+,PC
DescriptionThe return address pushed onto the stack by a CALL instruction is moved to
the program counter. The program continues at the code address following the
subroutine call.
Status BitsStatus bits are not affected.
3-56
RISC 16−Bit CPU
Instruction Set
RETIReturn from interrupt
SyntaxRETI
OperationTOS → SR
SP + 2→ SP
TOS→ PC
SP + 2→ SP
DescriptionThe status register is restored to the value at the beginning of the interrupt
service routine by replacing the present SR contents with the TOS contents.
The stack pointer (SP) is incremented by two.
The program counter is restored to the value at the beginning of interrupt
service. This is the consecutive step after the interrupted program flow.
Restoration is performed by replacing the present PC contents with the TOS
memory contents. The stack pointer (SP) is incremented.
Status BitsN: restored from system stack
Z: restored from system stack
C: restored from system stack
V: restored from system stack
Mode BitsOSCOFF, CPUOFF, and GIE are restored from system stack.
ExampleFigure 3−13 illustrates the main program interrupt.
Figure 3−13. Main Program Interrupt
PC −6
PC −4
PC −2
PC
PC +2
PC +4
PC +6
PC +8
Interrupt Request
Interrupt Accepted
PC+2 is Stored
Onto Stack
PC = PCi
PCi +2
PCi +4
PCi +n−4
PCi +n−2
PCi +n
RETI
RISC 16−Bit CPU
3-57
Instruction Set
* RLA[.W]Rotate left arithmetically
* RLA.B Rotate left arithmetically
SyntaxRLAdstorRLA.Wdst
RLA.Bdst
OperationC <− MSB <− MSB−1 .... LSB+1 <− LSB <− 0
EmulationADDdst,dst
ADD.Bdst,dst
DescriptionThe destination operand is shifted left one position as shown in Figure 3−14.
The MSB is shifted into the carry bit (C) and the LSB is filled with 0. The RLA
instruction acts as a signed multiplication by 2.
An overflow occurs if dst ≥ 04000h and dst < 0C000h before operation is
performed: the result has changed sign.
Figure 3−14. Destination Operand—Arithmetic Shift Left
Word
C
Byte
150
70
An overflow occurs if dst ≥ 040h and dst < 0C0h before the operation is
performed: the result has changed sign.
Status BitsN: Set if result is negative, reset if positive
Z: Set if result is zero, reset otherwise
C: Loaded from the MSB
V: Set if an arithmetic overflow occurs:
the initial value is 04000h ≤ dst < 0C000h; reset otherwise
Set if an arithmetic overflow occurs:
the initial value is 040h ≤ dst < 0C0h; reset otherwise
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleR7 is multiplied by 2.
RLAR7; Shift left R7 (× 2)
ExampleThe low byte of R7 is multiplied by 4.
RLA.BR7; Shift left low byte of R7 (× 2)
RLA.BR7; Shift left low byte of R7 (× 4)
0
3-58
Note:RLA Substitution
The assembler does not recognize the instruction:
RLA@R5+,RLA.B @R5+,orRLA(.B) @R5
It must be substituted by:
ADD @R5+,−2(R5)ADD.B @R5+,−1(R5) orADD(.B) @R5
RISC 16−Bit CPU
Instruction Set
* RLC[.W]Rotate left through carry
* RLC.BRotate left through carry
SyntaxRLCdst orRLC.Wdst
RLC.Bdst
OperationC <− MSB <− MSB−1 .... LSB+1 <− LSB <− C
EmulationADDCdst,dst
DescriptionThe destination operand is shifted left one position as shown in Figure 3−15.
The carry bit (C) is shifted into the LSB and the MSB is shifted into the carry
bit (C).
Figure 3−15. Destination Operand—Carry Left Shift
Word
C
Byte
150
70
Status BitsN: Set if result is negative, reset if positive
Z: Set if result is zero, reset otherwise
C: Loaded from the MSB
V: Set if an arithmetic overflow occurs
the initial value is 04000h ≤ dst < 0C000h; reset otherwise
Set if an arithmetic overflow occurs:
the initial value is 040h ≤ dst < 0C0h; reset otherwise
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleR5 is shifted left one position.
RLCR5; (R5 x 2) + C −> R5
ExampleThe input P1IN.1 information is shifted into the LSB of R5.
BIT.B#2,&P1IN; Information −> Carry
RLCR5; Carry=P0in.1 −> LSB of R5
ExampleThe MEM(LEO) content is shifted left one position.
RLC.BLEO; Mem(LEO) x 2 + C −> Mem(LEO)
Note:RLC and RLC.B Substitution
The assembler does not recognize the instruction:
RLC @R5+,RLC.B @R5+,or RLC(.B) @R5
It must be substituted by:
ADDC @R5+,−2(R5) ADDC.B@R5+,−1(R5) or ADDC(.B) @R5
RISC 16−Bit CPU
3-59
Instruction Set
RRA[.W]Rotate right arithmetically
RRA.BRotate right arithmetically
SyntaxRRAdst orRRA.Wdst
RRA.Bdst
OperationMSB −> MSB, MSB −> MSB−1, ... LSB+1 −> LSB, LSB −> C
DescriptionThe destination operand is shifted right one position as shown in Figure 3−16.
The MSB is shifted into the MSB, the MSB is shifted into the MSB−1, and the
LSB+1 is shifted into the LSB.
Figure 3−16. Destination Operand—Arithmetic Right Shift
Word
C
Byte
150
15
0
Status BitsN: Set if result is negative, reset if positive
Z: Set if result is zero, reset otherwise
C: Loaded from the LSB
V: Reset
Mode BitsOSCOFF, CPUOFF, and GIE are not affected.
ExampleR5 is shifted right one position. The MSB retains the old value. It operates
equal to an arithmetic division by 2.
RRAR5; R5/2 −> R5
;The value in R5 is multiplied by 0.75 (0.5 + 0.25).
;