Article View: comp.sys.atari.st
Article #29313blkcpy() correction
From: daemon
Date: Mon, 23 Nov 1987 07:06
Date: Mon, 23 Nov 1987 07:06
61 lines
1812 bytes
1812 bytes
ARGH!! Sure enough, the best way to find bugs in a piece of code is to
release it to the public. There is a minor bug in the blkcpy() function
that I just posted, so here is the corrected version... sorry...
[BLKCPY.S]
* char *blkcpy(dest, source, len)
* register char *dest;
* register char *source;
* register int len;
* /*
* * Copies the <source> block to the <dest>. <len> bytes are
* * always copied. No terminator is added to <dest>. A pointer
* * to <dest> is returned.
* */
* {
* register char *p = dest;
*
* if(source < dest)
* {
* dest += len;
* source += len;
* while(len--)
* *--dest = *--source;
* }
* else
* {
* while(len--)
* *dest++ = *source++;
* }
* return(p);
* }
.text
.globl _blkcpy
_blkcpy:
clr.l d0
move.w 12(a7),d0 ; number of bytes
blkcpy0:
move.l 4(a7),a1 ; destination
move.l 8(a7),a0 ; source
cmp.l a0,a1 ; check copy direction
bls blkcpy4
add.l d0,a0 ; move pointers to end
add.l d0,a1
bra blkcpy2
blkcpy1:
move.b -(a0),-(a1) ; (s < d) copy loop
blkcpy2:
dbra d0,blkcpy1
bra blkcpy5
blkcpy3:
move.b (a0)+,(a1)+ ; (s >= d) copy loop
blkcpy4:
dbra d0,blkcpy3
blkcpy5:
move.l 4(a7),d0 ; return destination pointer
rts
Dale Schumacher
..ihnp4!meccts!stag!syntel!dal
(alias: Dalnefre')
Technical Details
Message-ID:
<264@stag.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!uwvax!umn-d-ub!umn-cs!ems!nis!stag!daemonShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!rutgers!uwvax!umn-d-ub!umn-cs!ems!nis!stag!daemon From: daemon@stag.UUCP Newsgroups: comp.sys.atari.st Subject: blkcpy() correction Message-ID: <264@stag.UUCP> Date: Mon, 23-Nov-87 02:06:35 EST Article-I.D.: stag.264 Posted: Mon Nov 23 02:06:35 1987 Date-Received: Wed, 25-Nov-87 21:20:56 EST Sender: daemon@stag.UUCP Lines: 61