mirror of
https://github.com/cc65/cc65.git
synced 2024-11-18 00:07:21 +00:00
38f716079a
git-svn-id: svn://svn.cc65.org/cc65/trunk@1119 b7a2c559-68d2-44c3-8de9-860c34a00d81
65 lines
1.1 KiB
ArmAsm
65 lines
1.1 KiB
ArmAsm
;
|
|
; 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
|
|
|
|
|
|
|