ARMAssemblylanguageprogramming.ppt
《ARMAssemblylanguageprogramming.ppt》由会员分享,可在线阅读,更多相关《ARMAssemblylanguageprogramming.ppt(41页珍藏版)》请在三一办公上搜索。
1、ARM Assembly language programming,AgendaARM Data processing instructionsARM Data transfer instructionsArm Control flow instructionsFeatures of Thumb state,ARM uses three types of instructionsData processing instructions(arithmetic operations,logical operations,register moves,comparisons,shift operat
2、ions).Data transfer(register load/store instructions).Control flow instructions(branch instructions).,Data processing instructions Rules apply to ARM data processing instructions:-All operands are 32 bit s,come either from registers or aas specified as constants in the instruction itself-The result
3、is also 32 bits and is placed in a register.-3 operands are used:2 for inputs and 1 for result.Ex.:ADD r0,r1,r2;r0=r1+r2 Works for both unsigned and 2s complement signed numbers.This may produce carry out signal and overflow bits,but ignored by default Result register can be same as an input operand
4、 register.,Data processing instructions(contd)ARMs basic arithmetic operations:,ADD r0,r1,r2;r0=r1+r2ADC r0,r1,r2;r0=r1+r2+CSUB r0,r1,r2;r0=r1 r2 SBC r0,r1,r2;r0=r1 r2+c+1RSB r0,r1,r2;r0=r2 r2RSC r0,r1,r2;r0=r2 r1+c-1,RSB stands for reverse subtraction.Operands may be unsigned or 2s complement integ
5、ers.C is the carry bit in the CPSR,Data processing instructions(contd)ARMs bit-wise logical operations:,AND r0,r1,r2;r0=r1 and r2(bit-by-bit for 32 bits)ORR r0,r1,r2;r0=r1 or r2 EOR r0,r1,r2;r0 r1 xor r2BIC r0,r1,r2;r0=r1 and not r2,BIC stands for bit clear,where every 1 in the second operand clears
6、 the corresponding bit in the first:,r1:0101 0011 1010 1111 1101 1010 0110 1011r2:1111 1111 1111 1111 0000 0000 0000 0000r0:0000 0000 0000 0000 1101 1010 0110 1011,Data processing instructions(contd)ARMs register move operations:,MOV r0,r2;r0=r2MVNr0,r2;r0=not r2,MVN stands for move negated:,r2:0101
7、 0011 1010 1111 1101 1010 0110 1011r0:1010 1100 0101 0000 0010 0101 1001 0100,Data processing instructions(contd)ARMs register comparison operations:,CMP r1,r2;set cc on r1 r2CMNr1,r2;set cc on r1+r2TSTr1,r2;set cc on r1 and r2TEQr1,r2;set cc on r1 xor r2,results of subtract,add,and,xor are NOT stor
8、ed in any registersThe condition code bits(cc)in the CPSR are set or cleared by these instructions Ex CMN r1,r2:N=1 if MSB of the addition(r1+r2)results in 1 else N=0Z=1 if the result of the addition is zero,else Z=0C is set to the carry-out of the additionV is set to the overflow of the addition,Da
9、ta processing instructions(contd)ARM has clever feature.In any data processing instructions,we can apply to the second register a shift operation For example:,ADD r3,r2,r2,LSL#3,Here LSL means logical shift left by the specified number of bits.Note that this is still a single ARM instruction,execute
10、d in a single cycle In most processors,this is a separate instruction,while ARM integrates this shifting into the ALU It is also possible to use a register value to specify the number of bits the second operand should be shifted by:,ADD r3,r2,r2,LSL r2,Data processing instructions(contd)Six possible
11、 ARM shift operations can be used,00000,00000,31,0,0,31,LSL#5,LSR#5,LSL:fill the vacated bits at the least significant end of the word with zeros.LSR:fill the vacated bits at the most significant end of the word with zeros.,Data processing instructions(contd)ASL:this is the same as LSK.ASR:fill the
12、vacated bits at the most significant end of the word with zeros if the source operand was positive,and with ones it is negative.,0,1,11111 1,00000 0,31,0,0,31,ASR#5,positive operand,ASR#5,negative operand,Data processing instructions(contd)ROR:the bits which fall off the least significant end are us
13、ed to fill the vacated bits at the most significant end of the word.RRX:rotate right extended by 1 place:the vacated bit(bit 31)is filled with the old value of the C flag and the operand is shifted one place to the right.This is effectively a 33 bit rotating using the register and the C flag,31,0,0,
14、31,ROR#5,RRX,C,C,Data processing instructions(contd)ARM has a number of multiply instructions:-produce the product of two 32-bit binary numbers held in the registers.-result of 32-bit by 32-bit is 64 bits,.The entire 64-bit result is stored in two registers.Sometimes only 32 bits of the product are
15、saved-Multiply Accumulate instruction also adds the product to a running total.,MUL r4,r3,r2;r4=r3*r2 MLA r4,r3,r2,r1;r4=(r3*r2)+1,Difference from the other arithmetic operations:-immediate second operands are not supported-the result register cannot be the same as the second source register.,ARM DA
16、TA transfer instructions 3 basic forms of data transfer instructions:-single register load/store instructions.-Multiple register load/sore instructions-single register swap instruction(combined lad and sore)Use a value in one register(called the base register)as a memory address and either loads the
17、 data value from that address into a designation register or stores the register value to memory:LDRr0,r1;r0=mem32r1STR r0,r1;mem32r1=r0 This is called register-indirect addressing,ARM DATA transfer instructions(contd)to load or store from or to a memory locations,an ARM register must be initialized
18、 to contain the address of that location.In order to do that a pseudo instruction is used:ADR(the assembler translate it to a real data processing instruction)Ex.Copy of data within memory TABLE1 to TABLE2,CopyADRr1,TABLE1ADR r2,TABLE2LDRr0,r1STRr0,r2.TABLE1.TABLE2.,ARM DATA transfer instructions(co
19、ntd)Extend the copy program further to copy the next word:,CopyADRr1,TABLE1ADR r2,TABLE2LDRr0,r1STRr0,r2ADD r1,r1,#4ADD r2,r2,#4.TABLE1.TABLE2.,Simplify with pre-indexed addressing mode:LDR r0,r1,#4;r0=mem32 r1+4,Base address,offset,Effective address,ARM DATA transfer instructions(contd)pre-indexed
20、addressing does not change r1.Sometimes,it is useful to modify the base register to point to the new address.This is achieved by adding a!,and we then have auto-indexing:LDR r0,r1,#4!;r0=mem31 r1+4;r1=r1+4The!indicates that the instruction should update the base register after the data transfer.In p
21、ost-indexed addressing,the base address is used without an offset as the transfer address,after which it is always modified.Using this,we can improce the program mpre LDR r0,r1,#4;r0=mem32r1;r1=r1+4,CopyADRr1,TABLE1ADR r2,TABLE2LDRr0,r1,#4STRr0,r2,#4.TABLE1.TABLE2.,ARM DATA transfer instructions(con
22、td),LDR and STR instructions are repeated until the required number of values has been copied into TABLE2,and then the loop is exited,ARM DATA transfer instructions(contd),The size of the data item which is transferred may be a single 8-bit byte instead of a 32-bit word.This option is selected by ad
23、ding a letter B onto the symbolic operation code:,LDRB ro,r1;r0=mem8 r1,LDR and STR instructions only load/store a single 32-bit word,ARM DATA transfer instructions(contd)Multiple register data transfersARM can load/store any subset of its register in a single instruction by using load/store multipl
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ARMAssemblylanguageprogramming
链接地址:https://www.31ppt.com/p-2878467.html