.extern main .global start .section .start start: mov r0, #_end mov r1, #heapend sto [r1], r0 mov sp, #stack mov r0, #main call sp, r0 push sp, r0 @ print the return value mov r0, #printint call sp, r0 mov r0, #0x1234 @ store to rom to terminate sto [r0], r0 .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 .global printint printint: mov r0, #-2 add r0, sp ldr r0, [r0] mov r1, #0x4000 sto [r1], r0 pop sp, pc .section .bss stack: .space 32*2 @ bytes, not words heapend: .word 0