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

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

f

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 XX70H into the IY index register. Using the regis­ter IY as a memory pointer with appropriate offsets, store the bytes A2H and 32H in memory locations XX4FH and XX9FH, respectively.

27. Calculate the value of the memory pointer if register IX contains 2000H with the displacement byte 80H.

28. Calculate the values of two memory pointers if register IY contains-20FFH and it is combined with the displacement bytes 7FH and 8FH.

29. Assuming the index register IX contains 2050H, 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 in memory location INBUF (Input Buffer). When the result generates a carry, subtract the last byte and display the sum.

32. Modify the above program to count and display the number of bytes added (excluding the last one).

33. You are given a long grocery list and asked to buy the items from number 20 to 47. Any item that costs more than $10.00 should be excluded. Add up the total cost and show the total expenses. Draw a flowchart for performing these tasks.

34. Modify the above flowchart to include a ceiling of $100 on total expenses.

35. Draw a flowchart to add the string of numbers stored in memory locations BUFFER. The end of the string is indicated by the number 00. Display the sum.

36. The following block of data is stored in memory locations INBUF. Transfer the data to the locations OUTBUF in the reverse order.

Data (H) 47, 97, F2, 9C, A2, 98

37. Ten bytes are stored in memory locations starting from INBUF. To Insert an additional five bytes at the beginning locations, it is necessary to shift the first ten bytes by five locations. Write a program to shift the data string by five memory locations.

38. Ten 16-bit readings are stored in memory locations SOURCE; the low-order byte is stored first, followed by the high-order byte. Write a program to copy the low-order bytes only to a new location BUFFER in a sequence.

39. Given the initial conditions in 38, ignore the high-order readings and pack the low-order readings in consecutive memory locations SOURCE.

40. Draw a flowchart to modify Illustrative Program 2 (Section 8. 7) to include the instruction Jump on Carry instead of Jump on No Carry (JP NC, SKIPCY). You may have to use an additional Jump instruction, and the flowchart may have to be altered significantly.

41. Modify Illustrative Program 2 (Section 8. 7) using the DE register as a mem­ory pointer instead of HL.

42. Modify Illustrative Program 2 (Section 8. 7) using the DE register as a mem­ory pointer and a memory location as a counter (instead of register B).

43. Write a program to add the following string of data bytes until a carry is generated. When the Carry flag is set, subtract the last byte added and dis­play the sum at OUTPRT.

Data (H) 89, 32, 2B, 7A, B5, 68, 2F

44. Modify the program in 43 to count the number of bytes added (excluding the byte that generates the carry) and display the count at the second port.

45. Ten 16-bit readings are stored in memory locations SOURCE; the low-order byte first, followed by the high-order byte. Write a program to add the low­order bytes. Display the sum at two different ports and store the sum in two memory locations OUTBUF and OUTBUF + 1.

46. Two sets of data, ten bytes each, are stored in memory locations INBUF4 1 and INBUF2. Subtract each data byte stored at INBUF2 from the corresponding data byte at INBUF l. Add the remainders, and if the sum of the remainders generates a carry, display FFH at PORT; otherwise, display the sum at PORT.

47. Find the errors in the following instructions.

a. The following instructions add two Hex bytes (06 and 52) and display the sum at PORT7

XX00

06

LD B, 06H

;Load data bytes

XX0I

06

XX02

0E

LD C,52H

XX03

52

XX04

80

ADDA,B

;Add data bytes

XX05

81

ADDA,C

XX06

D3

OUT(07H),A

;Display the sum

XX07

76

HALT

b. The following instructions add five bytes stored in memory locations starting from XX50H. The sum will be Jess than FFH.

XX00

9F

SUBA

;Clear A

XX01

21

LDHL,XX50H

;Set up HL as memory pointer

XX02

XX

XX03

50

XX04

78

LDB,05H

;Set up B as a counter

XX05

05

XX06

86

ADDA,(HL)

;Add byte

XX07

23

INCHL

;Point to next byte

XX08

05

DECB

;Reduce count

XX09

D2

JPNZ,XX04H

;if B 0, get next byte

XX10

04

XX11

XX

XX12

76

HALT

;End of program

c. The following program transfers 100H bytes of data starting at the memory location 2100H to a new location starting at 2800H.

NEXT.

LDHL, 2100H

;Set up HL as index for source

LDBC, 2800H

;Set up BC as index for new memory

LDDE,0100H

;Set up DE as counter

LD A, (HL)

;Get byte

LD (BC),A

;Transfer byte to new memory

INC HL

;Update indexes and counter

INC BC

DEC DE

JP NZ, NEXT

;If transfer is not complete, go back and get next byte

HALT

;End of data transfer

48. A data set with 512 bytes is stored in memory locations with the starting address INBUFI (XX00H). Shift the entire data set by 256 Locations with the starting address INBUF2 on the next page (XX + 1.00). Use the instruction LDDR.

49. Rewrite Illustrative Program 2 (Section 8.7) using the instructions DJNZ and JR NC.

50. Rewrite Illustrative Program l (Section 8.6) using the index registers IX and! IY as memory pointers and the instruction DJNZ.

51. Rewrite Illustrative Program 1(Section 8.6) to copy 512 bytes by using the IX and IY registers as memory pointers. Define the SOURCE and OUTBUF memory locations accordingly, and use BC register as a counter. (Hint: The decrement instructions for a register pair (such as DEC BC) do not affect any flags. Set the zero flag by ORing the contents of registers B and C.)

Leave a comment

Your email address will not be published. Required fields are marked *