A procedure will normally work with operands that are

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: t the pointers are pointing to. If a pointer is incremented it changes in units of the size of the data item in bytes. Thus: int *p; P = P+l; will increase the value of p by 4 bytes. Since the size of a data type is known at compile-time, the compiler can scale constants by an appropriate amount. If a variable is used as an offset it must be scaled at run-time: int i = 4 ; p = p + i; If p is held in r0 and i in r1, the change to p may be compiled as: ADD r0, r0, r1, LSL #2 ; scale r1 to int Where the data type is a structure with a size which is not a power of 2 bytes, a multiplication by a small constant is required. The shift and add instructions can usually produce the desired product in a small number of operations, using a temporary register where necessary. Arrays Arrays in C are little more than a shorthand notation for pointer operations, so the above comments apply here too. The declaration: int a[10]; 170 Architectural Support for High-Level Languages establishes a name, a, for the array which is just a pointer to the first element, and a reference to a [ i ] is equivalent to the pointer-plus-offset form * (a+ i); the two may be used interchangeably. 6.6 Conditional statements Conditional statements are executed if the Boolean result of a test is true (or false); in C these include if...else statements and switches (C 'case' statements). if...else The ARM architecture offers unusually efficient support for conditional expressions when the conditionally executed statement is small. For example, here is a C statement to find the maximum of two integers: if (a>b) c=a; else c=b; If the variables a, b and c are in registers r0, r1 and r2, the compiled code could be as simple as: CMP MOVGT MOVLE r0, r1 r2, r0 r2, rl ; if (a>b)... ; ..c=a.. ..else c=b (In this particular case the C compiler can produce a rather more obvious sequence: MOV CMP MOVLE r2, r0 r0, r1 r 2 , rl ; c=a ; if (a>b)... ; ...c=b However, this doesn't scale well to more complex 'if statements so we...
View Full Document

This document was uploaded on 10/30/2011 for the course CSE 378 380 at SUNY Buffalo.

Ask a homework question - tutors are online