问题
I am learning ARM Assembly Language. I'v read ADD should have 3 operands. However, I'v seen many cases in reality there are only two. such as:
STR R1, [SP,#0x20+var_1C]
LDR R1, =(a_lua - 0x1DE4E6)
MOVS R0, R4 ; haystack
ADD R1, PC
BLX strstr
CMP R0, #0
BNE loc_1DE4FA
Can any one help me with the meaning of ADD with two operands? Many thanks!
回答1:
Given the information in the comments that this really is ARM code, not 16-bit Thumb, then the answer is that your reference material predates UAL.
The introduction of the Thumb-2 instruction set brought along a modified assembly syntax called Unified Assembly Language which superceded the previous syntaxes for ARM and Thumb. Rather than have two separate (and incompatible) languages, UAL allows (within reason) the same source to be assembled to either ARM or Thumb instructions. One of the consequences of this is that for any 3-operand ARM instructions that has a 2-operand Thumb equivalent, specifying the destination register is optional - if omitted it will default to the first source register*.
Most assemblers will still support the older pre-UAL syntax for compatibility, but it's worth updating to a more modern reference once you get past the basics since there are some potentially confusing changes (like nearly all of the floating-point mnemonics).
* except in the case of MUL
where it's the other way round for awkward technical reasons.
回答2:
This is a shortcut notation, there is no 2 operand add or sub in ARM (however Thumb does have them).
add r0, r1
basically means use the first operand as the destination and first source register. It is identical to the instruction below and gets assembled to the same instruction.
add r0, r0, r1
来源:https://stackoverflow.com/questions/25503967/add-or-sub-with-only-two-operands-in-arm