microprocessor dr. rabie a. ramadan al-azhar university lecture 8
TRANSCRIPT
![Page 1: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/1.jpg)
Microprocessor
Dr. Rabie A. RamadanAl-Azhar University
Lecture 8
![Page 2: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/2.jpg)
Z80 Assembly Programming
2
![Page 3: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/3.jpg)
Arithmetic Operations
Addition and Subtraction Increment/Decrement 1’s and 2’s Complement
3
![Page 4: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/4.jpg)
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
![Page 5: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/5.jpg)
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
![Page 6: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/6.jpg)
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
![Page 7: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/7.jpg)
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
![Page 8: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/8.jpg)
Branch Operations
Jump instructions
Call and return instructions
Restart instructions
8
![Page 9: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/9.jpg)
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
![Page 10: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/10.jpg)
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
![Page 11: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/11.jpg)
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
![Page 12: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/12.jpg)
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
![Page 13: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/13.jpg)
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
![Page 14: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/14.jpg)
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
![Page 15: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/15.jpg)
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
![Page 16: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/16.jpg)
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
![Page 17: Microprocessor Dr. Rabie A. Ramadan Al-Azhar University Lecture 8](https://reader036.vdocument.in/reader036/viewer/2022083009/5697bfae1a28abf838c9c635/html5/thumbnails/17.jpg)
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