Unit 7.5 -- Copy A to B With Copy Subroutine

PROG

Copy data from block A to block B using subroutine

PED

Another subroutine example

CONCEPTS

None

SF

none

29.html
         
Unit 7.5, Copy A to B with Copy Subroutine


In  this unit, we see an example where we pass two blocks of
memory to a subroutine. Specifically, a source and a target.
Our  CCB  (stands for Copy Control Block) contains  the  two
addresses as well as the number of words to move.

Our main routine calls it once copying A to  B.   Note  that
the length of A is automatically kept track of by use of the
"ALEN EQU (*-A)/.4" in line 37.

Lines  5  and   6 loads the first word of the Copy   control
block   with  the  address  of  A.  Lines 7 and  8  set  the
second word of the CCB to point to B.  Lines 9 and 10,  load
the  third  word  with  the  length of A, which in this case
turns out to be four.

Then  line 11 sets register one to point to the copy control
block.  Line 12 is the call to the subroutine.

In the subroutine, R2 contains the address of  the  word  in
the  first  block to be moved.  It is loaded in line 19 from
the first word of the CCB passed.

Register 3 will point to the place to put this word.  It  is
loaded from the second word of the CCB in line 19.  Line  20
loads into register four the number of integer to move.

Register  9 will act as a counter up to the number of  words
to be read.  It is zeroed out in line 21.

The  loop that does the copying is in lines 23 to  32.    We
compare  register nine to the total number  of  integers  to
move in line 24.  Line 25 will causes leaving of the loop if
appropriate.

Then  we  load the word to be moved in line 26 and  drop  it
where it belongs in line 27.

Register 2 (the pointer in the source array) and register  3
(the  pointer  to  the  place to move it) are incremented in
lines 28 and 29.

Line 30 bumps the counter of integers moved.

the end of the loop stuff is in lines 31 to 32.

and finally, we return from the subroutine in line 33. We
return to the operating system in line 13.