Вы находитесь на странице: 1из 12

Tasks /1

1. Let us set and after that reset


a. the CY flag b. Zero flag

Solution of Task 1
;Label Instruction ORG 100H SCF CCF END Comment

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

Task 2
2. Let us clear the
a. Accumulator b. the general purpose registers and IX and IY ;Label

Solution of Task 2
Instruction ORG 100H LD A,0 LD BC,0 LD DE,0 LD HL,0 LD IX,0 LD IY,0 END
dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

Comment

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

11/02/2006

Task 3
3. Let us exchange the content of register A and B.

Solution of Task 3
;Label Instruction ORG 100H LD A,7AH LD B,0F4H LD C,A LD A,B LD B,C END Comment ;7A in A ;F4 in B ;C is the temporary register

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

Task 4
4. Let us exchange the content of register pair HL and register IX.

Solution of Task 4
;Label Instruction ORG 100H LD HL,1234H LD IX,5678H PUSH HL PUSH IX POP HL POP IX END Comment ;load HL ;load IX ;push HL and IX ; pop them in reverse sequence

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

Task 5
5. Let us add two 8-byte numbers which are situated from memory address 6000H and 6010H upward. Lower bytes are on lower addresses.

Solution of Task 5 / Page 1


;Label Instruction ORG 100H LD B,8D OR A LD HL,6000H LD DE,6010H REP: LD A,(DE) ADC A,(HL) LD (HL),A INC HL INC DE DJNZ REP Comment ;the count value ;set CY to 0 ;the starting address in memory of augend ;the starting address in memory of addend ;load next byte of addend ;add augend

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

10

Solution of Task 5 / Page 2


; ORG DW DW DW DW ORG DW DW DW DW END
11/02/2006

Task 6
6. Let us exchange the nibbles of register L.

6000H 78FEH 56FFH 34F0H 12F8H 6010H 1122H 1122H 1122H 1122H
dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 11

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

12

Solution of Task 6
;Label Instruction ORG 100H LD L,3AH RRC L RRC L RRC L RRC L END
11/02/2006

Tasks / 2
7. Let us change the sequence of bits in register C (MS bit with LS bit, etc.).

Comment ;3A be the number

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

13

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

14

Solution of Task 7
;Label Instruction ORG 0100H LD C,2EH LD B,8D RL C RR A DJNZ REP LD C,A END Comment ;2EH will be the number ;initializing loop counter ;1 shift to the left ;be shifted in A from the left ;do until B=0 ;load it back ;this is the END of it

Task 8
8. 8 bytes of data are located in the memory on address 6000H upward (lower byte on lower memory address). Develop the parity bits for the 8 bytes (9th bits) in C assuming even parity.

REP:

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

15

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

16

Solution of Task 8 Page 1


;Label Instruction ORG 100H LD HL,6000H LD B,08H LD C,0 LD A,(HL) OR A JP PE,EVEN SCF JP CONT SCF CCF RR C INC HL DJNZ REP Comment ;Starting address of memory block to HL ;B:=32D ;initialize C ;next word to HL ;to set the flags ;CY:=1

Solution of Task 8 Page 2


ORG DW DW DW DW END 6000H 159AH 2776H 0F8B9H 0C65AH

REP:

ODD: EVEN: CONT:

;CY:=0 ;next higher bit of C be equal to CY ;next byte ;do until B=0

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

17

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

18

Task 9
9. Two 2-digit BCD numbers are placed in register A and register B. Subtract the number in register B from register A. Let's assume the result to be positive.

Solution of Task 9
;Label Instruction ORG 100H LD A,82H LD B,27H SUB B DAA END Comment ;the minuend 2 digit ;the subtrahend 2 digit ; 2's complement subtraction ; BCD correction

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

19

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

20

Task 10
10. An 8-digit BCD number is placed in memory address 6000H - 6003H (higher byte on lower address). Let us shift the digits upward by one digital place so that the highest digit should be placed in the lower nibble of register A. (The lowest significant digit is to be loaded by 0.)

Solution of Task 10
;Label Instruction ; ORG 100H LD B,4H LD A,0 LD HL,6003H REP: RLD (HL) DEC HL DJNZ REP END Comment

;B:=4 ;A:=5AH (the pattern) ;Starting (LSDW) address of BCD block to HL ;rotate 1 digit to the left through A ;move to lower address (higher digit word) ;do until B=0

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

21

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

22

Task 11
;Label

Solution of Task 11
Instruction Comment ORG 100H LD HL,02A5H ;512+160+5=677D will be ; the test numbers LD B,4 SLA L RL H DJNZ REP END

11. Let us multiply the number in HL by 16D. Assume there is no carry.


REP:

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

23

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

24

Tasks 12
12. Let us multiply the number in DE by 22D. Assume there is no carry.
;Label REP:

Solution of Task 12 v1
Instruction ORG 0100H LD DE,00FFH LD H,D LD L,E ADD HL,HL PUSH HL ADD HL,DE ADD HL,HL EX (SP),HL POP DE ADD HL,HL ADD HL,HL ADD HL,HL ADD HL,DE EX DE,HL END Comment ;the number is 255D ;DE to HL ;2*DE ;2*DE to stack ;3*DE ;6*DE ;6*DE to stack and 2*DE to HL ;6*DE to DE ;4*DE ;8*DE ;16*DE ;22*DE ;vissza DE-be

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

25

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

26

Solution of Task 12 v2
;Label Instruction Comment ORG 0100H LD DE,00FFH ;the number is 255D LD B,22D LD HL,0 ADD HL,DE DJNZ REP ;add until BC=0 EX DE,HL END
dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 27

Task 13
13. Let us divide the number in register D by 8. The integer part of the result should be placed in register D and the fractional part in register E.

REP:

11/02/2006

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

28

Solution of Task 13
;Label Instruction ORG 0100H LD D,23D LD B,3 LD E,0 SRA D RR E DJNZ REP END Comment ;23D will be the test number ;3 cycles are needed ;initialize E to 0 ;arithmetic shift (divide by 2) ;the fractal part in E ;repeat until B=0

Tasks 14
14. Two 16-bit data are stored in the memory locations of 6000H,6001H and 6010H,6011H. Write a short subroutine to exchange the contents of the two locations if the content of register B is zero and leave it unchanged if it is not zero. You can use any register, but their previous content has to be unchanged when the program is accomplished.
29 11/02/2006 dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 30

REP:

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

Solution of Task 14
;Label Instruction ORG 0100H LD D,23D LD B,3 LD E,0 SRA D RR E DJNZ REP END Comment ;23D will be the test number ;3 cycles are needed ;initialize E to 0 ;arithmetic shift (divide by 2) ;the fractal part in E ;repeat until B=0

Task 15
15. Write a program to output 8 bytes to a peripheral with the address 3FH . The data to be output can be found in the memory on locations from 6000H upwards. Before every output step we have to check whether the peripheral is able to accept the data. We can check it with inputting the data from input peripheral 3E. If we receive a 0, than it is ready to accept the next byte. If not than we have to wait until its state will change to 0.
31 11/02/2006 dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 32

REP:

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

Solution of Task 15
;Label Instruction ORG 100H LD B,0 LD A,B CP 0H JP NZ,ENDALL OR A LD DE,(6000H) LD HL,(6010H) LD (6010H),DE LD (6000H),HL ENDALL: NOP ORG 6000H DW 1234H ORG 6010H DW 5678H END Comment ;B:=0 ;if B=0 then do ;test B (A) ;jump if not zero ;to clear CY flag ;first word to DE ;second word to HL ;first word to the address of the second ; second word to the address of the first

Tasks 16
16. We have a block of data in memory at 6000,601F. Lets us find the byte pattern of 5A. Transfer the address to HL if the pattern is found or clear the content of HL if not found.

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

33

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

34

Solution of Task 16 v1
;Label Instruction ORG 100H LD B,8D LD C,3FH LD HL,6000H IN A,(3EH) CP 0 JP NZ,REP OUTI DJNZ REP END Comment ;8 bytes will be transferred ;address of peripheral to C ;address of first byte in memory to HL ;input status to A ;test the status of peripheral ;if cannot send yet (3E)<>0 then wait ;OUT to peripheral from memory ; do until B=0

Solution of Task 16 v2 Page 1


;Label Instruction ORG 100H LD BC,1FH LD A,5AH LD HL,6000H REP: CPI JP Z,EQUAL JP PO,EQUAL JP REP EQUAL: NOP Comment ;B:=32D ;A:=5AH (the pattern) ;Sarting address of memory block to HL ;Compare (A) with ((HL)) and INC B ;Z=1 if (A)=((HL)) ;HA B=0 lett

REP:

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

35

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

36

Solution of Task 16 v2 Page 2


ORG DW DW DW DW DW DW DW DW END
11/02/2006

Program Development Sequence / 1


1.
a.

6000H 159AH 2776H 0F85AH 0C416H 4510H 0F21FH 2345H 0ABCEH


dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 37

Development of the assembly program


We have to write the program in any text editor. The output file has to be in text format excluding formatting information. The extension of the output file has to be .Z80.

b.
i.

Remarks:
In the first row of the program we have to give the address of the first code memory location. Let us choose e.g. 0100H. Syntax of this uses the ORG directive: e.g. ORG 100H The program has to be closed by the END directive in the last row A program line can be assembled of 3 parts: LABEL: INSTRUCTION ;COMMENT If there is no LABEL than a TAB has to be inserted at the beginning of the line.
dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 38

ii. iii. iv.


11/02/2006

Program Development Sequence / 1 (cont.)


2.

Assembling the source file


Assembling the assembly program The assembly program has to be assembled by the assembler. The Z80.bat file serves us to make the target (binary) code. Syntax: Z80.bat <filename> The extension of the filename must not be included! The target code will have .B80 (binary) extension..
We have to answer the question, addressed to us, during the assembly with an "Enter". If there were syntax errors in the assembly program, the assembler will enumerate the number and the bad lines. In this case we have to return to point 1 to make the corrections before reassembling the program.
dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 40

b. Remarks (cont.):
If a hexadecimal number begins with a letter, than a leading zero must be inserted. It is advised to use a TAB between the mnemonic and the (first) operand. A comment has to begin with a semi-colon (;). If the whole line is a comment than the first character in the line has to be this semi-colon.

a.

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

39

11/02/2006

Launching the Simulator


3. Program emulation and debugging
Emulation is to be accomplished on PC. The program to be run for emulation is Z80MU.exe. This full-screen emulator has to be started without parameters. It supports CP/M operating system, which had been developed for 8-bit micros. Some MS DOS commands are also available inside the emulator from the command prompt. Next Figure shows the commands for which detailed help is available.

Help is available for commands:

To ask HELP on any command we can either type HELP <name> Enter, where name is the name of the given command or type HELP and Enter and from the menu choose the given command and type its name at the "Your choice:" prompt.
11/02/2006 dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 42

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

41

Begin emulation
a. Emulation usually begins with READING the written and edited assembly program to the emulator. Syntax is

DEBUG in Z80MU

READ <address> <filename> <Enter>


where read is the command address is the relocation address for the program. If we do not give any address than a 100H will be added (because 100H is the default starting address of this emulator) to the address defined by the mentioned ORG directive. If we want our program to be loaded into the simulation memory to at the address place defined by the ORG directive in the assembly program, than we have to give 0 for this parameter. for the filename we have to give the full name (with extension, and if necessarily with full path). The extension is .B80 !

a.

After reading the binary file we have to run the debugger The command is DEBUG and the syntax is DEBUG <Enter> To use the debugger see the DEBUG HELP (Next Figure)
dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 43 11/02/2006 dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 44

11/02/2006

DEBUG in Z80MU
Some examples of the possibilities are given below. We can with:
i. ii. iii. iv. v. Alt G: start a program at a given memory address (given PC content) Alt S: step1 instruction further from the given code memory location (actual PC content) Alt C: define the step count (how many instructions to execute with Alt S) Alt T: define a condition with an expression to set a breakpoint to postpone the program execution Alt D: dump the memory content from the given address Example: <Alt> d 4000. See result on Next Figure.
dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166) 45 11/02/2006

DUMP memory

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

46

Disassamble
c. We can also give a <DISSAM> <address> command at the prompt. What the command is for can be seen in the HELP screen, see Figure 5.

Disassamble
Example:

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

47

11/02/2006

dr. Gyrgy Glckner - Digital Informatics Part 2 (VIAU0166)

48

Вам также может понравиться