2 MEMORY AND OPERATIONS

2.3 ALU (Arithmetic Logic Unit) and Registers

Table 2.3.1 shows ALU operations between the 4-bit registers, TEMPA and TEMPB.

Table 2.3.1 ALU register operation

Operation

Instruction

Add, without carry

ADD

Add, with carry

ADC

Subtract, without borrow

SUB

Subtract, with borrow

SBC

Logical-AND

AND

Logical-OR

OR

Exclusive-OR

XOR

Comparison

CP

Flag bit test

FAN

Rotate right, with carry

RRC

Rotate left, with carry

RLC

Invert

NOT

 

 

The Z (zero) flag is set when the result of ALU operation is

C

3

2

1

0

 

X

0

0

0

0

X: Don't care.

The C (carry) flag is set when an add operation causes a carry or when a subtract operation causes a borrow.

2.3.1 D (decimal) flag and decimal operations

Setting the D (decimal) flag activates the decimal mode, allowing decimal addition and subtraction. Table

2.3.1.1shows the relations of actual (decimal) results, ALU outputs, and the values of the C and Z flags.

Table 2.3.1.1 Results of hexadecimal and decimal operations

 

 

 

 

 

Addition

 

 

 

 

 

 

 

 

Subtraction

 

 

 

 

 

 

Actual

 

D = 0 : Result of

 

D = 1 : Result of

Actual

 

D = 0 : Result of

 

 

D = 1 : Result of

 

 

result

hexadecimal operation

decimal operation

result

hexadecimal operation

 

decimal operation

 

 

 

Z

 

C

ALU output

Z

 

C

ALU output

 

Z

 

C

ALU output

 

Z

 

C

ALU output

 

 

0

1

 

0

0

1

 

0

0

-16

1

 

1

0

 

0

 

1

A

 

 

1

0

 

0

1

0

 

0

1

-15

0

 

1

1

 

0

 

1

B

 

 

2

0

 

0

2

0

 

0

2

-14

0

 

1

2

 

0

 

1

C

 

 

3

0

 

0

3

0

 

0

3

-13

0

 

1

3

 

0

 

1

D

 

 

4

0

 

0

4

0

 

0

4

-12

0

 

1

4

 

0

 

1

E

 

 

5

0

 

0

5

0

 

0

5

-11

0

 

1

5

 

0

 

1

F

 

 

6

0

 

0

6

0

 

0

6

-10

0

 

1

6

 

1

 

1

0

 

 

7

0

 

0

7

0

 

0

7

-9

0

 

1

7

 

0

 

1

1

 

 

8

0

 

0

8

0

 

0

8

-8

0

 

1

8

 

0

 

1

2

 

 

9

0

 

0

9

0

 

0

9

-7

0

 

1

9

 

0

 

1

3

 

 

10

0

 

0

A

1

 

1

0

-6

0

 

1

A

 

0

 

1

4

 

 

11

0

 

0

B

0

 

1

1

-5

0

 

1

B

 

0

 

1

5

 

 

12

0

 

0

C

0

 

1

2

-4

0

 

1

C

 

0

 

1

6

 

 

13

0

 

0

D

0

 

1

3

-3

0

 

1

D

 

0

 

1

7

 

 

14

0

 

0

E

0

 

1

4

-2

0

 

1

E

 

0

 

1

8

 

 

15

0

 

0

F

0

 

1

5

-1

0

 

1

F

 

0

 

1

9

 

 

16

1

 

1

0

0

 

1

6

0

1

 

0

0

 

1

 

0

0

 

 

17

0

 

1

1

0

 

1

7

1

0

 

0

1

 

0

 

0

1

 

 

18

0

 

1

2

0

 

1

8

2

0

 

0

2

 

0

 

0

2

 

 

19

0

 

1

3

0

 

1

9

3

0

 

0

3

 

0

 

0

3

 

 

20

0

 

1

4

0

 

1

A

4

0

 

0

4

 

0

 

0

4

 

 

21

0

 

1

5

0

 

1

B

5

0

 

0

5

 

0

 

0

5

 

 

22

0

 

1

6

0

 

1

C

6

0

 

0

6

 

0

 

0

6

 

 

23

0

 

1

7

0

 

1

D

7

0

 

0

7

 

0

 

0

7

 

 

24

0

 

1

8

0

 

1

E

8

0

 

0

8

 

0

 

0

8

 

 

25

0

 

1

9

0

 

1

F

9

0

 

0

9

 

0

 

0

9

 

 

26

0

 

1

A

1

 

1

0

10

0

 

0

A

 

0

 

0

A

 

 

27

0

 

1

B

0

 

1

1

11

0

 

0

B

 

0

 

0

B

 

 

28

0

 

1

C

0

 

1

2

12

0

 

0

C

 

0

 

0

C

 

 

29

0

 

1

D

0

 

1

3

13

0

 

0

D

 

0

 

0

D

 

 

30

0

 

1

E

0

 

1

4

14

0

 

0

E

 

0

 

0

E

 

 

31

0

 

1

F

0

 

1

5

15

0

 

0

F

 

0

 

0

F

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

10

EPSON

S1C6200/6200A CORE CPU MANUAL