ARM汇编语言指令集(3)

 
  • 常数
There is no single instruction which will load a 32 bit immediate constant into a register without performing a data load from memory. The data processing instruction format has 12 bits available for operand2. Instead it is used to store 8 bit constants, giving a range 0-255.These 8 bits can be rotated right through an even umber of positions(ie RORs by 0,2 ,4…,30)
 
MOV, LDR只能使用8位位图立即数,这8位立即数可以由0-255之间的数循环右移(ror)而来。即这个数除以4,一直除,直到0-255范围内它为整数即可!例如0xF0000001是由0x1F循环右移4位而来。这样做是因为指令长度限制,不可能把32位立即数放在32位指令中,移位偶数也是此原因。例如合法常量有:0x3FC, 0xF0000000, 200, 0xF0000001;非法常量:0x1FE, 511, 0xFFFF, 0x1010, 0xF0000010等。但是MOV r0, #0xFFFFFFFF是合法的,因为等同于MVN r0, #0.
MOV r0,#4096是合法的,是因为4096可由0x40 ror 26而来。只要这些常量可由循环右移或者MVN产生,就是合法的。
If the required constant cannot be generated, an error will be reported.
Although the MOV/MVN mechanism will load a large range of constants into a register, sometimes this mechanism will not generate the required constant. Therefore, the assembler also provides a method which will load ANY 32 bit constant: LDR rd, = numeric constant.这种情况下,如果该常数可由MOV或MVN来实现,则会产生效果等同的MVN/MOV指令。Otherwise, the assembler will produce an LDR instruction with a PC-relative address to read the constant from a literal pool.
LDR r0, =0x42               ;generates MOV r0, #0x42
LDR r0, =0x55555555   ;generate LDR r0, [pc, offset to literal pool]
 
 
  • Branch instructions
Branch :                     B{<cond>} label
Branch with Link:      BL{<cond>} sub_routine_label
The offset for branch instructions is calculated by the assembler:By taking the difference between the branch instruction and the target address minus 8(to allow for the pipeline). This gives a 26 bit offset which is right shifted 2 bits(as the bottom two bits are always zero as instructions are word-aligned) and store into the instruction encoding. This gives a range of 32M bytes 
 
·          Multiplication Instructions
The basic ARM provides two multiplication instructions.
Multiply: MUL{<cond>}{S} Rd, Rm, Rs            ;Rd = Rm * Rs
Multiply Accumulate: MLA{<cond>}{S}Rd, Rm,Rs,Rn ;Rd =(Rm*Rs)+Rn
Restrictions on use: Rd and Rm connot be the same register, can be avoid by swapping Rm and Rs aroud. This works because multiplication is commutative
 
乘法指令与乘加指令共有6条:
 
指令
描述
格式
MUL
32 位元乘方指令
MUL{<cond>}{S}Rd,Rm,Rs
MLA
32 位元乘加指令
MLA{<cond>}{S}Rd,Rm,Rs,Rn
SMULL
64 位元有符号数乘法指令
SMULL{<cond>}{S}RdLo,RdHi,Rm,Rs
SMLAL
64 位元有符号数乘加指令
SMLAL{<cond>}{S}RdLo,RdHi,Rm,Rs
UMULL
64 位元无符号数乘法指令
UMULL{<cond>}{S}RdLo, RdHi, Rm, Rs
UMLAL
64 位元无符号数乘加指令
UMLAL{<cond>}{S}RdLo,RdHi, Rm,Rs
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值