1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-16 21:07:56 +00:00
kickc/src/test/ref/malloc-1.asm

53 lines
963 B
NASM
Raw Normal View History

// Experiments with malloc() - a word array
.pc = $801 "Basic"
:BasicUpstart(__start)
.pc = $80d "Program"
.const SIZEOF_WORD = 2
// Top of the heap used by malloc()
.label HEAP_TOP = $a000
.label WORDS = malloc.return
__start: {
// malloc(0x200)
jsr malloc
jsr main
rts
}
main: {
.label w = 2
lda #<WORDS
sta.z w
lda #>WORDS
sta.z w+1
ldx #0
__b1:
2020-02-23 08:44:36 +00:00
// *w++ = i
txa
ldy #0
sta (w),y
tya
iny
sta (w),y
2020-02-23 08:44:36 +00:00
// *w++ = i;
lda #SIZEOF_WORD
clc
adc.z w
sta.z w
bcc !+
inc.z w+1
!:
2020-02-23 08:44:36 +00:00
// for( byte i: 0..255)
inx
cpx #0
bne __b1
2020-02-23 08:44:36 +00:00
// }
rts
}
// Allocates a block of size chars of memory, returning a pointer to the beginning of the block.
// The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.
malloc: {
.const size = $200
.label mem = HEAP_TOP-size
.label return = mem
rts
}