ARM.SoC.Architecture

Branches are expensive on the arm so the absence of

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: at the jump table look-up does not fall past the end of the table, so some checking is necessary. 172 Architectural Support for High-Level Languages Another way of compiling a switch statement is illustrated by a procedure in the 'Dhrystone' benchmark program which ends (effectively) as follows: switch (a) { case 0: *b = 0; break; case 1: if (c>100) *b = 0; else *b = 3; break; case 2: *b = 1; break case 3: break; case 4: *b = 2; break; } /* end of switch */ } /* end of procedure */ The code which is generated highlights a number of aspects of the ARM instruction set. The switch statement is implemented by adding the value of the expression (in v2; the register naming convention follows the ARM Procedure Call Standard which will be described in Section 6.8 on page 176) to the PC after scaling it to a word offset. The overrun case falls through the add instruction into the slot left free by the PC offset. Any cases which require a single instruction (such as case 3), and the last case whatever its length, can be completed in line; others require a branch. This example also illustrates an if...then...else implemented using conditional instructions. ; on entry al = 0, a2 = 3, v2 = switch expression CMP ADDLS LDMDB v2,#4 check value for overrun.. pc,pc,v2,LSL #2 ..if OK, add to pc (+8) fp,{vl,v2,fp,sp,pc} ; ..if not OK, return B B B LDMDB LO LI L2 al,#2 al,[vl] case 0 case 1 case 2 case 4 fp,{vl,v2,fp,sp,pc} ; case 3 (return) MOV STR LO LI LDMDB STR LDMDB LDR fp,{vl,v2,fp,sp,pc} ; return al,[vl] fp,{vl,v2,fp,sp,pc} ; return a3,c_ADDR ; get address of c LDR CMP STRLE a3, [a3] a3,#&64 a2, [vl] ; get c ; c>100?.. ; .. No: *b = 3 STRGT LDMDB c_ADDR DCD L2 MOV STR LDMDB al, [vl] fp,{vl,v2,fp,sp,pc) <address of c> al,ttl al,[vl] fp,{vl,v2,fp,sp,pc} ; .. Yes: *b = 0 ; return ; *b = 1 ; return Loops 173 6.7 Loops The C language supports three forms of loop control structure: for(el;e2;e3){..} while (el) {..} do {..} while (el) Here el, e2 and e3 are expressions which evaluate to 'true' or...
View Full Document

Ask a homework question - tutors are online