General-Purpose Arithmetic Operations/Cpu Control Instructions - Nintendo GAME BOY Programming Manual

Hide thumbs Also See for GAME BOY:
Table of Contents

Advertisement

Game Boy Programming Manual
2.9 General-Purpose Arithmetic Operations and CPU Control Instructions
DAA
When performing addition and subtraction, binary coded decimal representation is used to set the
contents of register A to a binary coded decimal number (BCD).
The following table shows the processing that accompanies execution of the DAA instruction immediately
following execution of addition (ADD and ADC)and substraction (SUB and SBC) instructions.
Instruction
Before
Execution
ADD
ADC
(N = 0)
SUB
SBC
(N = 1)
Examples: When A = 45h and B = 38h,
ADD A, B ; A ← 7Dh, N ← 0
DAA
SUB A, B ; A ← 83h – 38h (4Bh), N ← 1
DAA
CPL
Takes the one's complement of the contents of register A.
Example: When A = 35h,
CPL
;
NOP
Only advances the program counter by 1; performs no other operations that have an effect.
Decimal
adjust acc
CY Contents
before
Bits 4-7
Execution
Register A
0h
9h
0
-
0h
8h
0
-
0h
9h
0
-
Fh
0
Ah-
9h
Fh
0
-
Fh
0
Ah-
0h
2h
1
-
0h
2h
1
-
0
3h
1
h-
0h
9h
0
-
0h
8h
0
-
7h
Fh
1
-
6h
Fh
1
-
; A ←7Dh + 06h (83h), CY ← 0
; A ← 4Bh + FAh (45h)
A ← A
A ← CAh
No operation
CY
H
N
*
0
--
H Contents
before
Bits 0-3
Execution
Register A
0h
9h
0
-
Fh
0
Ah-
0h
3h
1
-
0h
9h
0
-
Fh
0
Ah-
0h
3h
1
-
0h
9h
0
-
Fh
0
Ah-
0h
3h
1
-
0h
9h
0
-
6h
Fh
1
-
0h
9h
0
-
6h
Fh
1
-
CY
H
N
--
1
1
CY
H
N
--
--
--
122
Z
CYCL
7 6
5 4 3
*
1
00
100
Number Added
to Register A
00h
06h
06h
60h
66h
66h
60h
66h
66h
00h
FAh
A0h
9Ah
Z
CYCL
7 6
5 4 3
--
1
00
101
Z
CYCL
7 6
5 4 3
--
1
00
000
2 1 0
111
CY Contents
after
Execution
0
0
0
1
1
1
1
1
1
0
0
1
1
2 1 0
111
2 1 0
000

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents