How is the “update condition flags” S encoded in the 16-bit Thumb-2 assembly instruction set?

StackOverflow https://stackoverflow.com/questions/12980847

  •  09-07-2021
  •  | 
  •  

Question

So I need to write a very basic disassembler for class and I'm having a hard time figuring out how the S that can be appended to Thumb instructions is encoded.

For example, the instruction 0x0011 corresponds with the following assembly code:

movs    r1, r2

Why wouldn't it just be a regular mov?

Likewise, 0x1889 corresponds with:

adds    r1, r1, r2

As far as I can tell from reading the reference manual, this is the same encoding as the regular add instruction without the S. Is this the case? How is the instruction for updating condition flags sent?

Was it helpful?

Solution

Thumb doesn't use the S condition field for each instruction, so every instruction is unconditional (aside from the conditional branches, obviously). Part of the reduction from 32-bit ARM to 16-bit Thumb involved getting rid of it. The examples you provided shouldn't have the s to begin with, in my opinion (they don't get used in this manual).

Condition codes in Thumb are set implicitly by your ALU instructions (same as ARM), but to access them you need to use conditional branches.

OTHER TIPS

gnu assembler is very annoying and messes up instruction sets, but that is another story. for thumb mode dont put the s it complains but since you do not have a choice it is always there. just do an add r1,r2 assemble then disassemble and you will see the adds r1,r2 also if you double check and look at the machine instruction relative to what the manual says it also shows that the update flags will happen

0x0011 is a lsl immed_5, rm, rn so that is lsl r1,r2,#0 not an add.

0x1889 is indeed an add r1,r1,r2. the s is not a bit in the instruction set for thumb it is implied.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top