; A simple program to store the numbers 0 to 9 in ; a table and then to display them in reverse ; order. ; rdm34@cl.cam.ac.uk, 9.11.02 AREA myexample, CODE, READONLY IMPORT printhex IMPORT putchar ENTRY ; note we use registers r4 to r11 to ; hold our variables (counters, pointers etc.) ; ; We don't use r0,r1,r2 or r3 as they are used ; as arguments for procedure calls (they may be ; modified by procedures). r12-r15 have special ; uses such as stack pointer or program counter. ; ; lets put the address of 'mytable' into ; register r4 ; this address is calculated as the offset ; from the current PC. ; ; address of mytable=current PC + offset ; ADD r4, pc, #(mytable -8 -.) ; lets write the numbers 0 to 9 ; into the table. We will store each ; number as a byte in memory using ; the STORE BYTE instruction (STRB) MOV r5, #0 ; r5=0 loop STRB r5, [r4, r5] ; table[r5]=r5 ADD r5, r5, #1 ; r5=r5+1 CMP r5, #10 BNE loop ; if r5!=10 goto loop ; read the numbers in reverse and ; display them in the console window MOV r5, #9 ; start at table[9] outloop LDRB r6, [r4, r5] ; r6=table[r5] ; ; display number stored in r6 ; MOV r0, r6 ; put argument into r0 BL printhex ; call display hex function ; MOV r0, #10 ; print new line character BL putchar ; SUBS r5, r5, #1 ; set flags BPL outloop ; branch if r5 is still ; positive (PL) >=0 finish ;; Standard way to exit program mov r0,#0x18 mov r1,#0x20000 add r1,r1,#0x26 SWI 0x123456 mytable % 8192 ; 8K of zero bytes END ; simply the end of the source file