microprocessor
Download
Skip this Video
Download Presentation
Microprocessor

Loading in 2 Seconds...

play fullscreen
1 / 44

Microprocessor - PowerPoint PPT Presentation


  • 104 Views
  • Uploaded on

Microprocessor. Dr. Rabie A. Ramadan Al-Azhar University Lecture 7. Z80 Assembly Programming. High-level language (C, C++, Pascal). compiler. Assembly language (Z80). assembler. Object code. linker. Machine language. Programming Phases. Z80 Instruction Set.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Microprocessor ' - lee-glover


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
microprocessor

Microprocessor

Dr. Rabie A. Ramadan

Al-Azhar University

Lecture 7

programming phases
High-level language

(C, C++, Pascal)

compiler

Assembly language (Z80)

assembler

Object code

linker

Machine language

Programming Phases
z80 instruction set
Z80 Instruction Set
  • First, You are required to look for Z80 assembler to try some of the programs.
  • Z80 Includes all 8080 instructions
  • Contains 158 instructions
  • Instruction  Opcode + Operands
instruction format
Instruction Format
  • Z80 instruction  ranges from one byte to four bytes
  • Opcode varies from 1 to 2 bytes
  • Operands varies from 1 to 2 bytes
  • Operands could be memory locations , registers, I/O addresses , or memory addresses
z80 instruction set1
Z80 instruction Set
  • Instructions can be classified to:
    • 1-Byte instructions
    • 2-Byte instructions
    • 3-Byte instructions
    • 4-Byte instructions
z80 instruction set2
Z80 Instruction Set
  • 1-Byte Instruction
    • The opcode and operands are included in the same byte
    • Ex.
      • LD A,B load B into A  01 111 000
      • LD  01 , A 1111 , and B 000
    • For microprocessor internal usage only
z80 instruction set3
Z80 Instruction Set
  • 2-Byte Instructions
    • Opcode  First Byte
    • Operand  Second Byte
    • Ex. LD B, 32H  0000 0110 (6H) byte 1

0011 0010 (32H) byte 2

Load the “32” value into register B

    • LD B is represented by 6H and the second byte includes “32”
z80 instruction set4
Z80 Instruction Set
  • 3-Byte Instruction
    • One byte Opcode and two bytes Operand
    • Ex. LD BC, 2080H
      • 0000 0001 byte 1 LD BC (01H)
      • 1000 0000 byte 2 80H
      • 0010 0000 byte 3 20H
    • Loads the value “2080H” into the two registers B and C
    • Note: the load starts by the low order byte followed by the high order  80 then 20
z80 instruction set5
Z80 Instruction Set
  • 4-Byte Instructions
    • Not compatible with 8080 instruction set
    • 2 bytes Opcode and 2 bytes Operand
    • Ex. LD IX , 2000H
      • Loads the contents of memory address 2000H into IX register  first 2 bytes
      • 0000 0000 (00H)  byte 3
      • 0010 0000 (20H)  byte 4
z80 instruction set6
Z80 Instruction Set
  • Instruction Categories
    • Data Copy  transfer or load operations
    • Arithmetic Operations
    • Logic Operations
    • Bit Manipulation
    • Branch Operation
    • Machine Control Operations
data copy instructions
Data Copy Instructions
  • From register to register
    • LD A, B  load B into A
  • Specific 8 bits data into register
    • LD B, 32H  load “32” into B
  • Specific 16 bits data into register
    • LD HL , 2080H  loads “2080” into HL
  • From memory location into register
    • LD A , (2010H)  load the content of memory location (2010) into A
data copy instructions1
Data Copy Instructions
  • From input port into accumulator
    • IN A, (01H)  loads data from Input port (01H) into A
  • From the accumulator into the o/p port
    • OUT (07H) , A
  • Copy the contents of register into stack memory
    • PUSH BC  pushes the BC contents into the stack
  • Exchange data between registers
    • EXX BC, DE
arithmetic instructions
Arithmetic Instructions
  • Addition
    • Any thing is only added to the contents of the accumulator.
    • No two registers such as B and C can be added directly.
    • ADD A, B  add B to the accumulator contents
    • ADD A, 97H  add the value “97H” to the accumulator content
arithmetic instructions1
Arithmetic Instructions
  • Subtraction
    • A register or memory location can be subtracted from the accumulator
    • SUB C  subtract the contents of register C from the accumulator
    • SUB 47H  subtract the “47H” from the accumulator
  • Note : the accumulator in implied in the instruction
arithmetic instructions2
Arithmetic Instructions
  • Increment/Decrement
    • Add / Sub1 to/from the contents of any register or memory location
    • INC B
    • DEC BC
arithmetic instructions3
Arithmetic Instructions
  • 1’s and 2’s Complement
    • Do 1’s or 2’s complement on the contents of the accumulator
    • CPL  one’s complement  changes the 1 to 0 and vice versa
    • NEG  2’s complement (subtract the accumulator from 0 ) or (Add 1 to the 1’s complement )
group activity
Group Activity
  • Write a simple program to load the values “53H” and “F5H” into registers A and B respectively. Then add the two registers?
  • LD A, 53H
  • LD B, F5H
  • ADD A, B
logic operations
Logic Operations
  • Logic Functions
    • AND , OR , XOR with the accumulator contents
    • AND B
  • Shift and Rotate
    • RLC B  rotate left the contents of B
  • Compare
    • Compare the contents of a register with the contents of a register or memory location  O/p will be shown on the flag register
    • CP B
bit manipulation
Bit Manipulation
  • Bit Test
    • Verify the value of a bit (0 or 1)
    • Z flag is the indicator
    • BIT 7, B  check bit 7 in register B
  • Bit Set/Reset
    • SET 5, B
    • RES 2, B
branching operations
Branching Operations
  • Jump
    • Change the program sequence
    • JP C, 2050H  if C flag is set , jump to 2050H
  • Call/Return
    • Change the program sequence by calling or returning from a sub routine
      • CALL 2050H  call subroutine located at 2050H
  • Restart
    • Memory are divided into pages
    • Page number 00 marked with 8 restart locations
    • RST 28H  restart from the location 28H
machine control operations
Machine Control Operations
  • Control the Z80 operations
  • HALT  Suspend execution of an instruction
how to write a program
How to write a program ?
  • Phases
    • Problem Statement
    • Analysis
    • Flowchart
    • Write the Assembly
    • Execute
write the assembly
Write the Assembly
  • Will try to get our hands dirty in the lab
addressing modes
Addressing Modes
  • A way of specifying the operand or pointing to a data location
    • Immediate
    • Immediate extended
    • Register
    • Implied
    • Register indirect
    • Extended
    • Relative
    • Indexed
    • Bit
    • Page Zero
implied memory addressing
Implied Memory Addressing
  • Registers H and L hold the address of the memory location being accessed
    • LD C, (HL)  loads C register with the contents of the memory location pointed by HL registers
addressing modes1
Addressing Modes
  • Immediate
    • A byte following the opcode is the operand
    • LD B, 97H  97h id the value
  • ImmediateExtended
    • Two bytes following the opcode are the operands
    • LD BC , 3040H  3040H are the 2 bytes value
  • Register
    • Operand is a register
    • LD A, B  B is a register
addressing modes2
Addressing Modes
  • Implied
    • The opcode imply one of the operands
    • AND B  AND implies that the operation is done on the accumulator contents
  • RegisterIndirect
    • Register holds the memory location address
    • LD B, (HL)  the memory location is stored in H and L registers
  • Extended
    • The two bytes following the opcode specify the jump location
    • JP 208H
addressing modes3
Addressing Modes
  • Relative
    • The oprand indicates the placement of the next instruction to be executed relative to the current one
    • JR 14H  from the next instruction , jump 20 locations
  • Indexed
    • Use one of the index registers to define the next instruction location
    • INC (IX+10H)  if IX contains 2080H , then the content of the memory location (2080 +10) will be incremented
addressing modes4
Addressing Modes
  • Bit
    • Used with bit operations
    • SET 7, B
  • Page zero
    • Reset operation
    • RST 28H
reading materials
Reading Materials
  • Chapters 6 and 7
  • Please find one of the free Z80 assemblers and play with it
load instruction
Load Instruction
  • LD rd , rs copy data from rsto rd
  • LD r, 8-bit  immediate addressing mode , loaf 8 bit number into register r
    • LD B, 32H
  • LD rp , 16- bit  immediate extended addressing mode , load 16-bits into register pair
    • LD HL, 1840H
  • LD rx, 16-bit  immediate extended addressing mode , loads 16 bits into specified index register
    • LD IX, 2050H
load instructions example
Load instructions Example
  • Write a program to do the following:
    • Load 97h into the accumulator
    • Loads 2050H into HL register
    • Loads 2070H into IX register
    • Copy the contents of the accumulator into register C
    • Copy the contents of register H into register B
    • End the instructions by HALT
    • Write all of these instructions at the memory locations started at 2000H
    • Show the register contents by the end of this program ?
data copy between registers and memory
Data Copy Between Registers and Memory
  • Memory Address stored in 16 bits
  • LD r, (HL)  Indirect Addressing mode , loads the contents of a memory location whose address is stored in HL register pair
    • LD , B, (HL)
  • LD (HR), r  Indirect Addressing mode , loads the contents of a register into a memory location whose address is stored in HL register pair
    • LD (HL) , C
  • LD (HL), 8-bit  indirect and immediate , copy 8-bit into a memory location whose address is stored in HL register pair.
    • LD (HL), 97H
data copy between registers and memory1
Data Copy Between Registers and Memory
  • LD A, (rp)  indirect , copy the contents of a memory into A
  • LD (rp) , A indirect , copy the contents of A into a memory location
    • LD (BC), A
  • LD A, (16-bit)  Extended , copy contents of memory into accumulator
  • LD (16-bit), A  Extended , copy contents of the accumulator into memory
    • LD (2050H), A
data copy between registers and memory example
Data Copy Between Registers and Memory Example
  • The memory location 2050H contains the data byte 37H , write instructions to copy a byte from the memory location into register B?
answer1
Answer
  • Method 1:
    • LD HL, 2050H
    • LD B, (HL)
  • Method 2:
    • LD DE, 2050H
    • LD A, (DE)
    • LD B, A
  • Method 3:
    • LD A, (2050H)
    • LD B,A
data copy between accumulator and i o
Data Copy Between Accumulator and I/O
  • IN A, (8-bit) read data from input port to the accumulator
  • OUT (8-bit) , A  write data into the output port
  • See Example in Page 191
group activity1
Group Activity
  • Write comments to explain the function of the following instructions
    • LD HL, 2065H
    • LD (HL), 00H
    • HALT
group activity2
Group Activity
  • Specify the contents of the registers and memory locations if any after the execution of the following instructions:
  • A B C H L
  • 34 7F FF 01 00
  • LD A, 00H
  • LD BC, 8058H
  • LD B, A
  • LD HL, 2040H
  • LD L,C
  • LD (HL), A
  • HALT
slide44
Useful Links are now available on the website
  • http://www.diylife.com/2008/02/15/program-a-pic-microcontroller/
  • http://www.promeganet.com/?p=3
  • http://www.promeganet.com/?page_id=233
  • http://www.arabteam2000-forum.com/index.php?showtopic=76314
ad