(16C) Mask and Sign Extend
|
03-26-2019, 11:48 PM
Post: #1
|
|||
|
|||
(16C) Mask and Sign Extend
Here's a nice little program to handle instruction sets that have a signed offset in the lower bits of an instruction. Suppose you're working with a disassembly listing and need to mask the offset in a branch instruction and then add it to the program counter value. You'll need to sign extend the offset first if it happens to be negative.
A good example would be the PDP-11 branch instructions. The high eight bits of the instruction encode the branch type while the lower eight bits are a signed offset that gets multiplied by two and added to the PC for the target address. The PC has been incremented by the time the offset is added to form the new PC value. Usage: Enter the instruction followed by the number of bits in the offset. Press GSB A. The signed offset will be in X. You can now use the signed offset and incremented program counter value to calculate the target address of the branch instruction. Don't forget to Shift Left the offset first! Before: Y - Instruction X - # of bits in offset After X - Masked and sign extended offset Example (PDP-11) Set word size to 16, mode to Hex. BNE $+4 ; offset would be 3 Enter 0203h, 8h Result is 3h BEQ $-4 ; offset would be -5 Enter 03FBh, 8h Result is FFFBh (-5) Code:
Remember kids, "In a democracy, you get the government you deserve." |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(16C) Mask and Sign Extend - mfleming - 03-26-2019 11:48 PM
RE: (16C) Mask and Sign Extend - wynen - 04-09-2019, 09:38 AM
RE: (16C) Mask and Sign Extend - mfleming - 04-09-2019, 07:25 PM
RE: (16C) Mask and Sign Extend - hth - 04-12-2019, 08:33 PM
RE: (16C) Mask and Sign Extend - mfleming - 04-13-2019, 02:32 AM
RE: (16C) Mask and Sign Extend - hth - 04-16-2019, 01:56 AM
|
User(s) browsing this thread: 1 Guest(s)