SBC (Subtract With Borrow)
SBC (Subtract With Borrow)
; assume carry=1
; A <==BDH
A=A-(IY+d)-carry
rp: BC,DE,HL,SP
HL=HL-rp-carry
SET b,r
==> 2 bytes
SET b,(HL) ==>2 bytes
SET b,(IX+d) ==>4 bytes
SET b,(IY+d)
RLA
==> 1 byte
Equivalent to RL A
but flags are not affected (except N=0).
RLCA
==> 1 byte
Equivalent to RLC A
but flags are not affected (except N=0).
RRA
==> 1 byte
Equivalent to RR A
but flags are not affected (except N=0).
RRCA
==> 1 byte
Equivalent to RRC A
but flags are not affected (except N=0).
==> 2 bytes
Rotate right one hex digit between the accumulator and memory location
addressed by HL.
RRD
==> 2 bytes
ASSEMBLY DIRECTIVES
(PSEUDO OPERATIONS)
These are not Assembly language instructions, but they are rather
directives to the compiler.
EQU (equate): allows the programmer to equate labels and names with addresses
or data.
example:
NUMBER1 EQU 5
ADDRESS EQU 5000H
LD A, NUMBER1
; A5, value of 5 is loaded into the accumulator
LD A, (ADDRESS) ; A (5000H), contents of memory location 5000H are
loaded into the accumulator
ASSEMBLY DIRECTIVES
(PSEUDO OPERATIONS)
DB (Define byte): locates 8-bit immediate data in memory.
DW (Define word): locates 16-bit immediate data in memory.
example for DB:
LD A, (NUM1) ; A 12H
LD E, A
LD A, (NUM2) ; A 2FH
ADD A, E
; A 12H + 2FH=41H
HALT
NUM1 DB 12H
NUM2 DB 2FH
During compiling, the assembler assigns
each label the address value for the memory
location into which a DB pseudo operation
stores a byte. Then symbols in an instruction's
operand field, that match a label, are replaced
by the address value assigned to that label.
ASSEMBLY DIRECTIVES
(PSEUDO OPERATIONS)
example for DW:
LD HL, (NUM1) ; HL 22FFH
LD BC, (NUM2) ; BC AB36H
ADD HL,BC
HALT
NUM1 DW 22FFH
NUM2 DW AB36H
Each label is assigned the address value
for the two memory locations into which
a DW pseudo operation stores two bytes.
Then symbols in an instruction's operand
field, that match a label, are replaced by
the address value assigned to that label.
ASSEMBLY DIRECTIVES
(PSEUDO OPERATIONS)
ORG (Origin): allows the programmer to locate programs, subroutines, or data
anywhere in memory. Programs and data may be located in different areas of
memory.
example:
ORG 2000H ; locates program in memory starting from 2000H
LD A, 1
.
.
ORG 3000H ; locates data in memory starting from 3000H
NUM1 DB 28H
NUM2 DB 05H
ASSEMBLY DIRECTIVES
(PSEUDO OPERATIONS)
DS (Define storage): allows the programmer to locate memory locations for a
block of data.
example:
ORG 2000H
VALUE DS 1
TABLE DS 20
LD A,3FH
LD (VALUE),A ;
(2000H)3FH
LD IX,TABLE
LD (IX+1),A
ASSEMBLY DIRECTIVES
(PSEUDO OPERATIONS)
END: marks the end of the assembly language source program for a compiler.
The HALT instruction suggests the end of a program, but that does not necessarily
mean the end of assembly
example:
.
.
.
HALT
END
This is my first Z80 Assembly language program
I really worked hard for it! :
_________________________________________________________________
You can write any comments, or story, after the END directive.
Assembler will just ignore them.
20
Flowchart Components
21
Example Flowchart
Simple Programs
Simple Programs
Simple Programs
Simple Programs
Simple Programs
Simple Programs
Simple Programs
Simple Programs
Simple Programs
Load a byte of data into the accumulator from the I/O port identified by 8-bit
portaddress.
example:
assume that data byte 36H is available at the data bus of the port with
I/O address 80H.
IN A,(80H) ; A<== 36H
example: assume that data byte 36H is available at the data bus of the port with
I/O address 80H.
LD C,80H
IN D,(C) ;
D<== 36H
Output the contents of the accumulator to the I/O port identified by 8-bit
portaddress.
example:
LD A,36H
OUT (80H),A ; (80H)<== A
data byte 36H is sent to the data bus of the port
with I/O address 80H.
LD D,36H
LD C,80H
OUT (C),D ;
(80H)<== D
Reading Assignment
Please Read
Chapter 6
Chapter 7
Chapter 8
Chapter 9