刘帅嵌入式系统-ADD加法指令
ADD 指令将< > 表示的数据与寄存器< Rn >中的值相加,并把结果保存到目标寄存器< Rd > 中,同时根据操作的结果更新CPSR中相应的条件标志位。
指令的编码格式
指令的语法格式
ADD{< cond >} {S} < Rd >, < Rn> ,< >
其中:
指令操作的伪代码
if ConditionPassed<cond> thenRd=Rn + shifter_operandif S==1 and Rd==R15 thenCPSR=SPSRelse if S==1 thenN Flag=Rd[31]Z Flag=if Rd==0 then 1 else 0C Flag=CarryFrom(Rn + shifter_operand)V Flag=OverflowForm(Rn + shifter_operand)
指令的使用
ADD指令实现两个操作数相加。
典型的用法:
ADD Rx, Rx, #1 ;Rx=Rx+1
ADD Rd, Rx, Rx, LSL #n ;Rx=Rx+Rx*(2*n)
ADD Rs, PC, #offset ;生成基于PC的跳转指针