Lecture 8 - Rabie A. Ramadan
Download
Report
Transcript Lecture 8 - Rabie A. Ramadan
Microprocessor
Dr. Rabie A. Ramadan
Al-Azhar University
Lecture 8
Z80 Assembly Programming
2
Arithmetic Operations
Addition and Subtraction
Increment/Decrement
1’s and 2’s Complement
3
Addition and Subtraction
Performed in relation to the contents of the operands .
ADD A, r Add the contents of register r to the contents
of the accumulator and stores the result back in the
accumulator . Needs only one byte.
ADD A, 8-bit Add 8-bit data directly to the accumulator
(2 bytes).
ADD A, (HL) Add memory contents to the accumulator
(1 byte)
4
Addition and Subtraction
SUB r subtracts the contents of register r
from the accumulator.
SUB 8-bit subtract 8-bit from the
accumulator
SUB (HL) subtract memory contents from
the accumulator
5
Increment/Decrement
Instructions
INC/DEC r increment/ Decrement the contents of
register r.
INC/DEC (HL) Increment/decrement the contents of
memory
INC/DEC rp Increment/ decrement register pair (HL,
DE, BC, SP)
One byte each
6
1’s and 2’s Complement
Instructions
Performs the complement on the accumulator
contents .
CPL 1’s complement or inverts the contents of the
accumulator (1 byte)
NEG 2’s complement. Subtracts the accumulator
from 00 (2 bytes)
7
Branch Operations
Jump instructions
Call and return instructions
Restart instructions
8
Jump Instructions
Absolute Jump
• Operands specifies the 16-bit address to which the
•
program sequence should be transferred
Three bytes instruction
Relative Jump
• Contains 8-bit displacement
• 2-byte instruction
9
Absolute Jump
Unconditional
Conditional
• Implemented based on the following flags
• S sign
• Z Zero
• CY Carry
• P/V Parity/overflow
• Two instructions are associated with each flag.
One when the flag is set and one when the flag is
reset
10
Absolute Jump
JP 16-bit Jump unconditional to memory location
specified by the 16-bit operand
JP C, 16-bit Jump on carry to 16-bit address (CY=1)
JP NC, 16-bit Jump on no carry to 16-bit address
(CY=0)
JP Z, 16-bit Jump on zero to 16-bit address (z = 1)
11
Absolute Jump
JP NZ, 16-bit jump on zero to 16-bit address (Z = 0)
JP M, 16-bit jump on minus to 16-bit address (S = 1)
JP P, 16-bit Jump on positive to 16-bit address (S=0)
JP PE, 16-bit Jump on parity even to 16-bit address
(P/V = 1)
JP PO, 16-bit Jump on parity odd to 16-bit address
(P/V = 0)
12
Relative Jump Instructions
Unconditional and Conditional types
The instruction followed by 8-bit
displacement/offset value
Offset could be positive (forward) (D6-D0
and MSB is always 0)
Offset could be negative (backward) (2’s
complement)
13
Relative Jump Instructions
JR d, Jump relative unconditionally
JR Z, d jump relative if Z = 1
JR NZ jump relative if Z = 0
JR C, d jump relative if CY = 1
JR NC, d Jump relative if CY = 0
There are no relative Jump instructions based on Sign
and Parity flags
14
Instructions related to Index
Registers
LD IX, 16-bit load 16-bit data into IX register
LD (IX+d), 8-bit load 8-bit into memory location
(IX+d)
LD r, (IX + d) copy from memory (IX+d)
location into r
LD (IX+d), r copy from r into memory (IX+d)
ADD A, (IX+d) add contents of memory (IX+d)
into A
SUB (IX+d) subtract contents of memory IX+d
from A
15
Instructions related to Index
Registers
INC IX Increment 16-bit contents of IX
INC (IX+d) Increment contents of
memory IX+d
DEC IX decrement 16-bit contents of IX
DEC (IX+d) decrement contents of
memory IX + d
16
Example
Write instructions to read incoming data from
input port INPORT , count the number of
readings , and add the readings. When the sum
exceeds FF, stop reading the port, store the
number of readings added in memory location
OUTBUF , and display 01 at the output port
OUTLED to indicate the overload?
See page 200 for the answer
17