The KS57C2308/C2316 single-chip CMOS microcontroller has been designed for high performance using
Samsung's newest 4-bit CPU core, SAM47 (Samsung Arrangeable Microcontrollers).
With features such as LCD direct drive capability, 8-bit timer/counter, and serial I/O, the KS57C2308/C2316 offer
an excellent design solution for a wide variety of applications that require LCD functions.
Up to 40 pins of the 80-pin QFP package can be dedicated to I/O. Six vectored interrupts provide fast response
to internal and external events. In addition, the KS57C2308/C2316's advanced CMOS technology provides for
low power consumption and a wide operating voltage range.
OTP
The KS57C2308/C2316 microcontroller is also available in OTP (One Time Programmable) version,
KS57P2308/P2316. KS57P2308/P2316 microcontroller has an on-chip 8/16-Kbyte one-time-programmable
EPROM instead of masked ROM. The KS57P2308/P2316 is comparable to KS57C2308/C2316, both in function
and in pin configuration.
1-1
PRODUCT OVERVIEWKS57C2308/P2308/C2316/P2316
FEATURES
Memory
–512 × 4-bit RAM
–8 K × 8-bit ROM (KS57C2308/P2308)
–16 K × 8-bit ROM (KS57C2316/P2316)
–Idle mode (only CPU clock stops)
–Stop mode (main or sub system oscillation stops)
Oscillation Sources
–Crystal, ceramic, or RC for main system clock
–Crystal or external oscillator for subsystem clock
–Main system clock frequency: 4.19 MHz (typical)
–Subsystem clock frequency: 32.768 kHz
–CPU clock divider circuit (by 4, 8, or 64)
Instruction Execution Times
–0.95, 1.91, 15.3 µs at 4.19 MHz (main)
–122 µs at 32.768 kHz (subsystem)
–Real-time and interval time measurement
–Four frequency outputs to BUZ pin
–Clock source generation for LCD
8-Bit Serial I/O Interface
–8-bit transmit/receive mode
–8-bit receive only mode
–LSB-first or MSB-first transmission selectable
–Internal or external clock source
display expansion
TCL0I/OExternal clock input for timer/counter 027P1.3InputA-1
TCLO0I/OTimer/counter 0 clock output28P2.0InputD
SIISerial interface data input23P0.3InputA-1
SOI/OSerial interface data output22P0.2Input
SCK
INT0
INT1
I/OSerial I/O interface clock signal21P0.1Input
IExternal interrupts. The triggering edge for
INT0 and INT1 is selectable. Only INT0 is
24
25
P1.0
P1.1
InputA-1
D
D
synchronized with the system clock.
INT2IQuasi-interrupt with detection of rising edge
26P1.2InputA-1
signals.
INT4IExternal interrupt input with detection of rising
20P0.0InputA-1
or falling edge
KS0–KS7I/OQuasi-interrupt inputs with falling edge
44–51P6.0–P7.3Input
D
detection.
CLOI/OCPU clock output30P2.2InputD
BUZI/O2, 4, 8 or 16 kHz frequency output for buzzer
31P2.3InputD
sound with 4.19 MHz main system clock or
32.768 kHz subsystem clock.
X
IN,
X
OUT
XT
IN,
XT
OUT
V
DD
V
SS
RESET
TEST–
–Crystal, ceramic or RC oscillator pins for main
15,14–––
system clock. (For external clock input, use
XIN and input XIN‘s reverse phase to X
–Crystal oscillator pins for subsystem clock.
OUT
)
17,18–––
(For external clock input, use XTIN and input
XTIN's reverse phase to XT
OUT
)
–Main power supply12–––
–Ground13–––
–Reset signal19–InputB
Test signal input (must be connected to VSS)
16–––
*
*
*
NOTES:
1.Pull-up resistors for all I/O ports are automatically disabled if they are configured to output mode.
2.D * Type has a schmitt trigger circuit at input.
1-6
KS57C2308/P2308/C2316/P2316PRODUCT OVERVIEW
PIN CIRCUIT DIAGRAMS
V
DD
IN
Figure 1-3. Pin Circuit Type A
V
DD
PULL-UP
RESISTOR
P-CHANNEL
P-CHANNEL
N-CHNNEL
RESISTOR
ENABLE
DATA
OUTPUT
DISABLE
Figure 1-5. Pin Circuit Type C
RESISTOR
ENABLE
V
DD
P-CHANNEL
N-CHANNEL
V
DD
PULL-UP
RESISTOR
P-CHANNEL
OUT
IN
SCHMITT TRIGGER
Figure 1-4. Pin Circuit Type A-1 (P1, P0.0, P0.3)
DATA
OUTPUT
DISABLE
CIRCUIT
TYPE C
CIRCUIT TYPE A
Figure 1-6. Pin Circuit Type D
(P0.1, P0.2, P2, P3, P6, P7)
I/O
1-7
PRODUCT OVERVIEWKS57C2308/P2308/C2316/P2316
RESISTOR
V
DD
PNE
DATA
P-CH
PULL-UP
V
DD
RESISTOR
ENABLE
I/O
V
DD
V
LC0
V
LC1
OUTPUT
N-CH
ENABLE
CIRCUIT TYPE A
Figure 1-7. Pin Circuit Type E (P4, P5)
V
LC0
V
LC1
LCD SEGMENT/
COMMON DATA
V
LC2
OUT
LCD SEGMENT/
& PORT 8 DATA
V
LC2
Figure 1-9. Pin Circuit Type H-16 (P8)
V
DD
IN
OUT
Figure 1-8. Pin Circuit Type H-15 (SEG/COM)
1-8
SCHMITT TRIGGER
Figure 1-10. Pin Circuit Type B (RESET)
KS57C2308/P2308/C2316/P2316ADDRESS SPACES
2ADDRESS SPACES
PROGRAM MEMORY (ROM)
OVERVIEW
ROM maps for KS57C2 308/C2316 devices are mask programmable at the factory. KS57C2308 has 8K × 8-bit
program memory and KS57C2316 has 16K × 8-bit program memory, aside from the differences in the ROM size
the two products are identical in other features. In its standard configuration, the device's 8,192 × 8-bit (16,384 ×
8-bit) program memory has four areas that are directly addressable by the program counter (PC):
— 12-byte area for vector addresses
— 96-byte instruction reference area
— 20-byte general-purpose area
— 8064-byte general-purpose area (KS57C2308)
— 16256-byte general-purpose area (KS57C2316)
General-Purpose Program Memory
Two program memory areas are allocated for general-purpose use: One area is 20 bytes in size and the other is
8,064-bytes (16,256-bytes).
Vector Addresses
A 12-byte vector address area is used to store the vector addresses required to execute system resets and
interrupts. Start addresses for interrupt service routines are stored in this area, along with the values of the
enable memory bank (EMB) and enable register bank (ERB) flags that are used to set their initial value for the
corresponding service routines. The 16-byte area can be used alternately as general-purpose ROM.
REF Instructions
Locations 0020H–007FH are used as a reference area (look-up table) for 1-byte REF instructions. The REF
instruction reduces the byte size of instruction operands. REF can reference one 2-byte instruction, two 1-byte
instructions, and one 3-byte instruction which are stored in the look-up table. Unused look-up table addresses can
be used as general-purpose ROM.
Table 2-1. Program Memory Address Ranges
ROM Area FunctionAddress RangesArea Size (in Bytes)
Vector address area0000H–000BH12
General-purpose program memory000CH–001FH20
REF instruction look-up table area0020H–007FH96
General-purpose program memory0080H–1FFFH (KS57C2308)
0080H–3FFFH (KS57C2316)
8064 (KS57C2308)
16256 (KS57C2316)
2-1
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
GENERAL-PURPOSE MEMORY AREAS
The 20-byte area at ROM locations 000CH–001FH and the 8,064-byte (16,256-byte) area at ROM locations
0080H–1FFFH (0080H–3FFFH) are used as general-purpose program memory. Unused locations in the vector
address area and REF instruction look-up table areas can be used as general-purpose program memory.
However, care must be taken not to overwrite live data when writing programs that use special-purpose areas of
the ROM.
VECTOR ADDRESS AREA
The 12-byte vector address area of the ROM is used to store the vector addresses for executing system resets
and interrupts. The starting addresses of interrupt service routines are stored in this area, along with the enable
memory bank (EMB) and enable register bank (ERB) flag values that are needed to initialize the service routines.
12-byte vector addresses are organized as follows:
EMBERB
PC13
(note)
PC12PC11PC10PC9PC8
PC7PC6PC5PC4PC3PC2PC1PC0
NOTE: PC13 is used for KS57C2316/P2316 microcontroller.
To set up the vector address area for specific programs, use the instruction VENTn. The programming tips on the
next page explain how to do this.
0000H
VECTOR ADDRESS AREA
000BH
000CH
001FH
0020H
007FH
0080H
(12 Bytes)
GENERAL-PURPOSE AREA
(20 Bytes)
INSTRUCTION
REFERENCE
AREA
0000H
0002H
0004H
0006H
76543210
RESET
INTB/INT4
INT0
INT1
2-2
GENERAL-PURPOSE AREA
(8,064 Bytes/
16,256 Bytes)
1FFFH
3FFFH
Figure 2-1. ROM Address Structure
0008H
INTS
000AH
INTT0
Figure 2-2. Vector Address Structure
KS57C2308/P2308/C2316/P2316ADDRESS SPACES
++ PROGRAMMING TIP — Defining Vectored Interrupts
The following examples show you several ways you can define the vectored interrupt and instruction reference
areas in program memory:
1. When all vector interrupts are used:
ORG0000H
VENT01,0,RESET; EMB ← 1, ERB ← 0; Jump to RESET address by RESET
VENT10,0,INTB; EMB ← 0, ERB ← 0; Jump to INTB address by INTB
VENT20,0,INT0; EMB ← 0, ERB ← 0; Jump to INT0 address by INT0
VENT30,0,INT1; EMB ← 0, ERB ← 0; Jump to INT1 address by INT1
VENT40,0,INTS; EMB ← 0, ERB ← 0; Jump to INTS address by INTS
VENT50,0,INTT0; EMB ← 0, ERB ← 0; Jump to INTT0 address by INTT0
2. When a specific vectored interrupt such as INT0, and INTT0 is not used, the unused vector interrupt
locations must be skipped with the assembly instruction ORG so that jumps will address the correct locations:
ORG0000H
VENT01,0,RESET; EMB ← 1, ERB ← 0; Jump to RESET address by RESET
VENT10,0,INTB; EMB ← 0, ERB ← 0; Jump to INTB address by INTB
ORG0006H; INT0 interrupt not used
VENT30,0,INT1; EMB ← 0, ERB ← 0; Jump to INT1 address by INT1
VENT40,0,INTS; EMB ← 0, ERB ← 0; Jump to INTS address by INTS
ORG000CH; INTT0 interrupt not used
ORG0010H
3. If an INT0 interrupt is not used and if its corresponding vector interrupt area is not fully utilized, or if it is not
written by a ORG instruction in Example 2, a CPU malfunction will occur:
ORG0000H
VENT01,0,RESET; EMB ← 1, ERB ← 0; Jump to RESET address by RESET
VENT10,0,INTB; EMB ← 0, ERB ← 0; Jump to INTB address by INTB
VENT30,0,INT1; EMB ← 0, ERB ← 0; Jump to INT1 address by INT0
VENT40,0,INTS; EMB ← 0, ERB ← 0; Jump to INTS address by INT1
VENT50,0,INTT0; EMB ← 0, ERB ← 0; Jump to INTT0 address by INTS
ORG0010H
General-purpose ROM area
In this example, when an INTS interrupt is generated, the corresponding vector area is not VENT4 INTS, but
VENT5 INTT0. This causes an INTS interrupt to jump incorrectly to the INTT0 address and causes a CPU
malfunction to occur.
2-3
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
INSTRUCTION REFERENCE AREA
Using 1-byte REF instructions, you can easily reference instructions with larger byte sizes that are stored in
addresses 0020H–007FH of program memory. This 96-byte area is called the REF instruction reference area, or
look-up table. Locations in the REF look-up table may contain two 1-byte instructions, one 2-byte instruction, or
one 3-byte instruction such as a JP (jump) or CALL. The starting address of the instruction you are referencing
must always be an even number. To reference a JP or CALL instruction, it must be written to the reference area
in a two-byte format: for JP, this format is TJP; for CALL, it is TCALL.
By using REF instructions you can execute instructions larger than one byte, In summary, there are three ways
you can use the REF instruction:
— Using the 1-byte REF instruction to execute one 2-byte or two 1-byte instructions,
— Branching to any location by referencing a branch instruction stored in the look-up table,
— Calling subroutines at any location by referencing a call instruction stored in the look-up table.
++ PROGRAMMING TIP — Using the REF Look-Up Table
Here is one example of how to use the REF instruction look-up table:
ORG0020H
JMAINTJPMAIN; 0, MAIN
KEYCKBTSFKEYFG; 1, KEYFG CHECK
WATCHTCALLCLOCK; 2, CALL CLOCK
INCHLLD@HL,A; 3, (HL) ← A
INCSHL
•
•
•
ABCLDEA,#00H; 47, EA ← #00H
ORG0080H
MAINNOP
NOP
•
•
•
REFKEYCK; BTSF KEYFG (1-byte instruction)
REFJMAIN; KEYFG = 1, jump to MAIN (1-byte instruction)
In its standard configuration, the 512 x 4-bit data memory has four areas:
— 32 × 4-bit working register area in bank 0
— 224 × 4-bit general-purpose area in bank 0 which is also used as the stack area
— 224 × 4-bit general-purpose area in bank 1
— 32 × 4-bit area for LCD data in bank 1
— 128 × 4-bit area in bank 15 for memory-mapped I/O addresses
To make it easier to reference, the data memory area has three memory banks — bank 0, bank 1 and bank 15.
The select memory bank instruction (SMB) is used to select the bank you want to select as working data memory.
Data stored in RAM locations are 1-, 4-, and 8-bit addressable. One exception is the LCD data register area,
which is 1-bit and 4-bit addressable only.
Initialization values for the data memory area are not defined by hardware and must therefore be initialized by
program software following power RESET. However, when RESET signal is generated in power-down mode, the
most of data memory contents are held.
000H
01FH
020H
0FFH
100H
1DFH
1E0H
1FFH
F80H
FFFH
WORKING REGISTERS
(32 x 4 Bits)
GENERAL-PURPOSE
REGISTERS AND
STACK AREA
(224 x 4 Bits)
GENERAL-PURPOSE
REGISTERS
(224 x 4 Bits)
LCD DATA REGISTERS
(32 x 4 Bits)
MEMORY-MAPPED I/O
AEERESS REGISTERS
(128 x 4 Bits)
BANK 0
BANK 1
~~
BANK 15
Figure 2-3. Data Memory (RAM) Map
2-5
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
Memory Banks 0, 1, and 15
Bank 0(000H–0FFH)The lowest 32 nibbles of bank 0 (000H–01FH) are used as working registers;
the next 224nibbles (020H–0FFH) can be used both as stack area and as
general-purpose data memory. Use the stack area for implementing subroutine
calls and returns, and for interrupt processing.
Bank 1(100H–1FFH)The lowest 224 nibbles of bank1 (100H–1DFH) are for general–purpose use;
Use the remaining of 32 nibbles (1E0H–1FFH) as display registers or as
general purpose memory.
Bank 15(F80H–FFFH)The microcontroller uses bank 15 for memory-mapped peripheral I/O. Fixed
RAM locations for each peripheral hardware address are mapped into this
area.
Data Memory Addressing Modes
The enable memory bank (EMB) flag controls the addressing mode for data memory banks 0, 1 or 15. When the
EMB flag is logic zero, the addressable area is restricted to specific locations, depending on whether direct or
indirect addressing is used. With direct addressing, you can access locations 000H–07FH of bank 0 and bank 15.
With indirect addressing, only bank 0 (000H–0FFH) can be accessed. When the EMB flag is set to logic one, all
three data memory banks can be accessed according to the current SMB value.
For 8-bit addressing, two 4-bit registers are addressed as a register pair. Also, when using 8-bit instructions to
address RAM locations, remember to use the even-numbered register address as the instruction operand.
Working Registers
The RAM working register area in data memory bank 0 is further divided into four register banks (bank 0, 1, 2,
and 3). Each register bank has eight 4-bit registers and paired 4-bit registers are 8-bit addressable.
Register A is used as a 4-bit accumulator and register pair EA as an 8-bit extended accumulator. The carry flag
bit can also be used as a 1-bit accumulator. Register pairs WX, WL, and HL are used as address pointers for
indirect addressing. To limit the possibility of data corruption due to incorrect register addressing, it is advisable
to use register bank 0 for the main program and banks 1, 2, and 3 for interrupt service routines.
LCD Data Register Area
Bit values for LCD segment data are stored in data memory bank 1. Register locations in this area that are not
used to store LCD data can be assigned to general-purpose use.
2-6
KS57C2308/P2308/C2316/P2316ADDRESS SPACES
Table 2-2. Data Memory Organization and Addressing
AddressesRegister AreasBankEMB ValueSMB Value
000H–01FHWorking registers00, 10
020H–0FFHStack and general-purpose registers
100H–1DFHGeneral-purpose registers111
1E0H–1FFHLCD Data registers
F80H–FFFHI/O-mapped hardware registers150, 115
++ PROGRAMMING TIP — Clearing Data Memory Banks 0 and 1
Clear banks 0 and 1 of the data memory area:
RAMCLRSMB1; RAM (100H–1FFH) clear
LDHL,#00H
LDA,#0H
RMCL1LD@HL,A
INCSHL
JRRMCL1
SMB0; RAM (010H–0FFH) clear
LDHL,#10H
RMCL0LD@HL,A
INCSHL
JRRMCL0
2-7
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
WORKING REGISTERS
Working registers, mapped to RAM address 000H-01FH in data memory bank 0, are used to temporarily store
intermediate results during program execution, as well as pointer values used for indirect addressing. Unused
registers may be used as general-purpose memory. Working register data can be manipulated as 1-bit units, 4-bit
units or, using paired registers, as 8-bit units.
DATA
MEMORY
BANK 0
000H
001H
002H
003H
004H
005H
006H
007H
008H
00FH
010H
017H
018H
01FH
A
E
L
H
X
W
Z
Y
A
Y
...
A
Y
...
A
Y
...
WORKING
REGISTER
BANK 0
REGISTER
BANK 1
REGISTER
BANK 2
REGISTER
BANK 3
2-8
Figure 2-4. Working Register Map
KS57C2308/P2308/C2316/P2316ADDRESS SPACES
Working Register Banks
For addressing purposes, the working register area is divided into four register banks — bank 0, bank 1, bank 2,
and bank 3. Any one of these banks can be selected as the working register bank by the register bank selection
instruction (SRB n) and by setting the status of the register bank enable flag (ERB).
Generally, working register bank 0 is used for the main program, and banks 1, 2, and 3 for interrupt service
routines. Following this convention helps to prevent possible data corruption during program execution due to
contention in register bank addressing.
Table 2-3. Working Register Organization and Addressing
ERB SettingSRB SettingsSelected Register Bank
3210
000––Always set to bank 0
00Bank 0
10001Bank 1
10Bank 2
11Bank 3
Paired Working Registers
Each of the register banks is subdivided into eight 4-bit registers. These registers, named Y, Z, W, X, H, L, E and
A, can either be manipulated individually using 4-bit instructions, or together as register pairs for 8-bit data
manipulation.
The names of the 8-bit register pairs in each register bank are EA, HL, WX, YZ and WL. Registers A, L, X and Z
always become the lower nibble when registers are addressed as 8-bit pairs. This makes a total of eight 4-bit
registers or four 8-bit double registers in each of the four working register banks.
(MSB)
(LSB)(MSB)(LSB)
YZ
WX
HL
EA
Figure 2-5. Register Pair Configuration
2-9
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
Special-Purpose Working Registers
Register A is used as a 4-bit accumulator and double register EA as an 8-bit accumulator. The carry flag can also
be used as a 1-bit accumulator.
8-bit double registers WX, WL and HL are used as data pointers for indirect addressing. When the HL register
serves as a data pointer, the instructions LDI, LDD, XCHI, and XCHD can make very efficient use of working
registers as program loop counters by letting you transfer a value to the L register and increment or decrement it
using a single instruction.
C
A
EA
1-BIT
ACCUMULATOR
4-BIT
ACCUMULATOR
8-BIT
ACCUMULATOR
Figure 2-6. 1-Bit, 4-Bit, and 8-Bit Accumulator
Recommendation for Multiple Interrupt Processing
If more than four interrupts are being processed at one time, you can avoid possible loss of working register data
by using the PUSH RR instruction to save register contents to the stack before the service routines are executed
in the same register bank. When the routines have executed successfully, you can restore the register contents
from the stack to working memory using the POP instruction.
2-10
KS57C2308/P2308/C2316/P2316ADDRESS SPACES
++ PROGRAMMING TIP — Selecting the Working Register Area
The following examples show the correct programming method for selecting working register area:
1. When ERB = "0":
VENT2 1,0,INT0; EMB ← 1, ERB ← 0, Jump to INT0 address
INT0PUSHSB; PUSH current SMB, SRB
SRB2; Instruction does not execute because ERB = "0"
PUSHHL; PUSH HL register contents to stack
PUSHWX; PUSH WX register contents to stack
PUSHYZ; PUSH YZ register contents to stack
PUSHEA; PUSH EA register contents to stack
SMB0
LDEA,#00H
LD80H,EA
LDHL,#40H
INCSHL
LDWX,EA
LDYZ,EA
POPEA; POP EA register contents from stack
POPYZ; POP YZ register contents from stack
POPWX; POP WX register contents from stack
POPHL; POP HL register contents from stack
POPSB; POP current SMB, SRB
IRET
The POP instructions execute alternately with the PUSH instructions. If an SMB n instruction is used in an
interrupt service routine, a PUSH and POP SB instruction must be used to store and restore the current SMB and
SRB values, as shown in Example 2 below.
2. When ERB = "1":
VENT2 1,1,INT0; EMB ← 1, ERB ← 1, Jump to INT0 address
INT0PUSHSB; Store current SMB, SRB
SRB2; Select register bank 2 because of ERB = "1"
SMB0
LDEA,#00H
LD80H,EA
LDHL,#40H
INCSHL
LDWX,EA
LDYZ,EA
POPSB; Restore SMB, SRB
IRET
2-11
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
STACK OPERATIONS
STACK POINTER (SP)
The stack pointer (SP) is an 8-bit register that stores the address used to access the stack, an area of data
memory set aside for temporary storage of data and addresses. The SP can be read or written by 8-bit control
instructions. When addressing the SP, bit 0 must always remain cleared to logic zero.
F80HSP3SP2SP1"0"
F81HSP7SP6SP5SP4
There are two basic stack operations: writing to the top of the stack (push), and reading from the top of the stack
(pop). A push decrements the SP and a pop increments it so that the SP always points to the top address of the
last data to be written to the stack.
The program counter contents and program status word are stored in the stack area prior to the execution of a
CALL or a PUSH instruction, or during interrupt service routines. Stack operation is a LIFO (Last In-First Out)
type. The stack area is located in general-purpose data memory bank 0.
During an interrupt or a subroutine, the PC value and the PSW are saved to the stack area. When the routine has
completed, the stack pointer is referenced to restore the PC and PSW, and the next instruction is executed.
The SP can address stack registers in bank 0 (addresses 000H-0FFH) regardless of the current value of the
enable memory bank (EMB) flag and the select memory bank (SMB) flag. Although general-purpose register
areas can be used for stack operations, be careful to avoid data loss due to simultaneous use of the same
register(s).
Since the RESET value of the stack pointer is not defined in firmware, we recommend that you initialize the stack
pointer by program code to location 00H. This sets the first register of the stack area to 0FFH.
NOTE
A subroutine call occupies six nibbles in the stack; an interrupt requires six. When subroutine nesting or
interrupt routines are used continuously, the stack area should be set in accordance with the maximum
number of subroutine levels. To do this, estimate the number of nibbles that will be used for the
subroutines or interrupts and set the stack area correspondingly.
++ PROGRAMMING TIP — Initializing the Stack Pointer
To initialize the stack pointer (SP):
1. When EMB = "1":
SMB15; Select memory bank 15
LDEA,#00H; Bit 0 of SP is always cleared to "0"
LDSP,EA; Stack area initial address (0FFH) ← (SP) – 1
2. When EMB = "0":
LDEA,#00H
LDSP,EA; Memory addressing area (00H–7FH, F80H–FFFH)
2-12
KS57C2308/P2308/C2316/P2316ADDRESS SPACES
PUSH OPERATIONS
Three kinds of push operations reference the stack pointer (SP) to write data from the source register to the
stack: PUSH instructions, CALL instructions, and interrupts. In each case, the SP is decreased by a number
determined by the type of push operation and then points to the next available stack location.
PUSH Instructions
A PUSH instruction references the SP to write two 4-bit data nibbles to the stack. Two 4-bit stack addresses are
referenced by the stack pointer: one for the upper register value and another for the lower register. After the
PUSH has executed, the SP is decreased by two and points to the next available stack location.
CALL Instructions
When a subroutine call is issued, the CALL instruction references the SP to write the PC's contents to six 4-bit
stack locations. Current values for the enable memory bank (EMB) flag and the enable register bank (ERB) flag
are also pushed to the stack. Since six 4-bit stack locations are used per CALL, you may nest subroutine calls up
to the number of levels permitted in the stack.
Interrupt Routines
An interrupt routine references the SP to push the contents of the PC and the program status word (PSW) to the
stack. Six 4-bit stack locations are used to store this data. After the interrupt has executed, the SP is decreased
by six and points to the next available stack location. During an interrupt sequence, subroutines may be nested
up to the number of levels which are permitted in the stack area.
PUSH
(After PUSH, SP SP - 2)
SP - 2
SP - 1
SP
LOWER
UPPER
: PC13 is used for KS57C2316/P2316 microcontroller
NOTE
CALL
(After CALL, SP SP - 6)
SP - 6
SP - 5
SP - 4
SP - 3
SP - 2
SP - 1
SP
PC11- PC8
00
00EMB ERB
0000
PC13 PC12PC13 PC12
PC3 - PC0
PC7 - PC4
PSW
SP - 6
SP - 5
SP - 4
SP - 3
SP - 2
SP - 1
SP
Figure 2-7. Push-Type Stack Operations
INTERRUP
(When INT is acknowledged,
SP SP - 6)
PC11 - PC8
00
PC3 - PC0
PC7 - PC4
IS1IS0 EMB ERB
PSW
CSC2 SC1 SC0
2-13
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
POP OPERATIONS
For each push operation there is a corresponding pop operation to write data from the stack back to the source
register or registers: for the PUSH instruction it is the POP instruction; for CALL, the instruction RET or SRET; for
interrupts, the instruction IRET. When a pop operation occurs, the SP is incremented by a number determined by
the type of operation and points to the next free stack location.
POP Instructions
A POP instruction references the SP to write data stored in two 4-bit stack locations back to the register pairs and
SB register. The value of the lower 4-bit register is popped first, followed by the value of the upper 4-bit register.
After the POP has executed, the SP is incremented by two and points to the next free stack location.
RET and SRET Instructions
The end of a subroutine call is signaled by the return instruction, RET or SRET. The RET or SRET uses the SP
to reference the six 4-bit stack locations used for the CALL and to write this data back to the PC, the EMB, and
the ERB. After the RET or SRET has executed, the SP is incremented by six and points to the next free stack
location.
IRET Instructions
The end of an interrupt sequence is signaled by the instruction IRET. IRET references the SP to locate the six
4-bit stack addresses used for the interrupt and to write this data back to the PC and the PSW. After the IRET
has executed, the SP is incremented by six and points to the next free stack location.
SP
SP + 1
SP + 2
NOTE
POP
SP SP + 2)
LOWER
UPPER
: PC13 is used for KS57C2316/P2316 microcontroller
SP
SP + 1
SP + 2
SP + 3
SP + 4
SP + 5
SP + 6
RET OR SRET
SP SP + 6)
PC11 – PC8
00
00EMB ERB
0000
PC13 PC12PC13 PC12
PC3 – PC0
PC7 – PC4
PSW
Figure 2-8. Pop-Type Stack Operations
SP
SP + 1
SP + 2
SP + 3
SP + 4
SP + 5
SP + 6
IRET
SP SP + 6)
PC11 – PC8
00
PC3 – PC0
PC7 – PC4
IS1IS0 EMB ERB
PSW
CSC2 SC1 SC0
2-14
KS57C2308/P2308/C2316/P2316ADDRESS SPACES
BIT SEQUENTIAL CARRIER (BSC)
The bit sequential carrier (BSC) is a 16-bit general register that can be manipulated using 1-, 4-, and 8-bit RAM
control instructions. RESET clears all BSC bit values to logic zero.
Using the BSC, you can specify sequential addresses and bit locations using 1-bit indirect addressing
(memb.@L). (Bit addressing is independent of the current EMB value.) In this way, programs can process 16-bit
data by moving the bit location sequentially and then incrementing or decreasing the value of the L register.
BSC data can also be manipulated using direct addressing. For 8-bit manipulations, the 4-bit register names
BSC0 and BSC2 must be specified and the upper and lower 8 bits manipulated separately.
If the values of the L register are 0H at BSC0.@L, the address and bit location assignment is FC0H.0. If the L
register content is FH at BSC0.@L, the address and bit location assignment is FC3H.3.
++ PROGRAMMING TIP — Using the BSC Register to Output 16-Bit Data
To use the bit sequential carrier (BSC) register to output 16-bit data (5937H) to the P3.0 pin:
BITSEMB
SMB15
LDEA,#37H;
LDBSC0,EA; BSC0 ← A, BSC1 ← E
LDEA,#59H;
LDBSC2,EA; BSC2 ← A, BSC3 ← E
SMB0
LDL,#0H;
AGNLDBC,BSC0.@L;
LDBP3.0,C; P3.0 ← C
INCSL
JRAGN
RET
2-15
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
PROGRAM COUNTER (PC)
A 13-bit program counter (PC) stores addresses for instruction fetches during program execution (KS57C2316
microcontroller has 14-bit program counter, PC0–PC13). Whenever a reset operation or an interrupt occurs, bits
PC12 through PC0 (PC13 through PC0 for KS57C2316) are set to the vector address.
Usually, the PC is incremented by the number of bytes of the instruction being fetched. One exception is the
1-byte REF instruction which is used to reference instructions stored in the ROM.
PROGRAM STATUS WORD (PSW)
The program status word (PSW) is an 8-bit word that defines system status and program execution status and
which permits an interrupted process to resume operation after an interrupt request has been serviced. PSW
values are mapped as follows:
(MSB)(LSB)
FB0HIS1IS0EMBERB
FB1HCSC2SC1SC0
The PSW can be manipulated by 1-bit or 4-bit read/write and by 8-bit read instructions, depending on the specific
bit or bits being addressed. The PSW can be addressed during program execution regardless of the current value
of the enable memory bank (EMB) flag.
Part or all of the PSW is saved to stack prior to execution of a subroutine call or hardware interrupt. After the
interrupt has been processed, the PSW values are popped from the stack back to the PSW address.
When a RESET is generated, the EMB and ERB values are set according to the RESET vector address, and the
carry flag is left undefined (or the current value is retained). PSW bits IS0, IS1, SC0, SC1, and SC2 are all
cleared to logical zero.
Table 2-5. Program Status Word Bit Descriptions
PSW Bit IdentifierDescriptionBit AddressingRead/Write
IS1, IS0Interrupt status flags1, 4R/W
EMBEnable memory bank flag1R/W
ERBEnable register bank flag1R/W
CCarry flag1R/W
SC2, SC1, SC0Program skip flags8R
2-16
KS57C2308/P2308/C2316/P2316ADDRESS SPACES
INTERRUPT STATUS FLAGS (IS0, IS1)
PSW bits IS0 and IS1 contain the current interrupt execution status values. You can manipulate IS0 and IS1
flags directly using 1-bit RAM control instructions
By manipulating interrupt status flags in conjunction with the interrupt priority register (IPR), you can process
multiple interrupts by anticipating the next interrupt in an execution sequence. The interrupt priority control circuit
determines the IS0 and IS1 settings in order to control multiple interrupt processing. When both interrupt status
flags are set to "0", all interrupts are allowed. The priority with which interrupts are processed is then determined
by the IPR.
When an interrupt occurs, IS0 and IS1 are pushed to the stack as part of the PSW and are automatically
incremented to the next higher priority level. Then, when the interrupt service routine ends with an IRET
instruction, IS0 and IS1 values are restored to the PSW. Table 2-6 shows the effects of IS0 and IS1 flag settings.
Table 2-6. Interrupt Status Flag Bit Settings
IS1
Value
000All interrupt requests are serviced
011Only high-priority interrupt(s) as determined in the
102No more interrupt requests are serviced
11–Not applicable; these bit settings are undefined
Since interrupt status flags can be addressed by write instructions, programs can exert direct control over
interrupt processing status. Before interrupt status flags can be addressed, however, you must first execute a DI
instruction to inhibit additional interrupt routines. When the bit manipulation has been completed, execute an EI
instruction to re-enable interrupt processing.
IS0
Value
Status of Currently
Executing Process
Effect of IS0 and IS1 Settings
on Interrupt Request Control
interrupt priority register (IPR) are serviced
++ PROGRAMMING TIP — Setting ISx Flags for Interrupt Processing
The following instruction sequence shows how to use the IS0 and IS1 flags to control interrupt processing:
INTBDI; Disable interrupt
BITRIS1; IS1 ← 0
BITSIS0; Allow interrupts according to IPR priority level
EI; Enable interrupt
2-17
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
EMB FLAG (EMB)
The EMB flag is used to allocate specific address locations in the RAM by modifying the upper 4 bits of 12-bit
data memory addresses. In this way, it controls the addressing mode for data memory banks 0, 1 or 15.
When the EMB flag is "0", the data memory address space is restricted to bank 15 and addresses 000H–07FH of
memory bank 0, regardless of the SMB register contents. When the EMB flag is set to "1", the general-purpose
areas of bank 0, 1 and 15 can be accessed by using the appropriate SMB value.
++ PROGRAMMING TIP — Using the EMB Flag to Select Memory Banks
EMB flag settings for memory bank selection:
1. When EMB = "0":
SMB1; Non-essential instruction since EMB = "0"
LDA,#9H
LD90H,A; (F90H) ← A, bank 15 is selected
LD34H,A; (034H) ← A, bank 0 is selected
SMB0; Non-essential instruction since EMB = "0"
LD90H,A; (F90H) ← A, bank 15 is selected
LD34H,A; (034H) ← A, bank 0 is selected
SMB15; Non-essential instruction, since EMB = "0"
LD20H,A; (020H) ← A, bank 0 is selected
LD90H,A; (F90H) ← A, bank 15 is selected
2. When EMB = "1":
SMB1; Select memory bank 1
LDA,#9H
LD90H,A; (190H) ← A, bank 1 is selected
LD34H,A; (134H) ← A, bank 1 is selected
SMB0; Select memory bank 0
LD90H,A; (090H) ← A, bank 0 is selected
LD34H,A; (034H) ← A, bank 0 is selected
SMB15; Select memory bank 15
LD20H,A; Program error, but assembler does not detect it
LD90H,A; (F90H) ← A, bank 15 is selected
2-18
KS57C2308/P2308/C2316/P2316ADDRESS SPACES
ERB FLAG (ERB)
The 1-bit register bank enable flag (ERB) determines the range of addressable working register area. When the
ERB flag is "1", the working register area from register banks 0 to 3 is selected according to the register bank
selection register (SRB). When the ERB flag is "0", register bank 0 is the selected working register area,
regardless of the current value of the register bank selection register (SRB).
When an internal RESET is generated, bit 6 of program memory address 0000H is written to the ERB flag. This
automatically initializes the flag. When a vectored interrupt is generated, bit 6 of the respective address table in
program memory is written to the ERB flag, setting the correct flag status before the interrupt service routine is
executed.
During the interrupt routine, the ERB value is automatically pushed to the stack area along with the other PSW
bits. Afterwards, it is popped back to the FB0H.0 bit location. The initial ERB flag settings for each vectored
interrupt are defined using VENTn instructions.
++ PROGRAMMING TIP — Using the ERB Flag to Select Register Banks
ERB flag settings for register bank selection:
1. When ERB = "0":
SRB1; Register bank 0 is selected (since ERB = "0", the
LDEA,#34H; Bank 0 EA ← #34H
LDHL,EA; Bank 0 HL ← EA
SRB2; Register bank 0 is selected
LDYZ,EA; Bank 0 YZ ← EA
SRB3; Register bank 0 is selected
LDWX,EA; Bank 0 WX ← EA
2. When ERB = "1":
SRB1; Register bank 1 is selected
LDEA,#34H; Bank 1 EA ← #34H
LDHL,EA; Bank 1 HL ← Bank 1 EA
SRB2; Register bank 2 is selected
LDYZ,EA; Bank 2 YZ ← BANK2 EA
SRB3; Register bank 3 is selected
LDWX,EA; Bank 3 WX ← Bank 3 EA
; SRB is configured to bank 0)
2-19
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
SKIP CONDITION FLAGS (SC2, SC1, SC0)
The skip condition flags SC2, SC1, and SC0 in the PSW indicate the current program skip conditions and are set
and reset automatically during program execution. Skip condition flags can only be addressed by 8-bit read
instructions. Direct manipulation of the SC2, SC1, and SC0 bits is not allowed.
CARRY FLAG (C)
The carry flag is used to save the result of an overflow or borrow when executing arithmetic instructions involving
a carry (ADC, SBC). The carry flag can also be used as a 1-bit accumulator for performing Boolean operations
involving bit-addressed data memory.
If an overflow or borrow condition occurs when executing arithmetic instructions with carry (ADC, SBC), the carry
flag is set to "1". Otherwise, its value is "0". When a RESET occurs, the current value of the carry flag is retained
during power-down mode, but when normal operating mode resumes, its value is undefined.
The carry flag can be directly manipulated by predefined set of 1-bit read/write instructions, independent of other
bits in the PSW. Only the ADC and SBC instructions, and the instructions listed in Table 2-7, affect the carry flag.
Table 2-7. Valid Carry Flag Manipulation Instructions
Operation TypeInstructionsCarry Flag Manipulation
Direct manipulationSCFSet carry flag to "1"
RCFClear carry flag to "0" (reset carry flag)
CCFInvert carry flag value (complement carry flag)
BTST CTest carry and skip if C = "1"
Bit transfer
Boolean manipulation
LDB (operand)
LDB C,(operand)
BAND C,(operand)
(1)
,C
(1)
(1)
Load carry flag value to the specified bit
Load contents of the specified bit to carry flag
AND the specified bit with contents of carry flag and save
the result to the carry flag
BOR C,(operand)
(1)
OR the specified bit with contents of carry flag and save
the result to the carry flag
BXOR C,(operand)
(1)
XOR the specified bit with contents of carry flag and save
the result to the carry flag
Interrupt routine
INTn
(2)
Save carry flag to stack with other PSW bits
Return from interruptIRETRestore carry flag from stack with other PSW bits
NOTES:
1.The operand has three bit addressing formats: mema.a, memb.@L, and @H + DA.b.
2.“INTn” refers to the specific interrupt being executed and is not an instruction.
2-20
KS57C2308/P2308/C2316/P2316ADDRESS SPACES
++ PROGRAMMING TIP — Using the Carry Flag as a 1-Bit Accumulator
1. Set the carry flag to logic one:
SCF; C ← 1
LDEA,#0C3H; EA ← #0C3H
LDHL,#0AAH; HL ← #0AAH
ADCEA,HL; EA ← #0C3H + #0AAH + #1H, C ← 1
2. Logical-AND bit 3 of address 3FH with P3.3 and output the result to P4.0:
LDH,#3H; Set the upper four bits of the address to the H register
value
LDBC,@H+0FH.3; C ← bit 3 of 3FH
BANDC,P3.3; C ← C AND P3.3
LDBP4.0,C; Output result from carry flag to P4.0
2-21
ADDRESS SPACESKS57C2308/P2308/C2316/P2316
NOTES
2-22
KS57C2308/P2308/C2316/P2316ADDRESSING MODES
3ADDRESSING MODES
OVERVIEW
The enable memory bank flag, EMB, controls the two addressing modes for data memory. When the EMB flag is
set to logic one, you can address the entire RAM area; when the EMB flag is cleared to logic zero, the
addressable area in the RAM is restricted to specific locations.
The EMB flag works in connection with the select memory bank instruction, SMB n. You will recall that the SMB
n instruction is used to select RAM bank 0, 1 or 15. The SMB setting is always contained in the upper four bits of
a 12-bit RAM address. For this reason, both addressing modes (EMB = "0" and EMB = "1") apply specifically to
the memory bank indicated by the SMB instruction, and any restrictions to the addressable area within banks 0, 1
or 15. Direct and indirect 1-bit, 4-bit, and 8-bit addressing methods can be used. Several RAM locations are
addressable at all times, regardless of the current EMB flag setting.
Here are a few guidelines to keep in mind regarding data memory addressing:
— When you address peripheral hardware locations in bank 15, the mnemonic for the memory-mapped
hardware component can be used as the operand in place of the actual address location.
— Always use an even-numbered RAM address as the operand in 8-bit direct and indirect addressing.
— With direct addressing, use the RAM address as the instruction operand; with indirect addressing, the
instruction specifies a register which contains the operand's address.
3-1
ADDRESSING MODESKS57C2308/P2308/C2316/P2316
000H
01FH
020H
07FH
080H
0FFH
100H
1DFH
1E0H
RAM
Areas
Working
Registers
BANK 0
(General
Registers and
Stack)
BANK 1
(General
Registers)
Addressing
Mode
DA
DA.b
EMB = 0EMB = 1XXX
EMB = 1EMB = 0
SMB = 0SMB = 0
SMB = 1SMB = 1
@HL
@H + DA.b
@WX
@WL
mema.bmemb.@L
1FFH
F80H
FFFH
BANK 1
(Display Registers)SMB = 1SMB = 1
BANK 15
(Peripheral
Hardware
Registers)
NOTES
1. 'X' means don't care.
2. Blank columns indicate RAM areas that are not addressable, given the addressing method
and enable memory bank (EMB) flag setting shown in the column headers.
SMB = 15SMB = 15
FB0H
FBFH
FC0H
FF0H
Figure 3-1. RAM Address Structure
3-2
KS57C2308/P2308/C2316/P2316ADDRESSING MODES
EMB AND ERB INITIALIZATION VALUES
The EMB and ERB flag bits are set automatically by the values of the RESET vector address and the interrupt
vector address. When a RESET is generated internally, bit 7 of program memory address 0000H is written to the
EMB flag, initializing it automatically. When a vectored interrupt is generated, bit 7 of the respective vector
address table is written to the EMB. This automatically sets the EMB flag status for the interrupt service routine.
When the interrupt is serviced, the EMB value is automatically saved to stack and then restored when the
interrupt routine has completed.
At the beginning of a program, the initial EMB and ERB flag values for each vectored interrupt must be set by
using VENT instruction. The EMB and ERB can be set or reset by bit manipulation instructions (BITS, BITR)
despite the current SMB setting.
++ PROGRAMMING TIP — Initializing the EMB and ERB Flags
The following assembly instructions show how to initialize the EMB and ERB flag settings:
When the enable memory bank flag EMB is set to logic one, you can address the data memory bank specified by
the select memory bank (SMB) value (0, 1 or 15) using 1-, 4-, or 8-bit instructions. You can use both direct and
indirect addressing modes. The addressable RAM areas when EMB = "1" are as follows:
If SMB = 0,000H–0FFH
If SMB = 1,100H–1FFH
If SMB = 15,F80H–FFFH
EMB = "0"
When the enable memory bank flag EMB is set to logic zero, the addressable area is defined independently of
the SMB value, and is restricted to specific locations depending on whether a direct or indirect address mode is
used.
If EMB = "0", the addressable area is restricted to locations 000H–07FH in bank 0 and to locations F80H–FFFH
in bank 15 for direct addressing. For indirect addressing, only locations 000H–0FFH in bank 0 are addressable,
regardless of SMB value.
To address the peripheral hardware register (bank 15) using indirect addressing, the EMB flag must first be set to
"1" and the SMB value to "15". When a RESET occurs, the EMB flag is set to the value contained in bit 7 of ROM
address 0000H.
EMB-Independent Addressing
At any time, several areas of the data memory can be addressed independent of the current status of the EMB
flag. These exceptions are described in Table 3-1.
Table 3-1. RAM Addressing Not Affected by the EMB Value
A,@WX
and WL register pairs;
8-bit indirect addressing using SP
FB0H–FBFH
1-bit direct addressingPSW, SCMOD,
FF0H–FFFH
FC0H–FFFH1-bit indirect addressing using the
L register
IEx, IRQx, I/O
BSC, I/OBTST
PUSH
POP
BITS
BITR
BAND
EA
EA
EMB
IE4
FC3H.@L
C,P3.@L
3-4
KS57C2308/P2308/C2316/P2316ADDRESSING MODES
SELECT BANK REGISTER (SB)
The select bank register (SB) is used to assign the memory bank and register bank. The 8-bit SB register
consists of the 4-bit select register bank register (SRB) and the 4-bit select memory bank register (SMB), as
shown in Figure 3-2.
During interrupts and subroutine calls, SB register contents can be saved to stack in 8-bit units by the PUSH SB
instruction. You later restore the value to the SB using the POP SB instruction.
SMB (F83H)SRB (F82H)
SB
REGISTER
SMB 3SMB 2SMB 1SMB 000SRB 1SRB 0
Figure 3-2. SMB and SRB Values in the SB Register
Select Register Bank (SRB) Instruction
The select register bank (SRB) value specifies which register bank is to be used as a working register bank. The
SRB value is set by the “SRB n” instruction, where n = 0, 1, 2, 3.
One of the four register banks is selected by the combination of ERB flag status and the SRB value that is set
using the “SRB n” instruction. The current SRB value is retained until another register is requested by program
software. PUSH SB and POP SB instructions are used to save and restore the contents of SRB during interrupts
and subroutine calls. RESET clears the 4-bit SRB value to logic zero.
Select Memory Bank (SMB) Instruction
To select one of the four available data memory banks, you must execute an SMB n instruction specifying the
number of the memory bank you want (0, 1 or 15). For example, the instruction “SMB 1” selects bank 1 and
“SMB 15” selects bank 15. (And remember to enable the selected memory bank by making the appropriate EMB
flag setting.
The upper four bits of the 12-bit data memory address are stored in the SMB register. If the SMB value is not
specified by software (or if a RESET does not occur) the current value is retained. RESET clears the 4-bit SMB
value to logic zero.
The PUSH SB and POP SB instructions save and restore the contents of the SMB register to and from the stack
area during interrupts and subroutine calls.
3-5
ADDRESSING MODESKS57C2308/P2308/C2316/P2316
DIRECT AND INDIRECT ADDRESSING
1-bit, 4-bit, and 8-bit data stored in data memory locations can be addressed directly using a specific register or
bit address as the instruction operand.
Indirect addressing specifies a memory location that contains the required direct address. The KS57 instruction
set supports 1-bit, 4-bit, and 8-bit indirect addressing. For 8-bit indirect addressing, an even-numbered RAM
address must always be used as the instruction operand.
1-BIT ADDRESSING
Table 3-2. 1-Bit Direct and Indirect RAM Addressing
Operand
Notation
Addressing Mode
Description
DA.bDirect: a bit is indicated by the
RAM address (DA), memory
bank selection, and a the
specified bit number (b).
mema.bDirect: a bit is indicated by the
addressable area (mema) and
a the bit number (b).
memb.@LIndirect: a bit is indicated by
the addressable area
(memb.7–2 (upper) + L.3–2
(lower)) and the bit number
(L.1–0).
@H + DA.bIndirect: a bit is indicated by
the addressable area (H
(upper) + DA.3–0 (lower)) ,
memory bank selection, and
the bit number (b).
SMB15; Non-essential instruction, since EMB = "0"
LDA,P3; A ← (P3)
SMB0; Non-essential instruction, since EMB = "0"
LDADATA,A; (046H) ← A
LDBDATA,A; (F8EH (LCON)) ← A
2. If EMB = "1":
ADATA EQU46H
BDATA EQU8EH
SMB15
LDA,P3; A ← (P3)
SMB0
LDADATA,A; (046H) ← A
LDBDATA,A; (08EH) ← A
3-8
KS57C2308/P2308/C2316/P2316ADDRESSING MODES
++PROGRAMMING TIP — 4-Bit Addressing Modes (Continued)
4-Bit Indirect Addressing (Example 1)
1. If EMB = "0", compare bank 0 locations 040H–046H with bank 0 locations 060H–066H:
ADATA EQU46H
BDATA EQU66H
SMB1; Non-essential instruction, since EMB = "0"
LDHL,#BDATA
LDWX,#ADATA
COMPLDA,@WL; A ← bank 0 (040H–046H)
CPSEA,@HL; If bank 0 (060H–066H) = A, skip
SRET
DECSL
JRCOMP
RET
2. If EMB = "1", compare bank 0 locations 040H–046H to bank 1 locations 160H–166H:
ADATA EQU46H
BDATA EQU66H
SMB1
LDHL,#BDATA
LDWX,#ADATA
COMPLDA,@WL; A ← bank 0 (040H–046H)
CPSEA,@HL; If bank 1 (160H–166H) = A, skip
SRET
DECSL
JRCOMP
RET
3-9
ADDRESSING MODESKS57C2308/P2308/C2316/P2316
4-Bit Indirect Addressing (Example 2)
1. If EMB = "0", exchange bank 0 locations 040H–046H with bank 0 locations 060H–066H:
ADATA EQU46H
BDATA EQU66H
SMB1; Non-essential instruction, since EMB = "0"
LDHL,#BDATA
LDWX,#ADATA
TRANS LDA,@WL; A ← bank 0 (040H–046H)
XCHDA,@HL; Bank 0 (060H–066H) ↔ A
JRTRANS
2. If EMB = "1", exchange bank 0 locations 040H–046H to bank 1 locations 160H–166H:
ADATA EQU46H
BDATA EQU66H
SMB1
LDHL,#BDATA
LDWX,#ADATA
TRANS LDA,@WL; A ← bank 0 (040H–046H)
XCHDA,@HL; Bank 1 (160H–166H) ↔ A
JRTRANS
3-10
KS57C2308/P2308/C2316/P2316ADDRESSING MODES
8-BIT ADDRESSING
Table 3-4. 8-Bit Direct and Indirect RAM Addressing
Instruction
Notation
DADirect: 8-bit address indicated
@HLIndirect: the 8-bit address indi-
Addressing Mode
Description
by the RAM address (DA =
even number) and memory
bank selection
cated by the memory bank
selection and register HL; (the
4-bit L register value must be
an even number)
EMB Flag
Setting
++ PROGRAMMING TIP — 8-Bit Addressing Modes
Addressable
Area
000H–07FHBank 0–
0F80H–FFFHBank 15All 8-bit
1000H–FFFHSMB = 0, 1,
0000H–0FFHBank 0–
1000H–FFFHSMB = 0, 1,
Memory
15
15
Bank
Hardware I/O
Mapping
addressable
peripherals
(SMB = 15)
All 8-bit
addressable
peripherals
(SMB = 15)
8-Bit Direct Addressing
1. If EMB = "0":
ADATA EQU46H
BDATA EQU8EH
SMB15; Non-essential instruction, since EMB = "0"
LDEA,P4; E ← (P5), A ← (P4)
SMB0
LDADATA,EA; (046H) ← A, (047H) ← E
LDBDATA,EA; (F8EH) ← A, (F8FH) ← E
2. If EMB = "1":
ADATA EQU46H
BDATA EQU8EH
SMB15
LDEA,P4; E ← (P5), A ← (P4)
SMB0
LDADATA,EA; (046H) ← A, (047H) ← E
LDBDATA,EA; (08EH) ← A, (08FH) ← E
3-11
ADDRESSING MODESKS57C2308/P2308/C2316/P2316
++PROGRAMMING TIP — 8-Bit Addressing Modes (Continued)
8-Bit Indirect Addressing
1. If EMB = "0":
ADATA EQU46H
SMB1; Non-essential instruction, since EMB = "0"
LDHL,#ADATA
LDEA,@HL; A ← (046H), E ← (047H)
2. If EMB = "1":
ADATA EQU46H
SMB1
LDHL,#ADATA
LDEA,@HL; A ← (146H), E ← (147H)
3-12
KS57C2308/P2308/C2316/P2316MEMORY MAP
4MEMORY MAP
OVERVIEW
To support program control of peripheral hardware, I/O addresses for peripherals are memory-mapped to bank
15 of the RAM. Memory mapping lets you use a mnemonic as the operand of an instruction in place of the
specific memory location.
Access to bank 15 is controlled by the select memory bank (SMB) instruction and by the enable memory bank
flag (EMB) setting. If the EMB flag is "0", bank 15 can be addressed using direct addressing, regardless of the
current SMB value. 1-bit direct and indirect addressing can be used for specific locations in bank 15, regardless
of the current EMB value.
I/O MAP FOR HARDWARE REGISTERS
Table 4-1 contains detailed information about I/O mapping for peripheral hardware in bank 15 (register locations
F80H–FFFH). Use the I/O map as a quick-reference source when writing application programs. The I/O map
gives you the following information:
— Register address
— Register name (mnemonic for program addressing)
— Bit values (both addressable and non-manipulable)
— Read-only, write-only, or read and write addressability
— 1-bit, 4-bit, or 8-bit data manipulation characteristics
3.The carry flag can be read or written by specific bit manipulation instructions only.
REGISTER DESCRIPTIONS
In this section, register descriptions are presented in a consistent format to familiarize you with the
memory-mapped I/O locations in bank 15 of the RAM. Figure 4-1 describes the features of the register
description format. Register descriptions are arranged in alphabetical order. Programmers can use this section as
a quick-reference source when writing application programs.
Counter registers, buffer registers, and reference registers, as well as the stack pointer and port I/O latches, are
not included in these descriptions. More detailed information about how these registers are used is included in
Part II of this manual, "Hardware Descriptions”, in the context of the corresponding peripheral hardware module
descriptions.
4-4
KS57C2308/P2308/C2316/P2316MEMORY MAP
Register and bit IDs
used for bit addressing
Register ID
CLMOD
Bit
Identifier
RESET
Read/Write
Bit Addressing
CLMOD.3
CLMOD.2
Clock Output Mode Control RegisterFD0H
− −
Value
Name of individual
bit or related bits
Associated
Register name
3
.3
0
W
4
Enable/Disable Clock Output Control Bit
01Disable clock output
Enable clock output
Bit 2
0Always logic zero
2
.2
0
W
4
hardware module
1
.1
0
W
4
0
.0
W
Register location
in RAM bank 15
CPU
0
4
CLMOD.1 - .0
R = Read-only
W = Write-only
R/W = Read/write
Type of addressing
that must be used to
address the bit
(1-bit, 4-bit, or 8-bit)
Clock Source and Frequency Selection Control Bits
0
0
1
1
Select CPU clock source
0
Select system clock fxx/8 (524 kHz at 4.19 MHz)
1
0
Select system clock fxx/16 (262 kHz at 4.19
1Select system clock fxx/64 (65.5 kHz at 4.19
Bit value immediately
following a
Description of the
effect of specific
bit
RESET
Figure 4-1. Register Description Format
Bit number in
MSB to LSB order
Bit identifier used
for bit addressing
4-5
MEMORY MAPKS57C2308/P2308/C2316/P2316
BMOD— Basic Timer Mode RegisterF85H
Bit
3210
Identifier.3.2.1.0
RESET Value
Read/Write
Bit Addressing
0000
WWWW
1/4444
.3Basic Timer Restart Bit
1Restart basic timer, then clear IRQB flag, BCNT and BMOD.3 to logic zero
.2–.0Input Clock Frequency and Signal Interrupt Interval Time Control Bits
000Input clock frequency:
Interrupt interval time (wait time):
011Input clock frequency:
Interrupt interval time (wait time):
101Input clock frequency:
Interrupt interval time (wait time):
111Input clock frequency:
Interrupt interval time (wait time):
12
fxx/2
(1.02 kHz)
220/fxx (250 ms)
fxx/29 (8.18 kHz)
217/fxx (31.3 ms)
fxx/27 (32.7 kHz)
215/fxx (7.82 ms)
fxx/25 (131 kHz)
213/fxx (1.95 ms)
NOTES:
1.When a RESET occurs, the oscillator stabilization wait time is 31.3 ms (217/fxx) at 4.19 MHz.
2.“fxx” is the system clock rate given a clock frequency of 4.19 MHz.
4-6
KS57C2308/P2308/C2316/P2316MEMORY MAP
CLMOD — Clock Output Mode RegisterFD0H
Bit
Identifier.3"0".1.0
RESET Value
Read/Write
Bit Addressing
.3Enable/Disable Clock Output Control Bit
.2Bit 2
.1–.0Clock Source and Frequency Selection Control Bits
3210
0000
WWWW
4444
0Disable clock output
1Enable clock output
0Always logic zero
00Select CPU clock source fx/4, fx/8, fx/64, or fxt/4 (1.05 MHz, 524 kHz,
65.5 kHz, or 8.19 kHz)
01Select system clock fxx/8 (524 kHz)
10Select system clock fxx/16 (262 kHz)
11Select system clock fxx/64 (65.5 kHz)
NOTE: “fxx” is the system clock, given a clock frequency of 4.19 MHz.
0Disable INT2 interrupt requests at the INT2 pin
1Enable INT2 interrupt requests at the INT2 pin
–Generate INT2 quasi-interrupt (This bit is set and is not cleared automatically
by hardware when a rising or falling edge is detected at INT2 or KS0–KS7
respectively. Since INT2 is a quasi-interrupt, IRQ2 flag must be cleared by
software.)
0Select CPU clock as a sampling clock
1Select sampling clock frequency of the selected system clock (fxx/64)
0Always logic zero
00Interrupt requests are triggered by a rising signal edge
01Interrupt requests are triggered by a falling signal edge
10Interrupt requests are triggered by both rising and falling signal edges
11Interrupt request flag (IRQ0) cannot be set to logic one
.2–.0External Interrupt 2 Edge Detection Selection Bit
3210
0000
WWWW
4444
0Always logic zero
000Select rising edge at INT2 pin
001Select falling edge at KS4–KS7
010Select falling edge at KS2–KS7
011Select falling edge at KS0–KS7
1––Ignore selection of falling edge at KS4–KS7
4-16
KS57C2308/P2308/C2316/P2316MEMORY MAP
IPR— Interrupt Priority RegisterFB2H
Bit
IdentifierIME.2.1.0
RESET Value
Read/Write
Bit Addressing
IMEInterrupt Master Enable Bit
.2–.0Interrupt Priority Assignment Bits
3210
0000
WWWW
1/4444
0Disable all interrupt processing
1Enable processing for all interrupt service requests
000Normal interrupt handling according to default priority settings
001Process INTB and INT4 interrupts at highest priority
010Process INT0 interrupts at highest priority
011Process INT1 interrupts at highest priority
100Process INTS interrupts at highest priority
101Process INTT0 interrupts at highest priority
4-17
MEMORY MAPKS57C2308/P2308/C2316/P2316
LCON— LCD Output Control RegisterF8EH
Bit
3210
Identifier"0".2"0".0
RESET Value
Read/Write
Bit Addressing
0000
WWWW
4444
.3LCD Bias Selection Bit
0This bit is used for internal testing only; always logic zero.
.2LCD Clock Output Disable/Enable Bit
0Disable LCDCK and LCDSY signal outputs.
1Enable LCDCK and LCDSY signal outputs.
.1Bit 1
0Always logic zero
.0LCD Display Control Bit
0LCD output low, turns display off: cut off current to dividing resistor, and output
If LMOD.3 = “1”, COM and SEG output in display mode; LCD display on.
NOTES:
1.You can manipulate LCON.0, when you try to turn ON/OFF LCD display internally. If you want to control LCD
ON/OFF or LCD contrast externally, you should set the LCON.0 to "0". refer to chapter 12, if you need more
information.
2.To select the LCD bias, you must properly configure both LMOD register and the external LCD bias circuit
connection.
4-18
KS57C2308/P2308/C2316/P2316MEMORY MAP
LMOD— LCD Mode RegisterF8DH, F8CH
Bit
Identifier.7.6.5.4.3.2.1.0
RESET Value
Read/Write
Bit Addressing
.7–.6LCD Output Segment and Pin Configuration Bits
.5–.4LCD Clock (LCDCK) Frequency Selection Bits
76543210
00000000
WWWWWWWW
88881/8888
00Segments 24–27; and 28–31
01Segment 24–27; 1-bit output at P8.4–P8.7
10Segment 28–31; 1-bit output at P8.0–P8.3
111-bit output only at P8.0–P8.3, and P8.4–P8.7
Bit
IdentifierPNE5.3PNE5.2PNE5.1PNE5.0PNE4.3PNE4.2PNE4.1PNE4.0
RESET Value
Read/Write
Bit Addressing
PNE5.3P5.3 N-Channel Open-Drain Configurable Bit
PNE5.2P5.2 N-Channel Open-Drain Configurable Bit
PNE5.1P5.1 N-Channel Open-Drain Configurable Bit
PNE5.0P5.0 N-Channel Open-Drain Configurable Bit
76543210
00000000
WWWWWWWW
88888888
0Configure P5.3 as a push-pull
1Configure P5.3 as a n-channel open-drain
0Configure P5.2 as a push-pull
1Configure P5.2 as a n-channel open-drain
0Configure P5.1 as a push-pull
1Configure P5.1 as a n-channel open-drain
0Configure P5.0 as a push-pull
1Configure P5.0 as a n-channel open-drain
PNE4.3P4.3 N-Channel Open-Drain Configurable Bit
0Configure P4.3 as a push-pull
1Configure P4.3 as a n-channel open-drain
PNE4.2P4.2 N-Channel Open-Drain Configurable Bit
0Configure P4.2 as a push-pull
1Configure P4.2 as a n-channel open-drain
PNE4.1P4.1 N-Channel Open-Drain Configurable Bit
0Configure P4.1 as a push-pull
1Configure P4.1 as a n-channel open-drain
PNE4.0P4.0 N-Channel Open-Drain Configurable Bit
0Configure P4.0 as a push-pull
1Configure P4.0 as a n-channel open-drain
4-23
MEMORY MAPKS57C2308/P2308/C2316/P2316
PSW— Program Status WordFB1H, FB0H
Bit
76543210
IdentifierCSC2SC1SC0IS1IS0EMBERB
RESET Value
Read/Write
Bit Addressing
(1)0000000
R/WRRRR/WR/WR/WR/W
(2)8881/4/81/4/81/4/81/4/8
CCarry Flag
0No overflow or borrow condition exists
1An overflow or borrow condition does exist
SC2–SC0Skip Condition Flags
0No skip condition exists; no direct manipulation of these bits is allowed
1A skip condition exists; no direct manipulation of these bits is allowed
IS1, IS0Interrupt Status Flags
00Service all interrupt requests
01Service only the high-priority interrupt(s) as determined in the interrupt
priority register (IPR)
10Do not service any more interrupt requests
11Undefined
EMBEnable Data Memory Bank Flag
0Restrict program access to data memory to bank 15 (F80H–FFFH) and to
the locations 000H–07FH in the bank 0 only
1Enable full access to data memory banks 0, 1, 2, and 15
ERBEnable Register Bank Flag
0Select register bank 0 as working register area
1Select register banks 0, 1, 2, or 3 as working register area in accordance with
the select register bank (SRB) instruction operand
NOTES:
1.The value of the carry flag after a RESET occurs during normal operation is undefined. If a RESET occurs during
power-down mode (IDLE or STOP), the current value of the carry flag is retained.
2.The carry flag can only be addressed by a specific set of 1-bit manipulation instructions. See Section 2 for
detailed information.
4-24
KS57C2308/P2308/C2316/P2316MEMORY MAP
PUMOD— Pull-Up Resistor Mode RegisterFDDH, FDCH
Bit
IdentifierPUR7PUR6PUR5PUR4PUR3PUR2PUR1PUR0
RESET Value
Read/Write
Bit Addressing
PUR7Connect/Disconnect Port 7 Pull-Up Resistor Control Bit
PUR6Connect/Disconnect Port 6 Pull-Up Resistor Control Bit
PUR5Connect/Disconnect Port 5 Pull-Up Resistor Control Bit
PUR4Connect/Disconnect Port 4 Pull-Up Resistor Control Bit
76543210
00000000
WWWWWWWW
88888888
0Disconnect port 7 pull-up resistor
1Connect port 7 pull-up resistor
0Disconnect port 6 pull-up resistor
1Connect port 6 pull-up resistor
0Disconnect port 5 pull-up resistor
1Connect port 5 pull-up resistor
0Disconnect port 4 pull-up resistor
1Connect port 4 pull-up resistor
PUR3Connect/Disconnect Port 3 Pull-Up Resistor Control Bit
0Disconnect port 3 pull-up resistor
1Connect port 3 pull-up resistor
PUR2Connect/Disconnect Port 2 Pull-Up Resistor Control Bit
0Disconnect port 2 pull-up resistor
1Connect port 2 pull-up resistor
PUR1Connect/Disconnect Port 1 Pull-Up Resistor Control Bit
0Disconnect port 1 pull-up resistor
1Connect port 1 pull-up resistor
PUR0Connect/Disconnect Port 0 Pull-Up Resistor Control Bit
0Disconnect port 0 pull-up resistor
1Connect port 0 pull-up resistor
NOTE: Pull-up resistors for all I/O ports are automatically disabled when they are configured to output mode.
4-25
MEMORY MAPKS57C2308/P2308/C2316/P2316
SCMOD— System Clock Mode Control RegisterFB7H
Bit
Identifier.3.2"0".0
RESET Value
Read/Write
Bit Addressing
.3, .2 and .0CPU Clock Selection and Main System Clock Oscillation Control Bits
.1Bit 1
NOTE:SCMOD bits 3 and 0 cannot be modified simultaneously by a 4-bit instruction; they can only be modified by
separate 1-bit instructions.
3210
0000
WWWW
1111
000Select main system clock (fx); enable main system clock
001Select sub system clock (fxt); enable main system clock
010Select main system clock (fx); disable sub system clock
101Select sub system clock (fxt); disable main system clock
0Always logic zero
4-26
KS57C2308/P2308/C2316/P2316MEMORY MAP
SMOD— Serial I/O Mode RegisterFE1H, FE0H
Bit
Identifier.7.6.5"0".3.2.1.0
RESET Value
Read/Write
Bit Addressing
.7–.5Serial I/O Clock Selection and SBUF R/W Status Control Bits
.4Bit 4
76543210
00000000
WWWWR/WWWW
88881/8888
000Use an external clock at the SCK pin;
Enable SBUF when SIO operation is halted or when SCK goes high
001Use the TOL0 clock from timer/counter 0;
Enable SBUF when SIO operation is halted or when SCK goes high
01xUse the selected CPU clock (fxx/4, 8, or 64; “fxx” is the system
clock); Enable SBUF read/write operation. “x” means “don't care.”
100
111
0Always logic zero
4.09 kHz clock (fxx/210)
262 kHz clock (fxx/24); Note: You cannot select a fxx/24 clock
frequency if you have selected a CPU clock of fxx/64
.3Initiate Serial I/O Operation Bit
1Clear IRQS flag and 3-bit clock counter to logic zero; then initiate serial
transmission. When SIO transmission starts, this bit is cleared by hardware to
logic zero
.2Enable/Disable SIO Data Shifter and Clock Counter Bit
0Disable the data shifter and clock counter; the contents of IRQS flag is
retained when serial transmission is completed
1Enable the data shifter and clock counter; The IRQS flag is set to logic one
when serial transmission is completed
.1Serial I/O Transmission Mode Selection Bit
0Receive-only mode; output buffer is off
1Transmit-and-receive mode; output buffer is on
.0LSB/MSB Transmission Mode Selection Bit
0Transmit the most significant bit (MSB) first
1Transmit the least significant bit (LSB) first
4-27
MEMORY MAPKS57C2308/P2308/C2316/P2316
TMOD0— Timer/Counter 0 Mode RegisterF91H, F90H
Bit
Identifier"0".6.5.4.3.2"0""0"
RESET Value
Read/Write
Bit Addressing
.7Bit 7
.6–.4Timer/Counter 0 Input Clock Selection Bits
76543210
00000000
WWWWWWWW
88881/8888
0Always logic zero
000External clock input at TCL0 pin on rising edge
001External clock input at TCL0 pin on falling edge
100
101
110
0Disable timer/counter 0 output at the TCLO0 pin
1Enable timer/counter 0 output at the TCLO0 pin
UUnknown
4-29
MEMORY MAPKS57C2308/P2308/C2316/P2316
WDFLAG — Watchdog Timer Counter Clear Flag RegisterF9AH
Bit
IdentifierWDTCF“0”“0”“0”
RESET Value
Read/Write
Bit Addressing
WDTCFWatchdog Timer Counter Clear Flag
.2–.0Bits 2–0
NOTE: After watchdog timer is cleared by writing “1”, this bit is cleared to “0” automatically.
3210
0000
WWWW
1/41/41/41/4
1Clears the watchdog timer counter
0Always logic zero
4-30
KS57C2308/P2308/C2316/P2316MEMORY MAP
WDMOD — Watchdog Timer Mode RegisterF99H, F98H
Bit
Identifier.7.6.5.4.3.2.1.0
RESET Value
Read/Write
Bit Addressing
WDMODWatchdog Timer Enable/Disable Control
76543210
10100101
WWWWWWWW
88888888
5AHDisable watchdog timer function
OthersEnable watchdog timer function
4-31
MEMORY MAPKS57C2308/P2308/C2316/P2316
WMOD— Watch Timer Mode RegisterF89H, F88H
Bit
Identifier.7"0".5.4.3.2.1.0
RESET Value
Read/Write
Bit Addressing
.7Enable/Disable Buzzer Output Bit
.6Bit 6
.5–.4Output Buzzer Frequency Selection Bits
76543210
0000(note)000
WWWWRWWW
88881888
0Disable buzzer (BUZ) signal output
1Enable buzzer (BUZ) signal output
0Always logic zero
002 kHz buzzer (BUZ) signal output
014 kHz buzzer (BUZ) signal output
108 kHz buzzer (BUZ) signal output
1116 kHz buzzer (BUZ) signal output
.3
.2Enable/Disable Watch Timer Bit
.1Watch Timer Speed Control Bit
.0Watch Timer Clock Selection Bit
NOTE:RESET sets WMOD.3 to the current input level of the subsystem clock, XTIN. If the input level is high,
WMOD.3 is set to logic one; if low, WMOD.3 is cleared to zero along with all the other bits in the WMOD
register.
XTIN Input Level Control Bit
Input level to XT
0
Input level to XTIN pin is high; 1-bit read-only addressable for test
1
0Disable watch timer and clear frequency dividing circuits
1Enable watch timer
0Normal speed; set IRQW to 0.5 seconds
1High-speed operation; set IRQW to 3.91 ms
0Select the system clock (fxx/128) as the watch timer clock
1Select a subsystem clock as the watch timer clock
pin is low; 1-bit read-only addressable for test
IN
4-32
KS57C2308/P2308/C2316/P2316SAM47 INSTRUCTION SET
5SAM47 INSTRUCTION SET
OVERVIEW
The SAM47 instruction set is specifically designed to support the large register files that are typical of most
KS57-series microcontrollers.
The SAM47 instruction set includes 1-bit, 4-bit, and 8-bit instructions for data manipulation, logical and arithmetic
operations, program control, and CPU control. I/O instructions for peripheral hardware devices are flexible and
easy to use. Symbolic hardware names can be substituted as the instruction operand in place of the actual
address. Other important features of the SAM47 instruction set include:
— 1-byte referencing of long instructions (REF instruction)
— Redundant instruction reduction (string effect)
— Skip feature for ADC and SBC instructions
Instruction operands conform to the operand format defined for each instruction. Several instructions have
multiple operand formats.
Predefined values or labels can be used as instruction operands when addressing immediate data. Many of the
symbols for specific registers and flags may also be substituted as labels for operations such DA, mema, memb,
b, and so on. Using instruction labels can greatly simplify programming and debugging tasks.
INSTRUCTION SET FEATURES
In this section, the following SAM47 instruction set features are described in detail:
— Instruction reference area
— Instruction redundancy reduction
— Flexible bit manipulation
— ADC and SBC instruction skip condition
NOTE
1. The ROM size accessed by instruction may change for different devices in the SAM47 product.
2. The number of memory bank selected by SMB may change for different devices in the SAM47 product
family.
3. The port names used instruction set may change for different devices in SAM47 product family.
4. The interrupt names and the interrupt numbers used in the instruction set may change for different
devices in the SAM47 product family.
5-1
SAM47 INSTRUCTION SETKS57C2308/P2308/C2316/P2316
Instruction Reference Area
Using the 1-byte REF (Reference) instruction, you can reference instructions stored in the addresses
0020H–007FH of program memory (the REF instruction look-up table). The location referenced by REF may
contain either two 1-byte instructions or a single 2-byte instruction. The starting address of the instruction being
referenced must always be an even number.
3-byte instructions such as JP or CALL may also be referenced using REF. To reference these 3-byte
instructions, the 2-byte pseudo commands, TJP and TCALL, must be written in the reference.
The PC is not incremented when an REF instruction is executed. After it executes, the program's instruction
execution sequence resumes at the address immediately following the REF instruction. By using REF instructions
to execute instructions larger than one byte, as well as branches and subroutines, you can reduce the program
size. To summarize, the REF instruction can be used in three ways:
— Using the 1-byte REF instruction to execute one 2-byte or two 1-byte instructions;
— Branching to any location by referencing a branch address that is stored in the look-up table;
— Calling subroutines at any location by referencing a call address that is stored in the look-up table.
If necessary, an REF instruction can be circumvented by means of a skip operation prior to the REF in the
execution sequence. In addition, the instruction immediately following an REF can also be skipped by using an
appropriate reference instruction or instructions.
Two-byte instructions can be referenced by using an REF instruction. (An exception is XCH A,DA
(note)
)
If the MSB value of the first 1-byte instruction in the reference area is “0”, the instruction cannot be referenced by
a REF instruction. Therefore, if you use REF to reference two 1-byte instructions stored in the reference area,
specific combinations must be used for the first and second 1-byte instruction. These combinations are described
in Table5-1.
Table 5-1. Valid 1-Byte Instruction Combinations for REF Look-Ups
First 1-Byte InstructionSecond 1-Byte Instruction
InstructionOperandInstructionOperand
LDA,#im
INCS
(note)
R
INCSRRb
LDA,@Rra
DECS
INCS
(note)
(note)
R
R
INCSRRb
LD@HL,A
DECS
INCS
(note)
(note)
R
R
INCSRRb
NOTE: The MSB value of the instruction is “0”.
DECS
(note)
R
5-2
KS57C2308/P2308/C2316/P2316SAM47 INSTRUCTION SET
Reducing Instruction Redundancy
When redundant instructions such as LD A,#im and LD EA,#imm are used consecutively in a program sequence,
only the first instruction is executed, but the following redundant instructions are ignored, that is, they are handled
like a NOP instruction. When LD HL,#imm instructions are used consecutively, the following redundant
instructions are also ignored.
In the following example, only the “LD A, #im” instruction will be executed. The 8-bit load instruction which
follows it is interpreted as redundant and is ignored:
LD A,#im; Load 4-bit immediate data (#im) to accumulator
LD EA,#imm; Load 8-bit immediate data (#imm) to extended accumulator
In this example, the statements “LD A,#2H” and “LD A,#3H” are ignored:
BITR EMB
If consecutive LD HL, #imm instructions (load 8-bit immediate data to the 8-bit memory pointer pair, HL) are
detected, only the first LD is executed and the LDs which immediately follow are ignored. For example,
If an instruction reference with a REF instruction has a redundancy effect, the following conditions apply:
— If the instruction preceding the REF has a redundancy effect, this effect is cancelled and the referenced
instruction is not skipped.
— If the instruction following the REF has a redundancy effect, the instruction following the REF is skipped.
+ + PROGRAMMING TIP — Example of the Instruction Redundancy Effect
ORG0020H
ABCLDEA,#30H; Stored in REF instruction reference area
ORG0080H
•
•
•
LDEA,#40H; Redundancy effect is encountered
REFABC; No skip (EA ← #30H)
•
•
•
REFABC; EA ← #30H
LDEA,#50H; Skip
5-3
SAM47 INSTRUCTION SETKS57C2308/P2308/C2316/P2316
Flexible Bit Manipulation
In addition to normal bit manipulation instructions like set and clear, the SAM47 instruction set can also perform
bit tests, bit transfers, and bit Boolean operations. Bits can also be addressed and manipulated by special bit
addressing modes. Three types of bit addressing are supported:
— mema.b
— memb.@L
— @H+DA.b
The parameters of these bit addressing modes are described in more detail in Table 5-2.
Table 5-2. Bit Addressing Modes and Parameters
Addressing ModeAddressable PeripheralsAddress Range
mema.bERB, EMB, IS1, IS0, IEx, IRQxFB0H–FBFH
PortsFF0H–FFFH
memb.@LPorts and BSCFC0H–FFFH
@H+DA.bAll bit-manipulatable peripheral hardwareAll bits of the memory bank specified by
EMB and SMB that are bit-manipulatable
Instructions Which Have Skip Conditions
The following instructions have a skip function when an overflow or borrow occurs:
XCHIINCS
XCHDDECS
LDIADS
LDDSBS
If there is an overflow or borrow from the result of an increment or decrement, a skip signal is generated and a
skip is executed. However, the carry flag value is unaffected.
The instructions BTST, BTSF, and CPSE also generate a skip signal and execute a skip when they meet a skip
condition, and the carry flag value is also unaffected.
Instructions Which Affect the Carry Flag
The only instructions which do not generate a skip signal, but which do affect the carry flag are as follows:
The instructions “ADC A,@HL” and “SBC A,@HL” can generate a skip signal, and set or clear the carry flag,
when they are executed in combination with the instruction “ADS A,#im”.
If an “ADS A,#im” instruction immediately follows an “ADC A,@HL” or “SBC A,@HL” instruction in a program
sequence, the ADS instruction does not skip the instruction following ADS, even if it has a skip function. If,
however, an “ADC A,@HL” or “SBC A,@HL” instruction is immediately followed by an “ADS A,#im” instruction,
the ADC (or SBC) skips on overflow (or if there is no borrow) to the instruction immediately following the ADS,
and program execution continues. Table 5-3 contains additional information and examples of the “ADC A,@HL”
and “SBC A,@HL” skip feature.
Table 5-3. Skip Conditions for ADC and SBC Instructions
Sample
Instruction Sequences
ADC A,@HL
ADS A,#im
xxx
xxx
SBC A,@HL
ADS A,#im
xxx
xxx
If the result of
instruction 1 is:
1
Overflow
2
3
No overflow
Then, the execution
sequence is:
1, 3, 4
1, 2, 3, 4
Reason
ADS cannot skip
instruction 3, even if it
has a skip function.
4
1
2
3
Borrow
No borrow
1, 2, 3, 4
1, 3, 4
ADS cannot skip
instruction 3, even if it
has a skip function.
4
5-5
SAM47 INSTRUCTION SETKS57C2308/P2308/C2316/P2316
SYMBOLS and CONVENTIONS
Table 5-4. Data Type Symbols
SymbolData Type
dImmediate data
aAddress data
bBit data
rRegister data
fFlag data
iIndirect addressing data
t
memc × 0.5 immediate data
Table 5-5. Register Identifiers
Full Register NameID
4-bit accumulatorA
4-bit working registersE, L, H, X, W,
Z, Y
8-bit extended accumulatorEA
8-bit memory pointerHL
8-bit working registersWX, YZ, WL
Select register bank “n”SRB n
Select memory bank “n”SMB n
Carry flagC
Program status wordPSW
Port “n”Pn
“m”-th bit of port “n”Pn.m
Interrupt priority registerIPR
Enable memory bank flagEMB
Enable register bank flagERB
Table 5-6. Instruction Operand Notation
SymbolDefinition
DADirect address
@Indirect address prefix
srcSource operand
dstDestination operand
(R)Contents of register R
.bBit location
im4-bit immediate data (number)
imm8-bit immediate data (number)
#Immediate data prefix
ADR000H–1FFFH immediate address
ADRn“n” bit address
RA, E, L, H, X, W, Z, Y
RaE, L, H, X, W, Z, Y
RREA, HL, WX, YZ
RRaHL, WX, WL
RRbHL, WX, YZ
RRcWX, WL
memaFB0H–FBFH, FF0H–FFFH
membFC0H–FFFH
memcCode direct addressing:
0020H–007FH
SBSelect bank register (8 bits)
XORLogical exclusive-OR
ORLogical OR
ANDLogical AND
[(RR)]Contents addressed by RR
5-6
KS57C2308/P2308/C2316/P2316SAM47 INSTRUCTION SET
OPCODE DEFINITIONS
Table 5-7. Opcode Definitions (Direct)
Registerr2r1r0
A000
E001
L010
H011
i = Immediate data for indirect addressing
X100
W101
Z110
Y111
EA000
HL010
WX100
YZ110
r = Immediate data for register
CALCULATING ADDITIONAL MACHINE CYCLES FOR SKIPS
Table 5-8. Opcode Definitions (Indirect)
Registeri2i1i0
@HL101
@WX110
@WL111
A machine cycle is defined as one cycle of the selected CPU clock. Three different clock rates can be selected
using the PCON register.
In this document, the letter “S” is used in tables when describing the number of additional machine cycles
required for an instruction to execute, given that the instruction has a skip function (“S” = skip). The addition
number of machine cycles that will be required to perform the skip usually depends on the size of the instruction
being skipped — whether it is a 1-byte, 2-byte, or 3-byte instruction. A skip is also executed for SMB and SRB
instructions.
The values in additional machine cycles for “S” for the three cases in which skip conditions occur are as follows:
Case 1:No skipS = 0 cycles
Case 2:Skip is 1-byte or 2-byte instructionS = 1 cycle
Case 3:Skip is 3-byte instructionS = 2 cycles
NOTE: REF instructions are skipped in one machine cycle.
5-7
SAM47 INSTRUCTION SETKS57C2308/P2308/C2316/P2316
HIGH-LEVEL SUMMARY
This section contains a high-level summary of the SAM47 instruction set in table format. The tables are designed
to familiarize you with the range of instructions that are available in each instruction category.
These tables are a useful quick-reference resource when writing application programs.
If you are reading this user's manual for the first time, however, you may want to scan this detailed information
briefly, and then return to it later on. The following information is provided for each instruction:
— Instruction name
— Operand(s)
— Brief operation description
— Number of bytes of the instruction and operand(s)
— Number of machine cycles required to execute the instruction
The tables in this section are arranged according to the following instruction categories:
— CPU control instructions
— Program control instructions
— Data transfer instructions
— Logic instructions
— Arithmetic instructions
— Bit manipulation instructions
5-8
KS57C2308/P2308/C2316/P2316SAM47 INSTRUCTION SET
Table 5-9. CPU Control Instructions — High-Level Summary
NameOperandOperation DescriptionBytesCycles
SCFSet carry flag to logic one11
RCFReset carry flag to logic zero11
CCFComplement carry flag11
EIEnable all interrupts22
DIDisable all interrupts22
IDLEEngage CPU idle mode22
STOPEngage CPU stop mode22
NOPNo operation11
SMBnSelect memory bank22
SRBnSelect register bank22
REFmemcReference code11
VENTnEMB (0,1)
ERB (0,1)
ADR
Load enable memory bank flag (EMB) and the enable
register bank flag (ERB) and program counter to vector
address, then branch to the corresponding location
22
Table 5-10. Program Control Instructions — High-Level Summary
NameOperandOperation DescriptionBytesCycles
CPSER,#imCompare and skip if register equals #im22 + S
@HL,#imCompare and skip if indirect data memory equals #im22 + S
A,RCompare and skip if A equals R22 + S
A,@HLCompare and skip if A equals indirect data memory11 + S
EA,@HLCompare and skip if EA equals indirect data memory22 + S
EA,RRCompare and skip if EA equals RR22 + S
JPADR14Jump to direct address (14 bits)33
JPSADR12Jump direct in page (12 bits)22
JR#imJump to immediate address12
@WXBranch relative to WX register23
@EABranch relative to EA23
CALLADR14Call direct in page (14 bits)34
CALLSADR11Call direct in page (11 bits)23
RET–Return from subroutine13
IRET–Return from interrupt13
SRET–Return from subroutine and skip13 + S
5-9
SAM47 INSTRUCTION SETKS57C2308/P2308/C2316/P2316
Table 5-11. Data Transfer Instructions — High-Level Summary
NameOperandOperation DescriptionBytesCycles
XCHA,DAExchange A and direct data memory contents22
A,RaExchange A and register (Ra) contents11
A,@RRaExchange A and indirect data memory11
EA,DAExchange EA and direct data memory contents22
EA,RRbExchange EA and register pair (RRb) contents22
EA,@HLExchange EA and indirect data memory contents22
XCHIA,@HLExchange A and indirect data memory contents;
12 + S
increment contents of register L and skip on carry
XCHDA,@HLExchange A and indirect data memory contents;
12 + S
decrement contents of register L and skip on carry
LDA,#imLoad 4-bit immediate data to A11
A,@RRaLoad indirect data memory contents to A11
A,DALoad direct data memory contents to A22
A,RaLoad register contents to A22
Ra,#imLoad 4-bit immediate data to register22
RR,#immLoad 8-bit immediate data to register22
DA,ALoad contents of A to direct data memory22
Ra,ALoad contents of A to register22
EA,@HLLoad indirect data memory contents to EA22
EA,DALoad direct data memory contents to EA22
EA,RRbLoad register contents to EA22
@HL,ALoad contents of A to indirect data memory11
DA,EALoad contents of EA to data memory22
RRb,EALoad contents of EA to register22
@HL,EALoad contents of EA to indirect data memory22
LDIA,@HLLoad indirect data memory to A; increment register L
12 + S
contents and skip on carry
LDDA,@HLLoad indirect data memory contents to A; decrement
12 + S
register L contents and skip on carry
LDCEA,@WXLoad code byte from WX to EA13
EA,@EALoad code byte from EA to EA13
RRCARotate right through carry bit11
PUSHRRPush register pair onto stack11
SBPush SMB and SRB values onto stack22
POPRRPop to register pair from stack11
ADCA,@HLAdd indirect data memory to A with carry11
EA,RRAdd register pair (RR) to EA with carry22
RRb,EAAdd EA to register pair (RRb) with carry22
ADSA, #imAdd 4-bit immediate data to A and skip on carry11 + S
EA,#immAdd 8-bit immediate data to EA and skip on carry22 + S
A,@HLAdd indirect data memory to A and skip on carry11 + S
EA,RRAdd register pair (RR) contents to EA and skip on carry22 + S
RRb,EAAdd EA to register pair (RRb) and skip on carry22 + S
SBCA,@HLSubtract indirect data memory from A with carry11
EA,RRSubtract register pair (RR) from EA with carry22
RRb,EASubtract EA from register pair (RRb) with carry22
SBSA,@HLSubtract indirect data memory from A; skip on borrow11 + S
EA,RRSubtract register pair (RR) from EA; skip on borrow22 + S
RRb,EASubtract EA from register pair (RRb); skip on borrow22 + S
DECSRDecrement register (R); skip on borrow11 + S
RRDecrement register pair (RR); skip on borrow22 + S
INCSRIncrement register (R); skip on carry11 + S
DAIncrement direct data memory; skip on carry22 + S
@HLIncrement indirect data memory; skip on carry22 + S
RRbIncrement register pair (RRb); skip on carry11 + S
5-11
SAM47 INSTRUCTION SETKS57C2308/P2308/C2316/P2316
Table 5-14. Bit Manipulation Instructions — High-Level Summary
NameOperandOperation DescriptionBytesCycles
BTSTCTest specified bit and skip if carry flag is set11 + S
DA.bTest specified bit and skip if memory bit is set
mema.b
memb.@L
@H+DA.b
BTSFDA.bTest specified memory bit and skip if bit equals "0"
mema.b22 + S
memb.@L
@H+DA.b
BTSTZmema.bTest specified bit; skip and clear if memory bit is set
memb.@L
@H+DA.b
BITSDA.bSet specified memory bit
mema.b
memb.@L
@H+DA.b
BITRDA.bClear specified memory bit to logic zero
mema.b
memb.@L
@H+DA.b
BANDC,mema.bLogical-AND carry flag with specified memory bit
C,memb.@L
C,@H+DA.b22
BORC,mema.bLogical-OR carry with specified memory bit
C,memb.@L
C,@H+DA.b
BXORC,mema.bExclusive-OR carry with specified memory bit
C,memb.@L
C,@H+DA.b
LDBmema.b,CLoad carry bit to a specified memory bit
memb.@L,CLoad carry bit to a specified indirect memory bit
@H+DA.b,C
C,mema.bLoad specified memory bit to carry bit
C,memb.@LLoad specified indirect memory bit to carry bit
C,@H+DA.b
5-12
KS57C2308/P2308/C2316/P2316SAM47 INSTRUCTION SET
BINARY CODE SUMMARY
This section contains binary code values and operation notation for each instruction in the SAM47 instruction set
in an easy-to-read, tabular format. It is intended to be used as a quick-reference source for programmers who are
experienced with the SAM47 instruction set. The same binary values and notation are also included in the
detailed descriptions of individual instructions later in Section 5.
If you are reading this user's manual for the first time, please just scan this very detailed information briefly. Most
of the general information you will need to write application programs can be found in the high-level summary
tables in the previous section. The following information is provided for each instruction:
A ← A + im; skip on carry
EA ← EA + imm; skip on carry
A ← A+ (HL); skip on carry
EA ← EA + RR; skip on carry
RRb ← RRb + EA; skip on carry
C,A ← A – (HL) – C
C, EA ← EA –RR – C
C,RRb ← RRb – EA – C
A ← A – (HL); skip on borrow
EA ← EA – RR; skip on borrow
RRb ← RRb – EA; skip on borrow
R ← R–1; skip on borrow
RR ← RR–1; skip on borrow
R ← R + 1; skip on carry
DA ← DA + 1; skip on carry
(HL) ← (HL) + 1; skip on carry
RRb ← RRb + 1; skip on carry
5-19
SAM47 INSTRUCTION SETKS57C2308/P2308/C2316/P2316
Table 5-20. Bit Manipulation Instructions — Binary Code Summary
NameOperandBinary CodeOperation Notation
BTSTC11010111Skip if C = 1
DA.b11b1b00011Skip if DA.b = 1
a7a6a5a4a3a2a1a0
mema.b *
11111001Skip if mema.b = 1
memb.@L11111001Skip if [memb.7–2 + L.3–2].
[L.1–0] = 1
0100a5a4a3a2
@H+DA.b11111001Skip if [H + DA.3–0].b = 1
00b1b0a3a2a1a0
BTSFDA.b11b1b00010Skip if DA.b = 0
a7a6a5a4a3a2a1a0
mema.b *
11111000Skip if mema.b = 0
memb.@L11111000Skip if [memb.7–2 + L.3–2].
0100a5a4a3a2
@H DA.b11111000Skip if [H + DA.3–0].b = 0
00b1b0a3a2a1a0
BTSTZ
mema.b *
11111101Skip if mema.b = 1 and clear
memb.@L11111101Skip if [memb.7–2 + L.3–2].
0100a5a4a3a2
@H+DA.b11111101Skip if [H + DA.3–0].b =1 and clear
00b1b0a3a2a1a0
BITSDA.b11b1b00001
a7a6a5a4a3a2a1a0
mema.b *
11111111
memb.@L11111111
0100a5a4a3a2
@H+DA.b11111111
00b1b0a3a2a1a0
[L.1–0] = 0
[L.1–0] = 1 and clear
DA.b ← 1
mema.b ← 1
[memb.7–2 + L.3–2].[L.1–0] ← 1
[H + DA.3–0].b ← 1
5-20
KS57C2308/P2308/C2316/P2316SAM47 INSTRUCTION SET
Table 5-20. Bit Manipulation Instructions — Binary Code Summary (Continued)
NameOperandBinary CodeOperation Notation
BITRDA.b11b1b00000
a7a6a5a4a3a2a1a0
mema.b *
11111110
memb.@L11111110
0100a5a4a3a2
@H+DA.b11111110
00b1b0a3a2a1a0
BAND
C,mema.b *
11110101
C,memb.@L11110101
0100a5a4a3a2
C,@H+DA.b11110101
00b1b0a3a2a1a0
BOR
C,mema.b *
11110110
C,memb.@L11110110
0100a5a4a3a2
C,@H+DA.b11110110
00b1b0a3a2a1a0
BXOR
C,mema.b *
11110111
DA.b ← 0
mema.b ← 0
[memb.7–2 + L3–2].[L.1–0] ← 0
[H + DA.3–0].b ← 0
C ← C AND mema.b
C ← C AND [memb.7–2 + L.3–2].
[L.1–0]
C ← C AND [H + DA.3–0].b
C ← C OR mema.b
C ← C OR [memb.7–2 + L.3–2].
[L.1–0]
C ← C OR [H + DA.3–0].b
C ← C XOR mema.b
* mema.b
C,memb.@L11110111
0100a5a4a3a2
C,@H+DA.b11110111
00b1b0a3a2a1a0
Second ByteBit Addresses
10b1b0a3a2a1a0FB0H–FBFH
11b1b0a3a2a1a0FF0H–FFFH
C ← C XOR [memb.7–2 + L.3–2].
[L.1–0]
C ← C XOR [H + DA.3–0].b
5-21
SAM47 INSTRUCTION SETKS57C2308/P2308/C2316/P2316
Table 5-20. Bit Manipulation Instructions — Binary Code Summary (Concluded)
NameOperandBinary CodeOperation Notation
LDB
* mema.b
mema.b,C *
11111100
memb.@L,C11111100
0100a5a4a3a2
@H+DA.b,C11111100
00b1b0a3a2a1a0
C,mema.b *
11110100
C,memb.@L11110100
0100a5a4a3a2
C,@H+DA.b11110100
00b1b0a3a2a1a0
Second ByteBit Addresses
10b1b0a3a2a1a0FB0H–FBFH
11b1b0a3a2a1a0FF0H–FFFH
mema.b ← C
memb.7–2 + [L.3–2]. [L.1–0] ← C
H + [DA.3–0].b ← (C)
C ← mema.b
C ← memb.7–2 + [L.3–2] . [L.1–0]
C ← [H + DA.3–0].b
5-22
KS57C2308/P2308/C2316/P2316SAM47 INSTRUCTION SET
INSTRUCTION DESCRIPTIONS
This section contains detailed information and programming examples for each instruction of the SAM47
instruction set. Information is arranged in a consistent format to improve readability and for use as a
quick-reference resource for application programmers.
If you are reading this user's manual for the first time, please just scan this very detailed information briefly in
order to acquaint yourself with the basic features of the instruction set. The information elements of the
instruction description format are as follows:
— Instruction name (mnemonic)
— Full instruction name
— Source/destination format of the instruction operand
— Operation overview (from the "High-Level Summary" table)
— Textual description of the instruction's effect
— Binary code overview (from the "Binary Code Summary" table)
— Programming example(s) to show how the instruction is used
5-23
SAM47 INSTRUCTION SETKS57C2308/P2308/C2316/P2316
ADC —Add With Carry
ADCdst,src
Operation:OperandOperation SummaryBytesCycles
A,@HLAdd indirect data memory to A with carry11
EA,RRAdd register pair (RR) to EA with carry22
RRb,EAAdd EA to register pair (RRb) with carry22
Description:The source operand, along with the setting of the carry flag, is added to the destination operand
and the sum is stored in the destination. The contents of the source are unaffected. If there is an
overflow from the most significant bit of the result, the carry flag is set; otherwise, the carry flag
is cleared.
If “ADC A,@HL” is followed by an “ADS A,#im” instruction in a program, ADC skips the ADS
instruction if an overflow occurs. If there is no overflow, the ADS instruction is executed normally.
(This condition is valid only for “ADC A,@HL” instructions. If an overflow occurs following an
“ADS A,#im” instruction, the next instruction will not be skipped.)
OperandBinary CodeOperation Notation
A,@HL00111110
EA,RR11011100
10101r2r10
RRb,EA11011100
10100r2r10
Examples:1. The extended accumulator contains the value 0C3H, register pair HL the value 0AAH, and
the carry flag is set to "1":
SCF; C ← "1"
ADCEA,HL; EA ← 0C3H + 0AAH + 1H = 6EH, C ← "1"
JPSXXX; Jump to XXX; no skip after ADC
2. If the extended accumulator contains the value 0C3H, register pair HL the value 0AAH, and
the carry flag is cleared to "0":
RCF; C ← "0"
ADCEA,HL; EA ← 0C3H + 0AAH + 0H = 6DH, C ← "1"
JPSXXX; Jump to XXX; no skip after ADC
C, A ← A + (HL) + C
C, EA ← EA + RR + C
C, RRb ← RRb + EA + C
5-24
KS57C2308/P2308/C2316/P2316SAM47 INSTRUCTION SET
ADC — Add With Carry
ADC(Continued)
Examples:3. If ADC A,@HL is followed by an ADS A,#im, the ADC skips on carry to the instruction
immediately after the ADS. An ADS instruction immediately after the ADC does not skip even
if an overflow occurs. This function is useful for decimal adjustment operations.
a. 8 + 9 decimal addition (the contents of the address specified by the HL register is 9H):
RCF; C ← "0"
LDA,#8H; A ← 8H
ADSA,#6H; A ← 8H + 6H = 0EH
ADCA,@HL; A ← 0EH + 9H + C(0) = 7H, C ← "1"
ADSA,#0AH; Skip this instruction because C = "1" after ADC result
JPSXXX
b. 3 + 4 decimal addition (the contents of the address specified by the HL register is 4H):
RCF; C ← "0"
LDA,#3H; A ← 3H
ADSA,#6H; A ← 3H + 6H = 9H
ADCA,@HL; A ← 9H + 4H + C(0) = 0DH
ADSA,#0AH; No skip. A ← 0DH + 0AH = 7H
; (The skip function for “ADS A,#im” is inhibited after an
; “ADC A,@HL” instruction even if an overflow occurs.)
JPSXXX
5-25
SAM47 INSTRUCTION SETKS57C2308/P2308/C2316/P2316
ADS — Add And Skip On Overflow
ADSdst,src
Operation:OperandOperation SummaryBytesCycles
A, #imAdd 4-bit immediate data to A and skip on overflow11 + S
EA,#immAdd 8-bit immediate data to EA and skip on overflow22 + S
A,@HLAdd indirect data memory to A and skip on overflow11 + S
EA,RRAdd register pair (RR) contents to EA and skip on
overflow
RRb,EAAdd EA to register pair (RRb) and skip on overflow22 + S
Description:The source operand is added to the destination operand and the sum is stored in the destination.
The contents of the source are unaffected. If there is an overflow from the most significant bit of
the result, the skip signal is generated and a skip is executed, but the carry flag value is
unaffected.
22 + S
If “ADS A,#im” follows an “ADC A,@HL” instruction in a program, ADC skips the ADS instruction
if an overflow occurs. If there is no overflow, the ADS instruction is executed normally. This skip
condition is valid only for “ADC A,@HL” instructions, however. If an overflow occurs following an
ADS instruction, the next instruction is not skipped.
OperandBinary CodeOperation Notation
A, #im1010d3d2d1d0
EA,#imm11001001
d7d6d5d4d3d2d1d0
A,@HL00111111
EA,RR11011100
10011r2r10
RRb,EA11011100
10010r2r10
Examples:1. The extended accumulator contains the value 0C3H, register pair HL the value 0AAH, and
the carry flag = "0":
ADSEA,HL; EA ← 0C3H + 0AAH = 6DH
; ADS skips on overflow, but carry flag value is not
affected.
JPSXXX; This instruction is skipped since ADS had an overflow.
JPSYYY; Jump to YYY.
A ← A + im; skip on overflow
EA ← EA + imm; skip on overflow
A ← A + (HL); skip on overflow
EA ← EA + RR; skip on overflow
RRb ← RRb + EA; skip on overflow
5-26
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.