beautypg.com

4 arithmetic operations with numbering system – Epson S1C63000 User Manual

Page 13

background image

S1C63000 CORE CPU MANUAL

EPSON

7

CHAPTER 2: ARCHITECTURE

2.1.4 Arithmetic operations with numbering system

In the S1C63000, some instructions support a numbering system. These instructions are indicated with
the following notations in the instruction list.

ADC

operand,n4

SBC

operand,n4

INC

operand,n4

DEC

operand,n4

(See "Instruction List" or "Detailed Explanation of Instructions" for the contents of the operand.)

"n4" is a radix, and can be specified from 1 to 16. The additions/subtractions are done in the numbering
system with n4 as the radix. Various counters (such as binary, octal, decimal and hexadecimal) can be
realized easily by software.

The Z flag indicates that an operation result is "0" or not in arithmetics with any numbering system. The
C flag indicates a carry/borrow according to the radix.

The following shows examples of these operation.

Example 1) Octal addition

ADC %B,%A,8

(C flag is "0" before operation)

Setting value

Result

F register

B register

A register

B register

E

I

C

Z

0010B(2)

0111B(7)

0001B(1)

0

1

0

0101B(5)

0011B(3)

0000B(0)

0

1

1

Example 2) Decimal subtractio

SBC %B,%A,10

(C flag is "0" before operation)

Setting value

Result

F register

B register

A register

B register

E

I

C

Z

1001B(9)

0111B(7)

0010B(2)

0

0

0

0001B(1)

0010B(2)

1001B(9)

0

1

0

Example 3) 3-digit BCD down counter

LDB

%EXT,0

; Counter base address [0010H]

LD

%XL,0x10

LDB

[%X]+,0

; Initial value setting [100]

LDB

[%X]+,0

LDB

[%X]+,1

:
:

CTDOWN:

; Count down subroutine----------

LDB

%EXT,0

; Counter base address [0010H]

LD

%XL,0x10

DEC

[%X]+,10

; Decrements digit 1

SBC

[%X]+,0,10

; Decrements carry from digit 2

SBC

[%X],0,10

; Decrements carry from digit 3

CALR CTDISP

; Count number display routine

LD

%A,0

; Zero check

ADD

%A,[%X]

ADD

%X,-1

ADD

%A,[%X]

ADD

%X,-1

JRNZ CTEXIT

; Return if counter is not zero

CALR CTOVER

; Count over processing routine

CTEXIT:

RET

This routine constructs a 3-digit BCD counter using the decimal operation instructions underlined.
Calling the CTDOWN subroutine decrements the counter, and then returns to the main routine. If the
counter has to be zero, the CTOVER subroutine is called before returning to the main routine to
process the end of counting.