	.extern	main
	.global	start
	.section .start
start:
	mov	r0, #_end
	mov	r1, #heapend
	sto	[r1], r0
	mov	sp, #stack
	mov	pc, #main

	.section .text
	.global malloc
malloc:
	mov	r3, #heapend
	ldr	r1, [r3]
	mov	r2, r1
	add	r2, r0
	mov	r0, r1
	sto	[r3], r2
	pop	sp, pc

	.global free
free:
	pop	sp, pc
	
	.global writestr
writestr:
1:
	ldr	r3, [r0]	@ load in data
	mov	r1, #0x0	@ Is the loaded data equal to 0?
	tst	r3, r1		@ "" ""  ""     ""   ""    "" ""
	moveq	pc, #2f		@ If so, bail out
	mov	r1, #0x4000	@ Write address
	sto	[r1], r3	@ Write the data out
	mov	r1, #0x1	@ Add one to the write address
	add	r0, r1		@ ""  ""  "" ""  ""    ""
	mov	pc, #1b		@ Loop again
2:
	pop	sp, pc

	.section .bss
stack:
	.space	32*2		@ bytes, not words
heapend:
	.word	0
