Documente Academic
Documente Profesional
Documente Cultură
A B D H F C E L
doppelt vorhanden
Programmbeispiel Z80
IX IY SP PC
Z80
Vorlesung Datenverarbeitung 1
WS 2005/2006
Programmbeispiel Z80
The assembly program:
ORG 100H LD HL,1234H LD A,(HL) INC HL ADD A,(HL) INC HL LD (HL), A END ORG 1234H DB 100,200 ;Locate program at 100H ;Address of first number ;Operand 1 into Accu ;Address of 2nd number ;Addition ;Address of result (sum) ;store result ;end of program ;Location of the data ;put 64H and C8H
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
The listing generated by the assembler:
0001 0002 0003 0004 0005 0006 0007 0008 0009 0108 0011 0012 0013 1234 64 C8 ORG 1234H DB 100,200 ;Location of the data ;put 64H and C8H 0100 21 34 12 0103 7E 0104 23 0105 86 0106 23 0107 77 ORG 100H LD LD INC ADD INC LD END HL,1234H A,(HL) HL A,(HL) HL (HL), A ;Locate program at 100H ;Address of first number ;Operand 1 into Accu ;Address of 2nd number ;Addition ;Address of result (sum) ;store result ;end of program ; Assembly program Z80 Lecture "Datenverarbeitung 1"
Number of errors = 0
Vorlesung Datenverarbeitung 1
WS 2005/2006
Programmbeispiel Z80
Before start: Program located at 100H. Program counter points to that address. There are 2 numbers (data) at 1234H and 1235H.
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
Program
PC
0100
64 C8
Data
WS 2005/2006
Programmbeispiel Z80
1st instruction: LD HL,1234H ;Address of first number Meaning: HL:=1234H and (of course) PC:=PC+3
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
Program
PC
0100
64 C8
Data
Before...
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
1st instruction: LD HL,1234H ;Address of first number Meaning: HL:=1234H and (of course) PC:=PC+3
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
Program
1234
PC
0103
64 C8
Data
...After
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
2nd instruction: LD A,(HL) ;Operand 1 into Accu Meaning: A:=[HL] and (of course) PC:=PC+1
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
Program
1234
PC
0103
64 C8
Data
Before...
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
2nd instruction: LD A,(HL) ;Operand 1 into Accu Meaning: A:=[HL] and (of course) PC:=PC+1
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
64
Program
1234
PC
0104
64 C8
Data
...After
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
3rd instruction: INC HL ;Address of 2nd number Meaning: HL:=HL+1 and PC:=PC+1
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
64
Program
1234
PC
0104
64 C8
Data
Before...
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
3rd instruction: INC HL ;Address of 2nd number Meaning: HL:=HL+1 and PC:=PC+1
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
64
Program
1235
PC
0105
64 C8
Data
...After
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
4th instruction: ADD A,(HL) ;Addition Meaning: A:=A+[HL] and PC:=PC+1
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
64
Program
1235
PC
0105
64 C8
Data
Before...
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
4th instruction: ADD (HL) ;Addition Meaning: A:=A+[HL] and PC:=PC+1
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
2C
Flags 00xxx0x1
Program
1235
PC
0106
64 C8
Data
...After
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
5th instruction: INC HL ;Address of result (sum) Meaning: HL:=HL+1 and PC:=PC+1
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
2C
Flags 00xxx0x1
Program
1235
PC
0106
64 C8
Data
Before...
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
5th instruction: INC HL ;Address of result (sum) Meaning: HL:=HL+1 and PC:=PC+1
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
2C
Program
1236
PC
0107
64 C8
Data
...After
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
6th instruction: LD (HL), A ;store result Meaning: [HL]:=A and PC:=PC+1
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
2C
Program
1236
PC
0107
64 C8
Data
Before...
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
Programmbeispiel Z80
6th instruction: LD (HL), A ;store result Meaning: [HL]:=A and PC:=PC+1
0100 0101 0102 0103 0104 0105 0106 0107 21 34 12 7E 23 86 23 77
Accu
Flags
2C
Program
1236
PC
0108
64 C8 2C
Data
Programmbeispiel Z80
Z80 Flags S Z X H X P/V N C
Sign Zero no flag Half-Carry (Addition) for BCD Arithmetic no flag Parity/Overflow Half-Carry (Subtraction) for BCD Arithmetic Carry
Vorlesung Datenverarbeitung 1 WS 2005/2006 Dr.-Ing. Stefan Freinatis
S Z X H X P/V N C