Module 4
Syllabus - Module 4
4.1 Architectural Support for High-Level Languages
Abstraction in software design, Data types, Floating-point data types, The ARM
floating-point architecture, Expressions, Conditional statements, Loops, Functions and
procedures, Use of memory, Run-time environment.
4.2 The Thumb Instruction Set
The Thumb bit in the CPSR, The Thumb programmer's model, Thumb branch instructions,
Thumb software interrupt instruction, Thumb data processing instructions, Thumb single
register data transfer instructions, Thumb multiple register data transfer instructions,
Thumb breakpoint instruction, Thumb implementation, Thumb applications.
4.3 Architectural Support for System Development
The ARM memory interface, The Advanced Microcontroller Bus Architecture (AMBA).
4.4 Programming
Assembly and C language programming applications of embedded systems.
Architectural Support for High-Level Languages
• ARM architectural support for high-level languages refers to the tools and
methods used to develop ARM programs in high-level languages.
• High-level languages allow a program to be expressed in terms of abstractions
such as data types, structures, procedures, functions, and so on.
• Here we look at the requirements that a high-level language imposes on an
architecture and see how those requirements may be met.
• We will use C as the example high-level language
Abstraction in software design
Assembly-level abstraction
• Abstraction is important, then, at the assembly programming level, but all the responsibility for
supporting the abstraction and expressing it in terms of the machine primitives rests with the
programmer, who must therefore have a good understanding of those primitives and be
prepared to return frequently to think at the level of the machine.
High-level languages
• A high-level language allows the programmer to think in terms of abstractions that are above
the machine level; indeed, the programmer may not even know on which machine the
program will ultimately run. Parameters such as the number of registers vary from architecture
to architecture, so clearly these must not be reflected in the design of the language
Abstraction in software design
• In assembly language programming level ,the programmer works (almost)
directly with the raw machine instruction set, expressing the program in terms of
instructions, addresses, registers, bytes and words.
• A high-level language allows the programmer to think in terms of abstractions
that are above the machine level; indeed, the programmer may not even know
on which machine the program will ultimately run.
• The job of supporting the abstractions used in the high-level language on the
target architecture falls upon the compiler.
• Compilers are themselves extremely complex pieces of software.
Data types
ANSI (American National Standards Institute ) C basic data types
Signed and unsigned characters of at least eight bits.
Signed and unsigned short integers of at least 16 bits.
Signed and unsigned integers of at least 16 bits.
Signed and unsigned long integers of at least 32 bits.
Floating-point, double and long double floating-point numbers.
Enumerated types.
Bit fields.
Data types
ANSI C derived data types
• Arrays of several objects of the same type.
• Functions which return an object of a given type.
• Structures containing a sequence of objects of various types.
• Pointers (which are usually machine addresses) to objects of a given type.
• Unions which allow objects of different types to occupy the same space
at different times.
Floating-point data types
The Arm architecture provides high-performance and high-efficiency hardware
support for floating point operations .
The floating point data type is essential for a wide range of digital signal
processing (DSP) applications.
Floating-point data types
The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for
floating-point computation which was established in 1985 by the Institute of
Electrical and Electronics Engineers (IEEE).
• There are several ways to represent floating point number but IEEE 754 is the most
efficient in most cases. IEEE 754 has 3 basic components:
• The Sign of Mantissa –
This is as simple as the name. 0 represents a positive number while 1 represents a
negative number.
• The Biased exponent –
The exponent field needs to represent both positive and negative exponents. A bias
is added to the actual exponent in order to get the stored exponent.
• The Normalised Mantissa –
The mantissa is part of a number in scientific notation or a floating-point number,
consisting of its significant digits. Here we have only 2 digits, i.e. O and 1. So a
normalised mantissa is one with only one 1 to the left of the decimal
Floating-point data types
IEEE 754 numbers are divided into two based on the above three
components:
• single precision and
• double precision.
Floating-point data types - single precision floating point data format
To convert a number to floating point data type, 3 steps are followed
For better understanding on how to represent in arm floating point format we
we consider the number 1995
Step 1
• Convert 1995 to binary representation, which is: 11111001011 .
• This is a positive number, so the S bit will be zero
Floating-point data types - single precision floating point data format
Step 2
Step 3
Represent in single precision format(ARM floating point data format)
Floating-point data types - single precision floating point data format
Floating-point data types - Double precision floating point data format
• Greater accuracy may be achieved by using the double precision format
• which uses 64 bits to store each floating-point value.
• The interpretation is similar to that for single precision values, but now
the exponent bias for normalized numbers is +1023
IEEE 754 double precision floating-point number format.
Floating-point data types - Double extended precision floating point data
format
• More accuracy is available from the double extended precision format, which
uses 80 bits of information spread across three words.
• The exponent bias is 16383, and the J bit is the bit to the left of the binary point.
Packed decimal floating-point number format.
Some processors support packed decimal floating-point number format.
IEEE 754 packed decimal floating-point number format.
The ARM floating-point architecture
The ARM FPA10 hardware floating-point architecture supports single, double
and extended double precision format
Its external interface is to the ARM data bus and the coprocessor handshake
signals, so it has a modest pin-count requirement.
The coprocessor pipeline follower
The load/store unit that carries out format conversion on floating-point data
types as they are loaded from and stored to memory.
The register bank which stores eight 80-bit extended precision floating-point
operands.
The arithmetic unit which incorporates an adder, a multiplier and a divider,
together with rounding and normalizing hardware.
The ARM floating-point architecture
The ARM floating-point architecture
• The FPA10 arithmetic unit operates in four pipeline stages:
1. Prepare: align operands.
2. Calculate: add, multiply or divide.
3. Align: normalize the result.
4. Round: apply appropriate rounding to the result.
The FPA10 is used as a macrocell on the ARM7500FE chip
A much higher performance floating-point unit, the VFP10, has been
designed to operate with the ARM10TDMI processor core
Expressions
• Since all data processing instructions operate only on values in register, the key
to the efficient evaluation of a complex expression is to get the required values
into the registers in the right order and to ensure that frequently used values are
normally resident in registers
• Few methods to sort the expression in the right order to load and combine
operands to achieve the result according to the operator precedence is given
below.
Expressions
• Pointer arithmetic
• A pointer is a memory address that holds the location of a data item.
• Arithmetic on pointers depends on the size of the data type that the pointers are pointing to.
• If a pointer is incremented it changes in units of the size of the data item in bytes(according to the data types)
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).
• The ARM architecture offers unusually efficient support for conditional expressions when the
conditionally executed statement is small.
If..else
switches
Loops
Functions and procedures
• Good programming practice requires that large programs are broken down into
components that are small enough to be thoroughly tested;
• Furthermore, the full program should be designed as a hierarchy of components.
Functions and procedures
• A typical hierarchy is illustrated in Figure.
• The top of the hierarchy is the program called main.
• The remaining hierarchy is fairly informal; lower-level routines may be shared by
higher-level routines
• At the lowest level of the hierarchy there are leaf routines; these are routines
which do not themselves call any lower-level routines.
• In a typical program some of the bottom-level routines will be library or system
functions; these are predefined.
Functions and procedures
Terminology
Use of memory
• An ARM system, like most computer systems, has its memory arranged as a linear set of logical
addresses. A C program expects to have access to a fixed 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 work out a maximum size. These dynamic data areas are
Use of memory
Address space model : The normal use of memory is illustrated in Figure
Run-time environment
Run-time environment
• Minimal run-time library
Example program
The Thumb Instruction Set
The Thumb instruction set is a subset of the ARM instruction set and the
instructions operate on a restricted view of the ARM registers
The instruction set gives full access to the eight 'Lo' general purpose registers
r0 to r7, and makes extensive use of r13 to r15 for special purposes:
• r13 is used as a stack pointer. • r14 is used as the link register. • r15 is the
program counter (PC)
• The remaining registers (r8 to r12 and the CPSR) have only restricted access:
• A few instructions allow the 'Hi' registers (r8 to r15) to be specified. • The
CPSR condition code flags are set by arithmetic and logical operations and
control conditional branching
• All Thumb instructions are 16 bits long. They map onto ARM instructions so
they inherit many properties of the ARM instruction set:
The Thumb Instruction Set
The “T” bit in CPSR toggles
ARM processors which support the Thumb instruction set can also execute the
standard 32-bit ARM instruction set, and the interpretation of the instruction
stream at any particular time is determined by bit 5 of the CPSR, the T bit.
• If T is set the processor interprets the instruction stream as 16-bit Thumb
instructions, otherwise it interprets it as standard ARM instructions
• Not all ARM processors are capable of executing Thumb instructions; those that
are have a T in their name, such as the ARM7TDMI
The Thumb programmer's model
Switching between ARM and Thumb instructions
• ARM cores start up, after reset, executing ARM instructions. The normal way they
switch to execute Thumb instructions is by executing a Branch and Exchange
instruction
• An explicit switch back to an ARM instruction stream can be caused by executing a
Thumb BX instruction
The Thumb programmer's model
Thumb branch instructions
Thumb software interrupt instruction
Thumb data processing instructions
Thumb single register data transfer instructions
Thumb multiple register data transfer
instructions
Thumb breakpoint instruction
Thumb implementation
Thumb implementation
Thumb to ARM instruction mapping.
Thumb applications
• The Thumb code requires 70% of the space of the ARM code.
• The Thumb code uses 40% more instructions than the ARM code.
• With 32-bit memory, the ARM code is 40% faster than the Thumb code.
• With 16-bit memory, the Thumb code is 45% faster than the ARM code.
• Thumb code uses 30% less external memory power than ARM code.
• So where performance is all-important, a system should use 32-bit memory
and run ARM code.
• Where cost and power consumption are more important, a 16-bit memory
system and Thumb code may be a better choice.
Thumb systems
• A high-end 32-bit ARM system may use Thumb code for certain non-critical
routines to save power or memory requirements.
• A low-end 16-bit system may have a small amount of on-chip 32-bit RAM
for critical routines running ARM code, but use off-chip Thumb code for all
non-critical routines.
• Mobile telephone and pager applications incorporate real-time digital
signal processing (DSP) functions that may require the full power of the
ARM, but these are tightly coded routines that can fit in a small amount of
on-chip memory. The more complex and much larger code that controls the
user interface, battery management system, and so on, is less time-critical,
and the use of Thumb code will enable off-chip ROMs to give good
performance on an 8- or 16-bit bus, saving cost and improving battery life.
A basic ARM memory system.
The ARM memory interface
• A 32-bit address bus, A[31:0], which gives the byte address of the data to be
accessed.
• A 32-bit bidirectional data bus, D[3J:OJ, along which the data is transferred.
• Signals that specify whether the memory is needed (mreq) and whether the
address is sequential (seq); these are issued in the previous cycle so that the
memory control logic can prepare appropriately.
• Signals that specify the direction (r/w) and size (b/w on earlier processors;
mas[1:0] on later processors) of the transfer.
• Bus timing and control signals (abe, ale, ape, dbe, lock, bl[3:0]).
DRAM memory organization.
DRAM memory organization.
• The cheapest memory technology (in terms of price per bit) is dynamic
random access memory (DRAM).
• 'Dynamic' memory stores information as electrical charge on a capacitor
where it gradually leaks away (over a millisecond or so).
• The memory data must be read and rewritten ('refreshed') before it leaks
away.
• Like most memory devices, the storage cells in a DRAM are arranged in a
matrix which is approximately square.
• Unlike most other memory devices, this organization is exposed to the user.
• The matrix is addressed by row and by column, and a DRAM accepts the
row and column addresses separately.
DRAM memory organization.
• First the Row address strobe signal (ras) and then the column
address is presented and latched using the active-low column address
strobe (cas).
• If the next access is within the same row, a new column address may
be presented without first supplying a new row address.
• Since a cas-only access does not activate the cell matrix it can deliver
its data two to three times faster than a full ras-cas access and
consumes considerably less power.
• It is therefore very advantageous to use cas-only accesses whenever
possible.
AMBA
• AMBA stands for Advanced Microcontroller Bus Architecture. AMBA
specification specifies an on chip communication standard. This is
used to design embedded microcontrollers with high performance.
• AMBA an established open source specification for on-chip
interconnects.
• AMBA serves as a framework for SoC designs and development of the
IP library.
• AHB support in all new ARM cores.
AMBA