- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Addition of multi-byte numbers in Z-80
Now, in this section we will see how we can use the Zilog Z-80 Microprocessor to add Multi-byte numbers.
In this example, we are using 4-byte numbers (56 2F 7A 89)16 and (21 FB A9 AF)16
In the memory, at first, we are storing the byte counts, and then the numbers (from least significant bytes to Most significant bytes) in different segments. So after storing the data, the memory structure will be look like this
Address | Value |
---|---|
5000H | 04H |
. . . | |
5050H | 89H |
5051H | 7AH |
5052H | 2FH |
5053H | 56H |
. . . | |
5070H | AFH |
5071H | A9H |
5072H | FBH |
5073H | 21H |
. . . |
Now, we are writing a program at location 8000H to add these two 4-byte number and store the result at location 5090H onwards.
Program
Address | Hex Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
8000 | 37 | SCF | Set the carry flag | |
8001 | 3F | CCF | Complement the carry flag | |
8002 | 21 00 50 | LD HL, 5000H | Load 5000h into HL pair | |
8005 | DD 21 50 50 | LD IX, 5050H | Set 5050 into index register IX | |
8009 | DD 7E 00 | LOOP | LD A, (IX+0H) | Load accumulator with IX + 00H |
800C | DD 8E 20 | ADC A, (IX+20H) | Add IX + 20H with Acc and Carry | |
800F | DD 77 40 | LD (IX+40H), A | Store accumulator data at IX + 40H | |
8012 | DD 23 | INC IX | Increase IX register | |
8014 | 35 | DEC (HL) | Decrease the memory content, pointer by HL pair | |
8015 | C2 09 80 | JP NZ, LOOP | Jump to Loop, until it is 0 | |
8018 | D2 20 80 | JP NC, DONE | If Carry flag is off, go to Done | |
801B | DD 36 40 01 | LD (IX+40H), 01 | Store 01H at location IX + 40H | |
801F | 76 | HALT | Halt the program | |
8020 | DD 36 40 00 | DONE | LD (IX+40H), 00 | Store 00H at location IX + 40H |
8024 | 76 | HALT | Halt the program |
Output
Address | Value |
---|---|
5000H | 04H |
. . . | |
5050H | 89H |
5051H | 7AH |
5052H | 2FH |
5053H | 56H |
. . . | |
5070H | AFH |
5071H | A9H |
5072H | FBH |
5073H | 21H |
. . . | |
5090H | 38H |
5091H | 24H |
5092H | 2BH |
5093H | 78H |
5094H | 00H |
Advertisements