.extern malloc .global main main: mov r0, #0x2 @ size mov r1, #malloc call sp, r1 mov r1, #0x0 sto [r0], r1 mov r1, #listhead sto [r1], r0 mov r0, #string mov r1, #listadd call sp, r1 mov r0, #string2 mov r1, #listadd call sp, r1 @ now walk the list mov r0, #listhead @ start off with the list head 1: ldr r2, [r0] @ load the next pointer into r2 mov r1, #0 @ test to see if the next pointer is 0 tst r2, r1 @ if so, then moveq pc, #end @ bail out mov r1, #1 @ add one to the list address, where the string pointer lives add r1, r2 @ push sp, r0 @ save the list address ldr r0, [r1] @ load the string pointer mov r1, #writestr @ load the address to call call sp, r1 @ do it! pop sp, r0 @ restore the list address ldr r0, [r0] @ move to next mov pc, #1b @ and do it again! end: mov r0, #0x0000 sto [r0], r0 @ kill us off listadd: mov r1, #listhead @ start off with the list head 1: ldr r2, [r1] @ load the next pointer into r2 mov r3, #0 @ test to see if the next pointer is 0 tst r2, r3 @ if not, then ldrne r1, [r1] @ move to the next movne pc, #1b @ and get back into the loop mov r2, #1 @ add one to the list address, where the string pointer lives add r2, r1 @ sto [r2], r0 @ store the string push sp, r1 @ save the list address mov r0, #0x2 @ allocate 2 bytes mov r1, #malloc @ load the address to call call sp, r1 @ do it! mov r1, #0x0 @ load the value for next sto [r0], r1 @ store it in the next pointer pop sp, r1 @ restore the list address sto [r1], r0 @ set the next pointer pop sp, pc @ return .extern writestr @ Note that they have to be spaced out, since these are 16bit loads string: .string "H e l l o , w o r l d ! \n \000\000" string2: .string "G o o d b y e , w o r l d ! \n \000\000" .section .bss listhead: .word 0