0

I’m writing a C-SKY (CK803S) processor module for IDA Pro, and a question arose about offsets in transitions, small ones are fine, but long ones lead to nowhere, from the documentation: enter image description here

in code I implemented it like this:insn.Op1.addr = insn.ea + (((code32 & 0x3FFFFFF) << 1) & 0x3FFFFFF);

enter image description here

but I don’t understand what sign_extend does ?

1 Answer 1

0

Signextend is expanding an integer of some size into a larger size and filling the extra bits with the original sign bit. In other words - keeping the larger int positive/negative.

Example:

An original 8-bit number 0x7F (Binary 01111111) signextended to 32 bit becomes 0x0000007F.

An original 8-bit number 0x80 (Binary 10000000) signextended to 32 bit becomes 0xFFFFFF80

It makes sense using this operation in offsets as a relative offset can be negative.

2
  • that is, if 26 bits are 0, then we set bits 31..26 to 0, otherwise to 1? or force set to 1 - sign_extend, to 0 - zero_extend?
    – Andynvkz
    Commented Mar 7 at 7:25
  • If the most significant bit is 1 - all additional higher bits are set to 1. Otherwise - 0. signed, (int8) 0xFF equals to decimal-1. To keep the value in 32 bit they have to be all 1s, i.e. 0xFFFFFFFF
    – Yotamz
    Commented Mar 7 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.