Академический Документы
Профессиональный Документы
Культура Документы
Solution of Task 1
;Label Instruction ORG 100H SCF CCF END Comment
11/02/2006
11/02/2006
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
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
11/02/2006
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
11/02/2006
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.
11/02/2006
11/02/2006
10
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
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.).
13
11/02/2006
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
15
11/02/2006
16
REP:
;CY:=0 ;next higher bit of C be equal to CY ;next byte ;do until B=0
11/02/2006
17
11/02/2006
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
19
11/02/2006
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
21
11/02/2006
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/02/2006
23
11/02/2006
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
25
11/02/2006
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
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
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
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
33
11/02/2006
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
REP:
11/02/2006
35
11/02/2006
36
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
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
39
11/02/2006
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
41
Begin emulation
a. Emulation usually begins with READING the written and edited assembly program to the emulator. Syntax is
DEBUG in Z80MU
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
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
47
11/02/2006
48