This preview shows page 1. Sign up to view the full content.
Unformatted text preview: stem software, and could therefore be totally different from one ARM system to another, most ARM systems implement a common subset of calls in addition to any specific calls required by the particular application. The most useful of these is a routine which sends the character in the bottom byte of r0 to the user display device:
SWI SWI_WriteC ; output r0 [7:0] Another useful call returns control from a user program back to the monitor program: SWI SWI_Exit ; return to monitor The operation of SWIs is described in more detail in Section 5.6 on page 117. Jump tables Jump tables are not normally used by less experienced programmers, so you can ignore this section if you are relatively new to programming at the assembly level. The idea of a jump table is that a programmer sometimes wants to call one of a set of subroutines, the choice depending on a value computed by the program. It is clearly possible to do this with the instructions we have seen already. Suppose the value is in r0. We can then write:
r0, #0 SUB0 r0, #1 SUB1 r0, #2 SUB2 JUMPTAB CMP BEQ CMP BEQ CMP BEQ 68 ARM Assembly Language Programming However, this solution becomes very slow when the list of subroutines is long unless there is some reason to think that the later choices will rarely be used. A solution which is more efficient in this case exploits the visibility of the program counter in the general register file:
BL JUMPTAB JUMPTAB ADR CMP LDRLS B SUBTAB DCD DCD DCD r1, SUBTAB r0, #SUBMAX pc, [r1,r0,LSL #2] ERROR SUB0 SUB1 SUB2 r1 -> SUBTAB
check for overrun.. . . if OK, table jump .. otherwise signal error table of subroutine entry points The 'DCD' directive instructs the assembler to reserve a word of store and to initialize it to the value of the expression to the right, which in these cases is just the address of the label. This approach has a constant performance however many subroutines are in the table and independent of the distribution of frequency of use. Note, however, that the consequences of reading beyond the end of the table are likely to be dire, so checking for overrun is essential! Here, note how the overrun check is implemented by making the load into the PC conditional, so the overrun case skips the load an...
View Full Document
This document was uploaded on 10/30/2011 for the course CSE 378 380 at SUNY Buffalo.
- Spring '09