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.

68 CHAPTER 2 <strong>Instruction</strong> <strong>Sets</strong>LDR r0,[r4] ; get value of aMUL r2,r2,r0 ; compute final value of yADR r4,y ; get address for ySTR r2,[r4] ; store value of y at proper locationThe C statementz (a 2) | (b & 15);can be coded using r0 for a and z, r1forb, and r4 for addresses as follows:ADR r4,aLDR r0,[r4]MOV r0,r0,LSL 2ADR r4,bLDR r1,[r4]AND r1,r1,#15ORR r1,r0,r1ADR r4,zSTR r1,[r4]; get address for a; get value of a; perform shift; get address for b; get value of b; perform logical AND; compute final value of z; get address for z; store value of zWe have already seen three addressing modes: register, immediate, and indirect.The ARM also supports several forms of base-plus-offset addressing, which isrelated to indirect addressing. But rather than using a register value directly asan address, the register value is added to another value to form the address. Forinstance,LDR r0,[r1,#16]loads r0 with the value stored at location r1 16. Here,r1 is referred to as the baseand the immediate value the offset. When the offset is an immediate, it may haveany value up to 4,096;another register may also be used as the offset.This addressingmode has two other variations:auto-indexing and post-indexing. Auto-indexingupdates the base register, such thatLDR r0,[r1,#16]!first adds 16 to the value of r1, and then uses that new value as the address. The! operator causes the base register to be updated with the computed address sothat it can be used again later. Our examples of base-plus-offset and auto-indexinginstructions will fetch from the same memory location, but auto-indexing will alsomodify the value of the base register r1. Post-indexing does not perform the offsetcalculation until after the fetch has been performed. Consequently,LDR r0,[r1],#16will load r0 with the value stored at the memory location whose address is given byr1, and then add 16 to r1 and set r1 to the new value. In this case, the post-indexed

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

Saved successfully!

Ooh no, something went wrong!