Programming Examples
2. Copying a String
2. Copying a String
This example contains a section of assembly code that moves a byte string of arbitrary length to an arbitrary byte address.
;The routine reflect copies bytes from the source location
;to the destination location.
;
;The first parameter is the source address and the second
;parameter is the destination address.
;
;The third parameter is the number of bytes to copy.
;For performance, larger chunks of bytes are handled differently.
.CODE
.EXPORT reflect,ENTRY
reflect |
|
|
.PROC |
|
|
.CALLINFO | ENTRY_GR=6,SAVE_RP |
|
.ENTER |
|
|
COMB,=,N | %arg2,%r0,fallout | ; done, count is zero |
COMB,<,N | %arg2,%r0,choke | ; caller error, neg count |
OR | %arg0,%arg1,%r6 | ; source and dest |
OR | %r6,%arg2,%r6 | ; count |
EXTRU,= | %r6,31,2,%r0 | ; 2 low order bits = 0? |
B,N | onebyte | ; yes, skip this branch |
ADDIBT,<,N | ; no, skip chunkify if count<0 | |
chunkify |
|
|
LDWM | 16(%arg0),%r6 | ; word 1- > temp1 |
|
| ; point ahead 4 words in source |
LDW | ; place mark 3 wds back- >temp2 | |
LDW | ; place mark 2 wds back- >temp3 | |
LDW | ; place mark 1 wds back- >temp4 | |
STW | %r5,4(%arg1) | ; dest wd 2 |
STWM | %r6,16(%arg1) | ; dest wd 1 |
|
| ; point ahead 4 words in dest |
STW | ; dest wd 3 | |
ADDIBF,< | ; loop if count > 0 | |
STW | ; dest wd 2 | |
chekchunk |
|
|
ADDIBT,< | 12,%arg2,exeunt | ; go if count < |
COPY | %r0,%ret0 | ; clear rtnval |
subchunk |
|
|
LDWS,MA | 4(%arg0),%r6 | ; word- >temp1 |
|
| ; point ahead 4 bytes in source |
ADDIBF,< | ; go if count<4 | |
STWS,MA | %r6,4(%arg1) | ; dest< |
|
| ; point ahead 4 bytes in dest |
132 | Chapter 7 |