The LatticeMico8™ is an 8-bit microcontroller optimized for Field Programmable Gate Arrays (FPGAs) and Crossover Programmable Logic Device architectures from Lattice. Combining a full 18-bit wide instruction set with
32 General Purpose registers, the LatticeMico8 is a flexible Verilog reference design suitable for a wide variety of
markets, including communications, consumer, computer, medical, industrial, and automotive. The core consumes
minimal device resources, less than 200 Look Up Tables (LUTs) in the smallest configuration, while maintaining a
broad feature set.
Features
• 8-bit Data Path
• 18-bit Wide Instructions
• 32 General Purpose Registers
• 32 bytes of Internal Scratch Pad Memory
• Input/Output is Performed Using “Ports” (Up to 256 Port Numbers)
• Optional 256 bytes of External Scratch Pad RAM
• Two Cycles Per Instruction
• Lattice UART Reference Design Peripheral
Functional Description
The following figure shows a block diagram of LatticeMico8 microcontroller.
The register file is implemented using dual ported distributed RAM. It contains 32 8-bit entries. Two values can be
simultaneously read from the register file.
Scratch Pad RAM (Internal)
The internal scratch pad memory has 32 entries. It can be addressed directly or indirectly (via a register). Indirect
addressing mode is not available if external scratch pad memory is attached.
Optional External Scratch Pad
The external scratch pad provides an additional 256 bytes of memory. It can be implemented using either distributed RAM or using an EBR. The external scratch pad memory can be addressed via indirect addressing only.
Hardware (Circular) Call Stack
When a call instruction is executed, the address of the next instruction is pushed into the call stack, a ret
(return) instruction will pop the stack and continue execution from the location at the top of the stack.
An interrupt also causes the address of the instruction that would have executed next to be pushed into the call
stack. The reti (return from interrupt) instruction will pop the stack and continue from the location at the top of the
stack.
The stack is implemented as a circular buffer and any program execution will continue from an undefined location in
case of a stack overflow or underflow.
Interrupt Handling
The microcontroller has one interrupt source, which is level sensitive. The interrupt can be enabled or disabled by
software (cli = clear interrupt, sti = set interrupt). When an interrupt is received, the address of the next instruction is pushed into the call stack and the microcontroller continues execution from the interrupt vector (address 0).
The flags (carry and zero) are copied to shadow locations. The interrupt ack line is set high and the acknowledge line is held high for the entire duration of interrupt handling. Once the interrupt has been acknowledged the
interrupt line should be set to 0.
A reti instruction will pop the call stack and transfer control to the address on top of the stack. The Flags (carry
and zero) are restored from the shadow locations. The interrupt acknowledge line is set to low.
The microcontroller cannot handle nested interrupts.
Input/Output
Input and output are done via “ports”. Up to 256 port numbers are allowed. The lower 32 ports can be addressed
directly (using the import and export instructions), or indirectly (using the importi and exporti instructions).
The upper 224 ports can be accessed by indirect addressing only (by the importi and exporti instructions).
The port number (0-31 of import , export and 0-255 for importi and exporti instructions) is presented at the
external interface for two cycles.
For import and importi instructions, the ext_io_rd signal is strobed in the same cycle as the input values are
sampled. The address signal is ext_addr and the input signals are ext_io_din . Both the address and the I/O
read strobe are driven in the second cycle. In the case of the importi instruction, the ext_addr signal is driven
from the register file; otherwise, for the import instruction, it is driven directly from the instruction. Figure 2 shows
the waveform corresponding to a read.
2
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
Figure 2. Microcontroller Read Cycle Using import , importi
For export and exporti instructions, the ext_io_wr signal is strobed in the same cycle as the data out is
driven. Both the ext_io_wr and the ext_dout are driven in the second cycle of instruction execution. Figure 3
shows the waveform corresponding to a write. In the case of the exporti instruction, the ext_addr signal is
driven from the register file; otherwise, for the export instruction, it is driven directly from the instruction.
Figure 3. Microcontroller Write Cycle Using export , exporti
Scratch Pad Memory Access (External)
An optional scratch pad memory of up to 256 bytes can be attached externally to the processor. If external memory
is attached, the internal scratch pad can be accessed by direct addressing only (LSP and SSP instructions). The
external memory can be accessed by indirect addressing only (LSPI and SSPI instructions).
3
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
Instruction Sets
Please note that for all Branch and Call instructions, the signed offset is represented as binary 2’s complement.
ADD RD, Rb
17161514131211109876543210
0100RdRdRdRdRdRbRbRbRbRb000
0
CY Flag UpdatedZero Flag Updated
Ye s
Rd = Rd + Rb (add registers)
The carry flag is updated with the carry out from the addition. The zero flag is set to 1 if all the bits of the result are
0.
ADDI Rd, C
Ye s
17161514131211109876543210
0101RdRdRdRdRdCCCCCCCC
0
CY Flag UpdatedZero Flag Updated
Ye s
Ye s
Rd = Rd + CCCCCCCC (add constant to register)
The carry flag is updated with the carry out from the addition. The zero flag is set to 1 if all the bits of the result are
0.
ADDC Rd, Rb
17161514131211109876543210
0
0110RdRdRdRdRdRbRbRbRbRb000
CY Flag UpdatedZero Flag Updated
Ye s
Ye s
Rd = Rd + Rb + Carry Flag (add registers and carry flag)
The carry flag is updated with the carry out from the addition. The zero flag is set to 1 if all the bits of the result are
0.
ADDIC Rd, CC
17161514131211109876543210
0
0111RdRdRdRdRdCCCCCCCC
CY Flag UpdatedZero Flag Updated
Ye s
Ye s
Rd = Rd + CCCCCCCC + Carry Flag (add register, constant and carry flag)
The carry flag is updated with the carry out from the addition. The zero flag is set to 1 if all the bits of the result are
0.
4
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
SUB Rd, Rb
17161514131211109876543210
00000RdRdRdRdRdRbRbRbRbRb000
CY Flag UpdatedZero Flag Updated
Ye sYe s
Rd = Rd - Rb (subtract register from register)
The carry flag is set to 1 if the result is negative. The zero flag is set to 1 if all the bits of the result are 0.
SUBI Rd, C
17161514131211109876543210
0
0001RdRdRdRdRdCCCCCCCC
CY Flag UpdatedZero Flag Updated
Ye s
Ye s
Rd = Rd - CCCCCCCC (subtract constant from register)
The carry flag is set to 1 if the result is negative. The zero flag is set to 1 if all the bits of the result are 0.
SUBC Rd, Rb
17161514131211109876543210
0
0010RdRdRdRdRdRbRbRbRbRb000
CY Flag UpdatedZero Flag Updated
Ye s
Ye s
Rd = Rd - Rb - Carry Flag (subtract register with carry from register)
The carry flag is set to 1 if the result is negative. The zero flag is set to 1 if all the bits of the result are 0.
SUBIC Rd, C
17161514131211109876543210
00011RdRdRdRdRdCCCCCCCC
CY Flag UpdatedZero Flag Updated
Ye sYe s
Rd = Rd - CCCCCCCC - Carry Flag (subtract constant with carry from register)
The carry flag is set to 1 if the result is negative. The zero flag is set to 1 if all the bits of the result are 0.
5
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
MOV Rd, Rb
17161514131211109876543210
01000RdRdRdRdRdRbRbRbRbRb000
CY Flag UpdatedZero Flag Updated
NoYe s
Rd = Rb (move register to register)
The zero flag is set to 1 if all the bits of the result are 0.
MOVI Rd, C
17161514131211109876543210
01001RdRdRdRdRdCCCCCCCC
CY Flag UpdatedZero Flag Updated
NoYes
Rd = CCCCCCCC (move constant into register)
The zero flag is set to 1 if all the bits of the result are 0.
AND Rd, Rb
17161514131211109876543210
01010RdRdRdRdRdRbRbRbRbRb000
CY Flag UpdatedZero Flag Updated
NoYe s
Rd = Rd and Rb (bitwise AND registers)
The zero flag is set to 1 if all the bits of the result are 0.
ANDI Rd, C
17161514131211109876543210
01011RdRdRdRdRdCCCCCCCC
CY Flag UpdatedZero Flag Updated
NoYe s
Rd = Rd and CCCCCCCC (bitwise AND register with constant)
The zero flag is set to 1 if all the bits of the result are 0.
6
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
OR Rd, Rb
17161514131211109876543210
01100RdRdRdRdRdRbRbRbRbRb000
CY Flag UpdatedZero Flag Updated
NoYe s
Rd = Rd | Rb (bitwise OR registers)
The zero flag is set to 1 if all the bits of the result are 0.
ORI Rd, C
17161514131211109876543210
01101RdRdRdRdRdCCCCCCCC
CY Flag UpdatedZero Flag Updated
NoYe s
Rd = Rd | CCCCCCCC (bitwise OR register with constant)
The zero flag is set to 1 if all the bits of the result are 0.
XOR Rd, Rb
17161514131211109876543210
01110RdRdRdRdRdRbRbRbRbRb000
CY Flag UpdatedZero Flag Updated
NoYe s
Rd = Rd and Rb (bitwise XOR registers)
The zero flag is set to 1 if all the bits of the result are 0.
XORI Rd, CC
17161514131211109876543210
01111RdRdRdRdRdCCCCCCCC
CY Flag UpdatedZero Flag Updated
NoYe s
Rd = Rd and CC (bitwise XOR register with constant)
The zero flag is set to 1 if all the bits of the result are 0.
7
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
CMP Rd, Rb
17161514131211109876543210
10000RdRdRdRdRdRbRbRbRbRb000
CY Flag UpdatedZero Flag Updated
Ye sYe s
Subtract Rb from Rd and update the flags. The result of the subtraction is not written back.
The carry flag is set to 1 if the result is negative. The zero flag is set to 1 if all the bits of the result are 0.
CMPI Rd, C
17161514131211109876543210
10001RdRdRdRdRdCCCCCCCC
CY Flag UpdatedZero Flag Updated
Ye sYe s
Subtract Constant from Rd and update the flags. The result of the subtraction is not written back.
The carry flag is set to 1 if the result is negative. The zero flag is set to 1 if all the bits of the result are 0.
TEST Rd, Rb
17161514131211109876543210
10010RdRdRdRdRdRbRbRbRbRb000
CY Flag UpdatedZero Flag Updated
NoYe s
Perform a bitwise AND between Rd and Rb, update the zero flag. The result of the AND operation is not written
back.
The zero flag is set to 1 if all the bits of the result are 0.
TESTI Rd, CC
17161514131211109876543210
10011RdRdRdRdRdCCCCCCCC
CY Flag UpdatedZero Flag Updated
NoYe s
Perform a bitwise AND between Rd and Constant, update the zero flag. The result of the AND operation is not written back.
The zero flag is set to 1 if all the bits of the result are 0.
8
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
ROR Rd, Rb
17161514131211109876543210
10100RdRdRdRdRdRbRbRbRbRb000
CY Flag UpdatedZero Flag Updated
NoYe s
MSB
Rotate right. Register B is shifted right one bit, the highest order bit is replaced with the lowest order bit. The result
is written back to Register Rd. The zero flag is set to 1 if all the bits of the result are 0.
RORC Rd, Rb
17161514131211109876543210
10100RdRdRdRdRdRbRbRbRbRb001
CY Flag UpdatedZero Flag Updated
Ye sYe s
MSB
C
Rotate right through carry. The contents of Register B are shifted right one bit, the carry flag is shifted into the highest order bit, the lowest order bit is shifted into the carry flag. The zero flag is set to 1 if all the bits of the result are
0.
ROL Rd, Rb
17161514131211109876543210
10100RdRdRdRdRdRbRbRbRbRb010
CY Flag UpdatedZero Flag Updated
NoYe s
MSB
Rotate left. Register B is shifted left by one bit. The highest order bit is shifted into the lowest order bit. The zero flag
is set to 1 if all the bits of the result are 0.
9
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
ROLC Rd, Rb
17161514131211109876543210
10100RdRdRdRdRdRbRbRbRbRb011
CY Flag UpdatedZero Flag Updated
Ye sYe s
C
MSB
Rotate left through carry. Register B is shifted left by one bit. The carry flag is shifted into the lowest order bit and
the highest order bit is shifted into the carry flag. The zero flag is set to 1 if all the bits of the result are 0.
CLRC
17161514131211109876543210
101100000000000000
Carry Flag = 0
Clear carry flag.
SETC
17161514131211109876543210
101100000000000001
Carry Flag = 1
Set carry flag.
CLRZ
17161514131211109876543210
101100000000000010
CY Flag UpdatedZero Flag Updated
Ye sNo
CY Flag UpdatedZero Flag Updated
Ye sNo
CY Flag UpdatedZero Flag Updated
NoYe s
Zero Flag = 0
Clear zero flag.
10
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
SETZ
17161514131211109876543210
101100000000000011
CY Flag UpdatedZero Flag Updated
NoYe s
Zero Flag = 1
Set zero flag.
CLRI
17161514131211109876543210
101100000000000100
CY Flag UpdatedZero Flag Updated
NoNo
Interrupt Enable Flag = 0
Clear interrupt enable flag. Disable interrupts.
SETI
17161514131211109876543210
101100000000000101
CY Flag UpdatedZero Flag Updated
NoNo
Interrupt Enable Flag = 1
Set interrupt enable flag. Enable interrupt.
BZ Label
17161514131211109876543210
11001000LLLLLLLLLL
CY Flag UpdatedZero Flag Updated
NoNo
If Zero Flag = 1 then PC = PC + (Signed Offset of Label). Else PC = PC + 1.
Branch if 0. If zero flag is set, the PC is incremented by the signed offset of the label from the current PC. If zero
flag is 0, then execution continues with the following instruction. The offset can be +/- 512.
11
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
BNZ Label
17161514131211109876543210
11001001LLLLLLLLLL
CY Flag UpdatedZero Flag Updated
NoNo
If Zero Flag = 0 then PC = PC + (Signed Offset of Label). Else PC = PC + 1.
Branch if not 0. If zero flag is not set, the PC is incremented by the signed offset of the label from the current PC. If
zero flag is set, then execution continues with the following instruction. The offset can be +/- 512.
BC Label
17161514131211109876543210
11001010LLLLLLLLLL
CY Flag UpdatedZero Flag Updated
NoNo
If Carry Flag = 1 then PC = PC + (Signed Offset of Label). Else PC = PC + 1.
Branch if carry. If carry flag is set, the PC is incremented by the signed offset of the label from the current PC. If
carry flag is not set, then execution continues with the following instruction. The offset can be +/- 512.
BNC Label
17161514131211109876543210
11001011LLLLLLLLLL
CY Flag UpdatedZero Flag Updated
NoNo
If Carry Flag = 0 then PC = PC + (Signed Offset of Label). Else PC = PC + 1.
Branch if not carry. If carry flag is not set, the PC is incremented by the signed offset of the label from the current
PC. If carry flag is set, then execution continues with the following instruction. The offset can be +/- 512.
B Label
17161514131211109876543210
11001100LLLLLLLLLL
CY Flag UpdatedZero Flag Updated
NoNo
Unconditional Branch. PC = PC + Signed Offset of Label
Unconditional branch. PC is incremented by the signed offset of the label from the current PC. The offset can be +/-
512.
12
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
CALLZ Label
17161514131211109876543210
11011000LLLLLLLLLL
CY Flag UpdatedZero Flag Updated
NoNo
If Zero Flag = 1, then
Push PC + 1 into Call Stack
PC = PC + Signed Offset of LABEL
Else, PC = PC + 1
CALL if 0. If the zero flag is set, the address of the next instruction (PC+1) is pushed into the call stack and the PC
is incremented by the signed offset of the label from the current PC. If zero flag is not set, then execution continues
from the following instruction.
CALLNZ Label
17161514131211109876543210
11011001LLLLLLLLLL
CY Flag UpdatedZero Flag Updated
NoNo
If Zero Flag = 0, then
Push PC + 1 into Call Stack
PC = PC + Signed Offset of LABEL.
Else PC = PC + 1
CALL if NOT 0. If the zero flag is not set, the address of the next instruction (PC+1) is pushed into the call stack,
and the PC is incremented by the signed offset of the label from the current PC. If the zero flag is set, then execution continues from the following instruction.
CALLC Label
17161514131211109876543210
11011010LLLLLLLLLL
CY Flag UpdatedZero Flag Updated
NoNo
If Carry Flag = 1, then
Push PC + 1 into Call Stack
PC = PC + Signed Offset of LABEL.
Else, PC = PC + 1
CALL if carry. If the carry flag is set, the address of the next instruction (PC+1) is pushed into the call stack, and the
PC is incremented by the signed offset of the label from the current PC. If the carry flag is not set, then execution
continues from the following instruction.
13
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
CALLNC Label
17161514131211109876543210
11011011LLLLLLLLLL
CY Flag UpdatedZero Flag Updated
NoNo
If Carry Flag = 0, then
Push PC + 1 into Call Stack
PC = PC + Signed Offset of LABEL
Else, PC = PC + 1
CALL if not carry. If the carry flag is set, the address of the next instruction (PC+1) is pushed into the call stack, and
the PC is incremented by the signed offset of the label from the current PC. If the carry flag is not set, then execution continues from the following instruction.
CALL Label
17161514131211109876543210
11011100LLLLLLLLLL
CY Flag UpdatedZero Flag Updated
NoNo
Push PC + 1 into Call Stack
PC = PC + Signed offset of LABEL
Unconditional call. Address of the next instruction (PC+1) is pushed into the call stack, and the PC is incremented
by the signed offset of the label from the current PC.
RET
17161514131211109876543210
111010000000000000
CY Flag UpdatedZero Flag Updated
NoNo
PC = Top of Call Stack
Pop Call Stack
Unconditional return. PC is set to the value on the top of the call stack. The call stack is popped.
IRET
17161514131211109876543210
111010000000000001
PC = Top of Call Stack
Pop Call Stack
CY Flag UpdatedZero Flag Updated
NoNo
14
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
Restore Zero and Carry Flags from shadow locations
Return from interrupt. In addition to popping the call stack, the carry and zero flags are restored from shadow locations.
IMPORT Rd, Port#
17161514131211109876543210
11110RdRdRdRdRdPPPPP001
CY Flag UpdatedZero Flag Updated
NoNo
Rd = Value from Port (Port#)
Read value from port number (Port#) and write into register Rd. Port # can be 0-31.
IMPORTI Rd, Rb
17161514131211109876543210
11110RdRdRdRdRdRbRbRbRbRb011
CY Flag UpdatedZero Flag Updated
NoNo
Rd = Value from Port # in Register Rb
Indirect read of port. Value is read from port number in register Rb. Port number can be 0-255.
EXPORT Rd, Port#
17161514131211109876543210
11110RdRdRdRdRdPPPPP000
CY Flag UpdatedZero Flag Updated
NoNo
Port Value(Port#) = Rd
Output value of Register D to Port#. Port# can be 0-31.
EXPORTI Rd, Rb
17161514131211109876543210
11110RdRdRdRdRdRbRbRbRbRb010
CY Flag UpdatedZero Flag Updated
NoNo
Port Value(Rb) = Rd
Output value of Register D to Port# designated by Register B. Port# can be 0-255.
15
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
LSP Rd, SS
17161514131211109876543210
11110RdRdRdRdRdSSSSS101
CY Flag UpdatedZero Flag Updated
NoNo
Rd = Scratch Pad(SS)
Load from scratch pad memory direct. Load the value from the scratch pad location designated by constant SS into
Register D. SS can be 0-31.
LSPI Rd, Rb
17161514131211109876543210
11110RdRdRdRdRdRbRbRbRbRb111
CY Flag UpdatedZero Flag Updated
NoNo
Rd = Scratch Pad (Rb)
Load from scratch pad memory indirect. Load the value from the scratch pad location designated by Register B into
Register D. The location address can be 0-255.
SSP Rd, SS
17161514131211109876543210
11110RdRdRdRdRdSSSSS100
CY Flag UpdatedZero Flag Updated
NoNo
Scratch Pad (SS) = Rd
Store into scratch pad memory direct. Store value of register D into scratch pad memory location designated by
constant SS. The location address can be 0-31.
SSPI Rd, Rb
17161514131211109876543210
11110RdRdRdRdRdRbRbRbRbRb110
CY Flag UpdatedZero Flag Updated
NoNo
Scratch Pad (Rb) = Rd
Store into scratch pad memory indirect. Store value of register D, into scratch pad memory location designated by
register B. The location address can be 0-255.
16
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
Configuration Options
The LatticeMico8 microcontroller has the following configurable features:
• Register File size: LatticeMico8 can be configured to have 16 or 32 registers. Default configuration is 32 8-bit
registers. Un-commenting the line `define REGISTERS_16, will configure the micro-controller with 16 registers.
Note: the Assembler will allow registers 16 through 31 to be used.
• Internal Scratch Pad memory size: Default configuration is 32 bytes. Un-commenting the `define
SCRATCH_PAD_MEM_16, will configure the controller to have 16 bytes of internal scratch pad memory.
• External memory interface: The external memory interface can be optionally enabled. This allows for adding an
extra 256 bytes of memory to the microcontroller. By default this is not available, un-commenting the line `define
EXT_SP_MEM will enable this feature.
I/O Configurations
Table 1. I/O with No External Scratch Pad Memory
NameIn/OutWidth (bits)Description
clkIn1Clock
rst_nIn1Reset active low
ext_io_dinIn8Input data for import
intrIn1Interrupt active high
ext_addrOut8Address for import/export
ext_doutOut8Output data for export
ext_io_wrOut1High for export
ext_io_rdOut1High for import
intr_ackOut1Interrupt acknowledge active high
Table 2. I/O with 256 Bytes External Scratch Pad Memory
NameIn/OutWidth (bits)Description
ext_mem_dinIn8Input from external scratch pad
ext_mem_wrOut1High indicates write to external memory
ext_mem_rdOut1High indicates read from external memory
When `define EXT_SP_MEM is set, three extra ports are added to the controller to communicate with the external
scratch pad memory. The ext_dout is used to write data into the external memory. The address bus ext_addr is
also shared.
Assembler and Instruction Set Simulator
The software tools for the LatticeMico8 microcontroller include an Assembler and an Instruction Set Simulator, both
developed in C. The purpose of the Assembler is to generate an Embedded Block RAM (EBR) initialization file from
a text assembler input file. The purpose of the Simulator is to execute a program in the host environment. This section describes the use of these tools.
Assembler
The assembler reads in a text assembler source file (default extension .s) and creates one of the following as output:
• Hexadecimal output file (can be used by Module Manager)
• Binary output file (can be used by Module Manager)
17
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
• Verilog initialization file (included in design before synthesis)
In addition to these outputs, the Assembler can also generate an assembler listing file.
-o <filename>Fully qualified name of the output file.
-s <Program Rom Size>Default 512 bytes
-lGenerate listing file. The listing file is generated in the same directory as the
source with the extension .lst.
-vx Generate output in hexadecimal (default)
-vb Generate output in binary
-veGenerate output in Verilog “INIT” format
-?Help message
Instructions
The Assembler supports all instructions as described in the Instruction Set section.
Pseudo-Ops
The Assembler supports the following pseudo-ops:
OptionComment
nopExpanded by the Assembler to mov R0,R0. An instruction without side effects.
Labels
Label definitions are any character sequences ending in a ‘:’. No other instruction or Assembler directives are
allowed in the same line as a label definition.
The Assembler allows both forward and backward references to a label (i.e. it is legal to reference a label before it
is defined). Both references in the following example are valid.
BackLabel:
...
...
bBackLabel
...
...
bForwardLabel
...
...
ForwardLabel:
Comments
The character ‘#’ is used as the start of a comment. Everything following the comment character until a new line is
ignored by the Assembler.
Constants
The assembler accepts constants in various formats.
• Hexadecimal values: Hexadecimal constants must be prefixed with “0x” or “0X”. (e.g. 0xFF, 0x12, and 0XAB are
all valid hexadecimal constants).
18
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
• Octal values: Octal values must be prefixed with the numeric character ‘0’. (e.g. 077, 066, and 012 are valid
octal constants).
• Character constants: Single character constants must be enclosed in single quotation marks. (e.g. ‘A’, ‘v’, ‘9’
are all valid character constants).
• Decimal constants: Any sequence of decimal numbers can be a valid constant. (e.g. 123, 255, 231 are valid
decimal constants).
• Location counter: The special character $ (dollar sign) is used to give the current value of the location counter.
Note: The hexadecimal, octal, and decimal constants can be optionally prefixed with a ‘+’ or ‘-’ sign.
Assembler Directives
In addition to the instructions described in the Instruction Set section, the Assembler also supports the following
directives. An Assembler directive must be prefixed with a ‘.’ character.
• .org: This directive allows code to be placed at specific addresses. The syntax for this directive is:
.org <constant>
The constant can be of any form described in the previous section. The Assembler will terminate with an error, if
the .org directive is given a location which is less than the current “local counter” value.
• .equ: This directive can be used to assign symbolic names to constants. The syntax of the directive is:
Although Lattice provides precompiled binary files, the source is available for compilation. The following commands
should be used in the Unix and Windows environments.
• Unix and Cygwin Environments:
gcc -o isp8asm isp8asm.c
• Windows Environment:
cl -o isp8asm_win isp8asm.c
Instruction Set Simulator
The software tools for LatticeMico8 include an Instruction Set Simulator for the microcontroller which allows programs developed for the microcontroller to be run and debugged on a host platform. The Simulator can also be
used to generate a disassembly listing of a LatticeMico8 program. The Simulator takes as input the memory output
file of the Assembler. It emulates the instruction execution of the LatticeMico8 in software. Please note that the
Simulator does not handle interrupts.
-x Use external scratch pad memory. Refer to the Functional Description section of
this document for details.
-ixProgram file is in hexadecimal format (default). This is the file generated by the
Assembler with the -vx options (default).
-ibProgram file is in binary format. This is the file generated by the Assembler with the
-vb option.
-tTrace the execution of the program. The Simulator will generate a trace as it executes each instruction. It will also print the modified value of any register (if the
instruction modifies a register value).
-dGenerate a disassembly of the program specified by the PROM file.
Simulator Interactions
The import, importi and export, exporti instructions can be used to interact with the simulator. When an
export, exporti instruction is executed, the simulator will print the value of the port number as well as the con-
tents of the exported register. If the port number is 0xFF, the simulator will terminate with an exit code identical to
the value of the exported register. When an import, importi instruction is executed, the simulator will issue a
prompt containing the port number and read in values from the standard input (stdin). The following figure shows
an example of a traced simulation.
Although Lattice provides precompiled binary files, the source is available for compilation. The following commands
should be used in the Unix and Windows environments.
• Unix and Cygwin Environments:
gcc -o isp8sim isp8sim.c
• Windows Environment:
cl -o isp8sim_win isp8sim.c
Example
To display the features and capabilities of the LatticeMico8, a demonstration example is also available. It demonstrates the interaction between the timer and the controller and the interrupt capability.
# This program will allow user to run a fibonacci number
# generator and updown counter. This program responds to
# the interrupt from the user (through Orcastra).
# When there is an interrupt, the program will halt the current program,
# and execute the int_handler function. When the intr_handler function
# is done, the program will continue from its last position
b int_handler
nop
nop
seti# set the program to be able to receive interrupt
nop
nop
b start
21
LatticeMico8 Microcontroller
Lattice SemiconductorUser’s Guide
start:
import r5, 5
mov r6, r5
andi r5, 0xf0# masking r5 to decide type of program
mov r7, r5
mov r5, r6
andi r5, 0x0f# masking r5 to get the speed
mov r25, r5