Sie sind auf Seite 1von 33

Architectural Support for High level languages

Data Types
Number ranges: ARM deals efficiently with 32-bit quantities, so the first data type that the architecture supports is the 32-bit unsigned! integer, which has a "alue in the range: # to $ 2%$ %&' 2%()# * # to ++++++++ )&, ARM supports a 2-s complement binary notation where the "alue of the top bit is made negati"e. in a 32-bit signed integer all the bits ha"e the same "alue as they ha"e in the unsigned case apart from bit 3), which has the "alue -23) instead of/23), Now the range of numbers is: -2 )$' $03 &$0)# to /2 )$' $03 &$')# * 0#######)& to '+++++++)&

Floating-point data types

+loating-point numbers attempt to represent real numbers with uniform accuracy, A generic way to represent a real number is in the form: R=axbn where n is chosen so that a falls within a defined range of "alues. b is usually implicit in the data type and is often equal to 2,

IEEE 754
1he most compact representation of a floating-point number defined by 2333 '($ is the 32-bit -single precision- format:

E pressions
1he basic ARM integer data processing instruction implement most of the 4 integer arithmetic, bit-wise and shift primiti"es directly, 35ceptions are di"ision and remainder which require se"eral ARM instructions, Accessing operands: A procedure will normally wor6 with operands that are presented in one of the following ways, and can be accessed as indicated: ), As an argument passed through a register, 1he "alue is already in a register, so no further wor6 is necessary,

2, As an argument passed on the stac6, 7tac6 pointer r)3! relati"e addressing with an immediate offset 6nown at compile-time allows the operand to be collected with a single 89R, 3, As a constant in the procedure-s literal pool, :4-relati"e addressing, again with an immediate offset 6nown at compile-time, gi"es access with a single 89R, $, As a local "ariable, 8ocal "ariables are allocated space on the stac6 and are accessed by a stac6 pointer relati"e 89R, (, As a global "ariable, ;lobal and static! "ariables are allocated space in the static area and are accessed by static base relati"e addressing,

!ointer arith"etic
Arithmetic on pointers depends on the si<e of the data type that the pointers are pointing to, 2f a pointer is incremented it changes in units of the si<e of the data item in bytes, int =p. : * :/). increase the "alue of p by $ bytes,! 2f a "ariable is used as an offset it must be scaled at runtime: int i * $ . p * p / i.


#onditional state"ents
4onditional statements are e5ecuted if the >oolean result of a test is true or false!. in 4 these include if,,,else statements and switches 4 -case- statements!, if,,,else 1he ARM architecture offers unusually efficient support for conditional e5pressions when the conditionally e5ecuted statement is small, +or e5ample, here is a 4 statement to find the ma5imum of two integers: if a?b! c*a. else c*b.

2f the "ariables a, b and c are in registers r#, r) and r2, the compiled code could be as simple as:

7witches A switch, or case, statement e5tends the two-way decision of an if,,,else statement to many ways, 1he standard 4 form of a switch statement is:


An alternati"e is to use a @ump table, 2n its simplest form a @ump table contains a target address for each possible "alue of the switch e5pression, 2t is not possible for the @ump table to contain an address for e"ery possible "alue of a 32-bit integer


1he 4 language supports three forms of loop control structure: A for el.e2.e3!B,,C A while el! B,,C A do B,,C while el! Dere el, e2 and e3 are e5pressions which e"aluate to -trueor -false- and B,,C is the body of the loop which is e5ecuted a number of times determined by the control structure,


For loops


%hile loops


do&&%hile loops
1he conceptual arrangement of a -do,,while- loop is similar to the impro"ed -whileE loop abo"e, but without the initial branch since the loop body is e5ecuted before the test and is therefore always e5ecuted at least once!: 8FF: ,, G,, >N3 8FF: 3H21 . loop body . e"aluate e5pression


Functions and procedures

8arge programs are bro6en down into components that are small enough to be thoroughly tested, A large, monolithic program is too comple5 to test fully and is li6ely to ha"e -bugs- in hidden corners, :rogram hierarchy: 1he top of the hierarchy is the program called main. 1he remaining hierarchy is fairly informal. lower-le"el routines may be shared by higher-le"el routines, calls may s6ip le"els, and the depth may "ary across the hierarchy,



8eaf routines: At the lowest le"el of the hierarchy there are leaf routines; these are routines which do not themsel"es call any lowerle"el routines, 2n a typical program some of the bottom-le"el routines will be library or system functions. these are predefined operations which may or may not be leaf routines,


1here are se"eral terms that are used to describe components of this program structure Subroutine: a generic term for a routine that is called by a higher-le"el routine, particularly when "iewing a program at the assembly language le"el, Function: a subroutine which returns a "alue through its name, A typical in"ocation loo6s li6e: c * ma5 a, b!. Procedure: a subroutine which is called to carry out some operation on specified data item s!, A typical in"ocation loo6s li6e: printf IDello JorldHnI!.

4 functions: 7ome programming languages ma6e a clear distinction between functions and procedures, but 4 does not, Arguments and parameters: An argument is an e5pression passed to a function call. a "alue recei"ed by the function is a parameter. 4 uses a strict -call by "alue- semantics, so a copy is made of each argument when a function is called and, though the function may change the "alues of its parameters, since these are only copies of the arguments the arguments themsel"es are not affected,


A'( !rocedure #all Standard )A!#S*

2n order to support fle5ible mi5ing of routines generated by different compilers and written in assembly language, ARM 8imited has defined a set of rules for procedure entry and e5it, 1he A:47 imposes a number of con"entions on the ARM architecture: 2t defines particular uses for the -general-purposeregisters, 2t defines which form of stac6 is used from the fullKempty, ascendingKdescending choices supported by the ARM instruction set, 2t defines the format of a stac6-based data structure used for bac6-tracing when debugging programs,

2t defines the function argument and result passing mechanism to be used by all e5ternally "isible functions and procedures, -35ternally "isible- means that the procedure interface is offered outside the current programming module,! 2t supports the ARM shared library mechanism, which means it supports a standard way for shared re-entrant! code to access static data,


+se of "e"ory
An ARM system, li6e most computer systems, has its memory arranged as a linear set of logical addresses, A 4 program e5pects to ha"e access to a fi5ed area of program memory where the application image resides! and to memory to support two data areas that grow dynamically and where the compiler often cannot wor6 out a ma5imum si<e, 1he dynamic data areas are: 1he stac6, Jhene"er a function is called, a new acti"ation frame is created on the stac6 containing a bac6 trace record, local non-static! "ariables, and so on, Jhen a function returns its stac6 space is automatically reco"ered and will be reused for the ne5t function call,

1he heap, 1he heap is an area of memory used to satisfy program requests malloc !! for more memory for new data structures, A program which continues to request memory o"er a long period of time should be careful to free up all sections that are no longer needed, otherwise the heap will grow until memory runs out, 2n a typical memory managed ARM system the logical space allocated to a single application will be "ery large, in the range of ) to $ ;bytes,



#hun,ed stac, "odel

A -chun6ed- stac6 is, where the stac6 is a series of chained chun6s within the heap, 1his causes the application to occupy a single contiguous area of memory, which grows in one direction as required, and may be more con"enient where memory is "ery tight,


Stac, -ehaviour



Data storage
1he "arious data types supported in 4 require differing amounts of memory to store their binary representations, 1he basic data types occupy a byte chars!, a half-word short ints!, a word ints, single precision float! or multiple words double precision floats!, 9eri"ed data types structs, arrays, unions, and so on! are defined in terms of multiple basic data types,


Data align"ent
1he ARM 4 compiler generally aligns data items on appropriate boundaries: A >ytes are stored at any byte address, A Dalf-words are stored at e"en byte addresses, A Jords are stored on four-byte boundaries, Jhere se"eral data items of different types are declared at the same time, the compiler will introduce padding where necessary to achie"e this alignment:


struct 72 Bchar c. int 5. short s.C e5ample).

+ig: 35ample of normal struct memory allocation


Memory efficiency: struct S2 {char c; short s; int x;} example2;

+ig: 35ample of more efficient struct memory allocation


:ac6ed structs ,,pac6ed struct 73 Bchar c. int 5. short s ; } e5ample3.

+ig: 35ample of pac6ed struct memory allocation