INMC News

  

Summer 1979 · Issue 3

Page 15 of 26

Soft­ware Section

1. Beginners’ Corner

How to move data around–quickly!

I have seen a program which put a message on the screen with a piece of code like this:

LD   HL, address on Screen
LD   A, "M
LD   (HL), A
INC  HL
LD   A, "E
LD   (HL), A
INC  HL

and so on ..... and on ....... and on .......

This works very well, but it takes a long time and a lot of program just to do this simple task. You should see the last newsletter for an easy way to display a message using code EF, then the message, then a zero.

But quite often, one wants to move lots of data around and not just output a message at the current cursor address. By far the easiest way is by the LDIR instruction. Here is an explanation:

  1. Set HL to the address of the data you want to move.
  2. Set DE to the address you want to move it to.
  3. Set BC to the length of the data you want moved.
  4. LDIR instruction – this does the work.

For example, suppose you had 48 bytes of data at address 0E80, and you wanted to put this on the top line of the screen. The address of the top line is 0BCA.

SO:

1.  21 80 0F     LD HL,0E80 (from)
2.  11 CA OB     LD DE,0BCA (to)
3.  01 30 00     LD BC,0030

(Length of data, 0030 = 48 decimal)

4.  ED B0        LDIR

/

Page 15 of 26