Replaced calloc by an assembler version
git-svn-id: svn://svn.cc65.org/cc65/trunk@1119 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -5,7 +5,6 @@ _hextab.s
|
|||||||
_scanf.s
|
_scanf.s
|
||||||
abort.s
|
abort.s
|
||||||
bsearch.s
|
bsearch.s
|
||||||
calloc.s
|
|
||||||
errormsg.s
|
errormsg.s
|
||||||
fclose.s
|
fclose.s
|
||||||
fdopen.s
|
fdopen.s
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ C_OBJS = _afailed.o \
|
|||||||
_scanf.o \
|
_scanf.o \
|
||||||
abort.o \
|
abort.o \
|
||||||
bsearch.o \
|
bsearch.o \
|
||||||
calloc.o \
|
|
||||||
errormsg.o \
|
errormsg.o \
|
||||||
fclose.o \
|
fclose.o \
|
||||||
fdopen.o \
|
fdopen.o \
|
||||||
@@ -59,6 +58,7 @@ S_OBJS = _fdesc.o \
|
|||||||
abs.o \
|
abs.o \
|
||||||
atexit.o \
|
atexit.o \
|
||||||
atoi.o \
|
atoi.o \
|
||||||
|
calloc.o \
|
||||||
copydata.o \
|
copydata.o \
|
||||||
cprintf.o \
|
cprintf.o \
|
||||||
errno.o \
|
errno.o \
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* calloc.c
|
|
||||||
*
|
|
||||||
* Ullrich von Bassewitz, 06.06.1998
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* calloc (size_t count, size_t size)
|
|
||||||
{
|
|
||||||
void* mem;
|
|
||||||
size *= count;
|
|
||||||
if (mem = malloc (size)) {
|
|
||||||
memset (mem, 0, size);
|
|
||||||
}
|
|
||||||
return mem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
64
libsrc/common/calloc.s
Normal file
64
libsrc/common/calloc.s
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
;
|
||||||
|
; Ullrich von Bassewitz, 15.11.2001
|
||||||
|
;
|
||||||
|
; Allocate a block and zero it.
|
||||||
|
;
|
||||||
|
; void* __fastcall__ calloc (size_t count, size_t size);
|
||||||
|
;
|
||||||
|
|
||||||
|
.export _calloc
|
||||||
|
.import _malloc, _memset
|
||||||
|
.import tosumulax, pushax, push0
|
||||||
|
|
||||||
|
|
||||||
|
; -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
.proc _calloc
|
||||||
|
|
||||||
|
; We have the first argument in a/x and the second on the stack. Calling
|
||||||
|
; tosumulax will give the product of both in a/x.
|
||||||
|
|
||||||
|
jsr tosumulax
|
||||||
|
|
||||||
|
; Save size for later
|
||||||
|
|
||||||
|
sta Size
|
||||||
|
stx Size+1
|
||||||
|
|
||||||
|
; malloc() is a fastcall function, so we do already have the argument in
|
||||||
|
; the right place
|
||||||
|
|
||||||
|
jsr _malloc
|
||||||
|
|
||||||
|
; Check for a NULL pointer
|
||||||
|
|
||||||
|
cpx #0
|
||||||
|
bne ClearBlock
|
||||||
|
cmp #0
|
||||||
|
beq ClearBlock
|
||||||
|
|
||||||
|
; We have a NULL pointer, bail out
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
|
; No NULL pointer, clear the block. memset will return a pointer to the
|
||||||
|
; block which is exactly what we want.
|
||||||
|
|
||||||
|
ClearBlock:
|
||||||
|
jsr pushax ; ptr
|
||||||
|
jsr push0 ; #0
|
||||||
|
lda Size
|
||||||
|
ldx Size+1 ; Size
|
||||||
|
jmp _memset
|
||||||
|
|
||||||
|
.endproc
|
||||||
|
|
||||||
|
; -------------------------------------------------------------------------
|
||||||
|
; Data
|
||||||
|
|
||||||
|
.bss
|
||||||
|
|
||||||
|
Size: .res 2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user