This preview shows page 1. Sign up to view the full content.
Unformatted text preview: d falls into the branch to the error handler. The only performance cost of checking for overrun is the comparison with the maximum value. More obvious code might have been:
CMP BHI error LDR jump r0, #SUBMAX ERROR pc, [r1,r0,LSL ; ; #2] check .. ; for overrun.. if overrun call .. else table but note that here the cost of conditionally skipping the branch is borne every time the jump table is used. The original version is more efficient except when overrun is detected, which should be infrequent and, since it represents an error, performance in that case is not of great concern. An alternative, less obvious way to implement a jump table is discussed in 'switches'on page 171. Writing simple assembly language programs 69 3.4 Writing simple assembly language programs
We now have all the basic tools for writing simply assembly language programs. As with any programming task, it is important to have a clear idea of your algorithm before beginning to type instructions into the computer. Large programs are almost certainly better written in C or C++, so we will only look at small examples of assembly language programs. Even the most experienced programmers begin by checking that they can get a very simple program to run before moving on to whatever their real task is. There are so many complexities to do with learning to use a text editor, working out how to get the assembler to run, how to load the program into the machine, how to get it to start executing and so on. This sort of simple test program is often referred to as a Hello World program because all it does is print 'Hello World' on the display before terminating. Here is an ARM assembly language version: This program illustrates a number of the features of the ARM assembly language and instruction set: The declaration of the code 'AREA', with appropriate attributes. The definitions of the system calls which will be used in the routine. (In a larger program these would be defined in a file which other code files would reference.) The use of the ADR pseudo instruction to get an address into a base register. The use of auto-indexed addressing to move through a list of bytes. Conditiona...
View Full Document
This document was uploaded on 10/30/2011 for the course CSE 378 380 at SUNY Buffalo.
- Spring '09