Skip to content

Fix the condition, register and immediate of arm32 cmp, cmn, tst and teq ##arch - #27141

Merged
trufae merged 1 commit into
radareorg:masterfrom
HuzaifaChaudary:arm32-compare-immediates
Oct 23, 2026
Merged

trufae merged 1 commit into
radareorg:masterfrom
HuzaifaChaudary:arm32-compare-immediates

Conversation

@HuzaifaChaudary

@HuzaifaChaudary HuzaifaChaudary commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
  • Mark this if you consider it ready to merge
  • I've added tests (optional)
  • I wrote some lines in the book (optional)

Description

cmp , cmn , tst and teq with an immediate dropped the condition , and above 255 also the register :

input before ( decoded with llvm-mc ) after
cmnhi r10, 417792 cmn r0, #208896 660a7a83
teqeq r11, 1856 teq r0, #1856 1d0d3b03
tstmi r9, 108, 12 tst r9, #108, #12 6c061943
cmple sp, 236, 30 ec0f5df3 , condition 0xf , not an instruction ec0f5dd3
  • the immediate path ORed 0xe2 into the low byte . the 2 is the I bit , the e is the al condition , and it was ORed over the condition that was already there , so eq came out as al , and anything with the top bit , like le , as nv
  • values above 255 went to findyz , which did not set Rn and computed the rotation wrong . it had no other caller , so it is gone , and the value goes through getimmed8 , the same encoder mov uses , which refuses what has no 8 bit rotated form
  • the #imm8, #rot form keeps its own path , only checked to fit in 8 bits now , and a bad first register is refused instead of OR'd in as -1

found by decoding random words with llvm-mc ( -triple=armv7 ) , assembling the text with rasm2 -a arm -b 32 and decoding the result again . same as llvm went from 618 to 659 of 3459 : 22 that were wrong and 19 that findyz refused , nothing that was right changed . the 6 new lines in db/asm/arm_32 fail before the change . the new test in db/tools/rasm2 pins that a value with no encoding ( tst r0, 0x101 ) is refused , master refused it too but also logged Parameter 257 out of range (0-255) . db/asm has no failures .

the tests are added next to the other compare tests and not at the end of the files , so this does not conflict with #27137 or #27140 , which touch other parts of armass.c .

Copilot AI balanced review requested due to automatic review settings October 22, 2026 23:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@trufae
trufae merged commit 7abe192 into radareorg:master Oct 23, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants