@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ @ This program prints numbers 0 to 15 in hex. @ @ It defines and uses a function print_digit. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ @ Program part 1: definition of main. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ .globl _start _start: @initialize sp at start of program mov sp, #0x100000 @ program preamble sub sp, sp, #12 str r0, [sp, #0] str r1, [sp, #4] str r5, [sp, #8] @ program main body mov r5, #0x0 my_loop: cmp r5, #0xf bgt program_exit mov r0, r5 bl print_digit add r5, r5, #1 b my_loop @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ @ Program part 2: definition of functions. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ print_digit: @ print_digit preamble sub sp, sp, #16 str lr, [sp, #0] str r0, [sp, #4] str r4, [sp, #8] str r5, [sp, #12] @ print_digit main body ldr r4,=0x101f1000 @ ASCII codes stored @ at [r4] get printed cmp r0, #10 addlt r5, r0, #48 addge r5, r0, #55 str r5, [r4] @ print_digit wrap-up ldr lr, [sp, #0] ldr r0, [sp, #4] ldr r4, [sp, #8] ldr r5, [sp, #12] add sp, sp, #16 bx lr @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ @ Program part 3: program exit. @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ program_exit: mov r1, #13 str r1, [r4] mov r1, #10 str r1, [r4] mov r1, #71 str r1, [r4] @ program wrap-up ldr r0, [sp, #0] ldr r1, [sp, #4] ldr r5, [sp, #8] add sp, sp, #12