Posts

Showing posts from August, 2014

ASSIGNMENTS on INTRODUCTION TO Z80 INSTRUCTIONS AND PROGRAMMING TECHNIQUES (part2)

Image
ASSIGNMENTS on INTRODUCTION TO Z80 INSTRUCTIONS AND PROGRAMMING TECHNIQUES (part2) 25. Rewrite the instructions in Figures 8.2 (a), (b), and (c) using the index regis­ters IX and IY as memory pointers. 26. Write instructions to load XX70 H into the IY index register. Using the regis­ter IY as a memory pointer with appropriate offsets, store the bytes A2 H and 32 H in memory locations XX4F H and XX9F H , respectively. 27. Calculate the value of the memory pointer if register IX contains 2000 H with the displacement byte 80 H . 28. Calculate the values of two memory pointers if register IY contains-20FF H and it is combined with the displacement bytes 7F H and 8F H . 29. Assuming the index register IX contains 2050 H , explain the difference be­tween the instructions INC IX and INC (IX + 0). 30. Rewrite Illustrative Program l (Section 8.6), Block Transfer of Data Bytes, using the index registers as memory pointers. 31. Draw a flowchart to add the numbers stored i...

ASSIGNMENTS on INTRODUCTION TO Z80 INSTRUCTIONS AND PROGRAMMING TECHNIQUES( part 1)

Image
ASSIGNMENTS on INTRODUCTION TO Z80 INSTRUCTIONS AND PROGRAMMING TECHNIQUES Note : In the following assignments, substitute high-order memory address XX with the high-order address and PORT with the output port address of your single-board microcomputer system, Use your own data if data are not given, and specify memory addresses for labels such as INBUF and OUTBUF. Section l. Write mnemonics to load 39 H into register B and 92 H into register D. Save the contents of B in register L, and display the contents of D at PORT 1. 2. Write instructions to load 47 H into register Band F2 H into register C using one instruction. Store the contents of C in memory location XX80 H and dis­play the contents of B at PORTl. Assemble the Hex code and store the code in memory. 3. Write instructions to load A2 H into register D and XX80 H into register HL.Copy the contents of D into memory location XX80 H . 4. Write instructions to load A7 H into register D and XX55 H into register BC....

SUMMARY off INTRODUCTION TO Z80 INSTRUCTIONS AND PROGRAMMING TECHNIQUES

Image
SUMMARY off INTRODUCTION TO Z80 INSTRUCTIONS AND PROGRAMMING TECHNIQUES   In this chapter, we illustrated a group of instructions from the Z80 set frequently used in writing programs. Instructions were selected from three groups: data copy, arithmetic, and branch. These instructions range from 1 byte to 4 bytes long. General characteristics of these instructions are as follows: 1. The data copy and load instructions copy the contents of the source into the destination without affecting the source contents. They do not affect the flags. 2. The arithmetic instructions (with some exceptions) assume one of the oper­ands is the accumulator, and the result of an operation is usually stored in the accumulator. Most of these instructions affect the flags. 3. The conditional Jump instructions are decision-making instructions and are executed according to the status of the flags. Not all instructions affect the flags; in particular, the data copy instructions and 16-bit increment...

ILLUSTRATIVE PROGRAM 3: BLOCK TRANSFER OF DATA BYTES USING Z80 SPECIAL INSTRUCTIONS

Image
ILLUSTRATIVE PROGRAM 3: BLOCK TRANSFER OF DATA BYTES USING Z80 SPECIAL INSTRUCTIONS   This program transfers data from one memory block to another using the Z80 instruction LDIR. Problem Statement Modify the illustrative program (Section 8.6.3) using the instruction LDIR with the problem statement as follows: Transfer 1024 (1K) bytes from the memory block SOURCE (0000H) to the memory block OUTBUF (1900H), and indicate the end of data transfer by displaying 01 at PORT0. Problem Analysis To use the instruction LDIR, the HL register should be used to point to memory SOURCE and the DE register to the destination OUTBUF, and the register BC should be used as the counter with the 16-bit count (03FF H = 1024 bytes). Program Label Mnemonics Comments START: LD HL, SOURCE ;Set up HL...

Z80 SPECIAL INSTRUCTIONS

Image
Z80 SPECIAL INSTRUCTIONS The Z80 instruction set includes some instructions that perform more than one task. These instructions improve programming efficiency considerably. Some of these instructions are: Mnemonics Description DJNZ d Decrement B and Jump Relative on no zero (Z = 0) The instruction decrements register B, and if B # 0, it jumps to the memory address specified by the offset value d. LDI Load and Increment The instruction copies a data byte from the memory location shown by HL into the memory location indicated by DE_. Reg­isters HL and DE are incremented. and BC is decrement LDIR Load, Increment, and Repeat This is similar to the instruction LDI, except ...

DEBUGGING A PROGRAM

Image
DEBUGGING A PROGRAM Debugging a program is similar to troubleshooting hardware, but it is much more difficult and cumbersome. When a program fails to work, very few clues alert you to what exactly went wrong. Therefore, it is essential to search carefully for the errors in the program logic, machine code, and execution. The debugging procedure can be divided into two parts: static debugging and dynamic debugging . Static debugging is similar to visual inspection of a circuit board; it is the paper-and-pencil check of a flowchart and machine code. Dynamic debugging involves observing out puts; register contents, and flags following the execution of either instruction (the single-step technique) or a group of instruc­tions (the breakpoint technique). Static Debugging of Machine Code Translating the assembly language into the machine code is similar to building a circuit from a schematic in that the machine code will have errors just as would the circuit board. If an assembler ...

Data Copy Between Z80 Registers and Memory

Image
Data Copy Between Z80 Registers and Memory To copy data from and into memory, the 16-bit address of a selected memory register must be specified, and this memory address can be specified by using indirect, direct, or other addressing modes in the indirect addressing mode, the address of a memory location is loaded into the HL register, and the register (HL) with the parentheses is used as a memory pointer to copy data. Registers BC and, DE can also be used in this manner, with some restrictions. In the direct addressing mode, the 16-bit address of a memory location is used as the operand of the copy instruction. Methods using index registers are-discussed after the discussion of 2's complement arithmetic because the index registers include a displacement byte, which is expressed as a signed 2's complement number. In Z80 mnemonics, the memory address is enclosed in parentheses, as shown in the following list. Opcode ...

ILLUSTRATIVE PROGRAM 2: ADDITION WITH CARRY

Image
ILLUSTRATIVE PROGRAM 2: ADDITION WITH CARRY The following program adds the number of bytes stored in memory and counts the number of carries generated. The maximum sum can be up to 16-bit. Problem Statement Add the following ten data bytes stored in memory with the starting address INBUF (Input Buffer). Store the sum in two memory locations; the low-order byte of the sum should be stored in OUTBUF and the high-order byte in OUTBUF + 1. Data (H): A2; 37, 4F, 97, 22, 6B, 75, 8E, 9A, C7. Problem Analysis This problem is similar to Example 8.11 and can be very easily analyzed in terms of the blocks shown in the generalized flowchart in Figure. 1. In the initialization block, we need to set up a counter to count ten bytes, a memory pointer for INBUF, and registers to save the partial sum and carries. We use the accumulator for addition. The memory pointer for OUTBUF is not necessary until the data processing is completed: thus, the memory pointer used for INBUF can also be use...

ILLUSTRATIVE PROGRAM 1: BLOCK TRANSFEER OF DATA BYTES

Image
ILLUSTRATIVE PROGRAM 1: BLOCK TRANSFEER OF DATA BYTES In practical applications, data transfer from one memory block to another is a com­mon occurrence. This illustrative program demonstrates how to copy data bytes from one block of memory to another using the instructions discussed previously. Problem Statement Ten bytes of data are stored in a block of memory; the first location is labeled SOURCE (1850 H ). Transfer all data bytes to a new block starting with the location labeled OUTBUF (Output Buffer = 1870 H ). When the data transfer is complete, display 01 at the output port PORT0. Problem Analysis Ten bytes are already stored in the memory block from 1850 H to 1859 H (Figure). These bytes must be copied into the memory block from I870 H to 1879 H ; these are called no overlapping memory blocks. This problem is similar to Ex­ample repeated ten times. Therefore, we must copy one byte from 1850 H into the Z80 microprocessor and then copy the byte into 1870 H as show...

PROGRAMMING TECHNIQUES: LOOPING. COUNTING, AND INDEXJHG

Image
PROGRAMMING TECHNIQUES: LOOPING. COUNTING, AND INDEXJHG The examples illustrated in the previous sections are simple and can be solved manually. However, a computer is at its best, surpassing human capability, when it has to repeat such tasks as adding a large set of numbers or copying bytes from one block of memory locations to another. It is fast and accurate. To perform a given repetitive task, commonly used techniques are looping, counting, and indexing. To add data bytes stored in memory, for example, the following steps are necessary. I. Define the task to be repeated : Looping . A loop is set up by using either a conditional Jump or an unconditional Jump as illustrated in Examples. 2. Specify how many times the task is to be repeated: Counting . The counter is set by loading a count (number of times the task is to be re­peated) .into a register or a register pair, and the counting is done by decre­menting the count every time the loop is repeated. The counter can al...

Z80 INSTRUCTIONS RELATED TO INDEX REGISTERS

Image
Z80 INSTRUCTIONS RELATED TO INDEX REGISTERS   The Z80 microprocessor includes two 16-bit index registers IX and IY, and they are used primarily as memory pointers. In the previous sections, we discussed instructions concerning data copy, arithmetic, and branch operations. The Z80 can perform these operations with the contents of memory registers using the index registers. The following group shows data copy, arithmetic, and unconditional jump instructions related to the IX registers; there is an identical set for the IY register. Opcode Operand Bytes Description LD IX, 16-bit 4 Load 16-bit data into IX register (this instruction was discussed in Section 8.1. l) LD ...