|
|
ASMSchool - Lesson 3
In this lesson, you will learn a bit about some more arithmetic instructions and some CPU controlling instructions.
General Purpose Arithmetic & CPU Control
There are a few instructions that don't fall under any of the other categories, mostly for the reason that they accomplish certain special tasks on the system.
DAA
This is the Decimal Adjust Accumulator instruction. It converts the value in A into a packed BCD (binary coded decimal) number. This instruction is used about as often as you'll win the lottery, so I wont detail it.
Flags affected are:
Z: set according to result
C: set according to result
N: reset (0)
H: set according to result
CPL
CPL is ComPLement A. It basically takes A and applies a one's complement. Which, I believe is just inverting all of the bits. EG: $02 would end up as $FD.
Flags affected are:
Z: no effect
C: no effect
N: set (1)
H: set (1)
SWAP r or (HL)
This instruction swaps the high and low nybble's of A. So $F0 becomes $0F, etc.
Flags affected are:
Z: set according to result
C: reset (0)
N: reset (0)
H: reset (0)
CCF
Complement Carry Flag - Simply inverts the carry flag in register F.
Flags affected are:
Z: no effect
C: set according to result
N: reset (0)
H: reset (0)
SCF
Set Carry Flag - Simply sets the carry flag (CY=1).
Flags affected are:
Z: no effect
C: set (1)
N: reset (0)
H: reset (0)
NOP
No Operation - CPU does nothing for 1 instruction cycle.
Flags affected are:
Z: no effect
C: no effect
N: no effect
H: no effect
HALT
HALT's the CPU until an interrupt occurrs. During HALT, the CPU power consumption is reduced. It's generally pretty smart to place two NOP's after a HALT due to a hardware bug.
Flags affected are:
Z: no effect
C: no effect
N: no effect
H: no effect
STOP
STOP's the CPU. The only way to start the CPU again is to turn off the GB and turn it back on, OR if using STOP on a GBC, it can be used to toggle the CPU speed (more in another lesson).
Flags affected are:
Z: no effect
C: no effect
N: no effect
H: no effect
DI
Disable Interrupts. Turns off all hardware interrupts. Use this if you want to run a piece of code and have it run uninterupted (lol).
Flags affected are:
Z: no effect
C: no effect
N: no effect
H: no effect
EI
Enable Interrupts. Enables hardware interrupts to occur.
Flags affected are:
Z: no effect
C: no effect
N: no effect
H: no effect
Wow, alot of handy tools those instructions are. Each has it's own use and you'll probably use most of them often. One of the big ones is DI, which most coders put at the very beginning of the game, so as to setup the gameboy hardware and load data without being interrupted. There are uses for the rest that you'll see later on. That's it for this lesson.
|
|
|
|
|