Post Reply 
(16C) Mask and Sign Extend
04-09-2019, 07:25 PM
Post: #3
RE: (16C) Mask and Sign Extend
Thanks for the hint, wynen! Here then is a shorter, simpler version of the original program. This is slightly different than the original in that you specify which bit is the sign bit rather than how many bits are in the offset. In both cases though, the offset is assumed to be in the lower bits of the instruction word.

Usage:
Enter the instruction followed by the bit number of the offset sign. 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.

Before:
Y - Instruction
X - bit # of the offset sign bit

After
X - Masked and sign extended offset

Example (PDP-11)
Set word size to 16, mode to Hex. The offset is the lower 8 bits of the instruction, so the sign bit would be bit 7.

BNE $+4 ; offset would be 3
Enter 0203h, 7h
Result is 3h

BEQ $-4 ; offset would be -5
Enter 03FBh, 7h
Result is FFFBh (-5)

Code:

001  LBL A        | 43 22 A      Mask & Sign Extend
002  MASKR        |    42 8      Bit # of ones
003  x<>y         |       34     X is instruction
004  LST X        |    43 36     Bit number of sign
005  B?           |    42 6      Sign bit high?
006  GTO 0        |    22 0      Yes
007  AND          |    42 20     Mask offset
008  RTN          |    43 21
009  LBL 0        | 43 22 0      Sign bit high
010  x<>y         |       34     Get mask
011  NOT          |    42 30     sign bit extended
012  OR           |    42 40
013  RTN          |    43 21

Remember kids, "In a democracy, you get the government you deserve."
Find all posts by this user
Quote this message in a reply
Post Reply 


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)