Search code examples
assemblypdp-11

riddle - replace 4 strokes of code in equivalent 2


tst r0
blt label
cmp r0, #11
bgt label

As I understand this peace of code is a brench if r0 < 0 or r0 > 11.

How can I optimize it to only 2 strokes of code.


Solution

  • Try unsigned comparison:

    cmp r0, #11
    bhi label
    

    Values below 0 are represented using two's complement. So, -1 represented as a 16-bit unsigned value is 1111111111111111, which is higher than 11 (which is 0000000000001011).