10.07.2015 Views

Instruction Sets

Instruction Sets

Instruction Sets

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.2 ARM Processor 612.2.2 Data OperationsArithmetic and logical operations in C are performed in variables. Variables areimplemented as memory locations. Therefore, to be able to write instructions toperform C expressions and assignments, we must consider both arithmetic andlogical instructions as well as instructions for reading and writing memory.Figure 2.7 shows a sample fragment of C code with data declarations and severalassignment statements. The variables a, b, c, x, y, and z all become data locationsin memory. In most cases data are kept relatively separate from instructions in theprogram’s memory image.In the ARM processor, arithmetic and logical operations cannot be performeddirectly on memory locations. While some processors allow such operationsto directly reference main memory, ARM is a load-store architecture—dataoperands must first be loaded into the CPU and then stored back to main memoryto save the results. Figure 2.8 shows the registers in the basic ARM programmingmodel. ARM has 16 general-purpose registers, r0 through r15. Except for r15, theyare identical—any operation that can be done on one of them can be done on theother one also. The r15 register has the same capabilities as the other registers, butit is also used as the program counter.The program counter should of course not beoverwritten for use in data operations. However, giving the PC the properties of ageneral-purpose register allows the program counter value to be used as an operandin computations, which can make certain programming tasks easier.The other important basic register in the programming model is the currentprogram status register (CPSR). This register is set automatically duringevery arithmetic, logical, or shifting operation. The top four bits of the CPSRhold the following useful information about the results of that arithmetic/logicaloperation:■ The negative (N) bit is set when the result is negative in two’s-complementarithmetic.■ The zero (Z) bit is set when every bit of the result is zero.■ The carry (C) bit is set when there is a carry out of the operation.■ The overflow (V) bit is set when an arithmetic operation results in an overflow.FIGURE 2.7A C fragment with data operations.int a, b, c, x, y, z;x (a b) c;y a*(b c);z (a

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!