(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." |
|||
04-09-2019, 09:38 AM
Post: #2
|
|||
|
|||
RE: (16C) Mask and Sign Extend
Just a hint:
The HP-16C has a nice feature to generate bit mask. Instead of the loop in your program (lines 002 -008) you could simply use Code:
Hartmut |
|||
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:
Remember kids, "In a democracy, you get the government you deserve." |
|||
04-12-2019, 08:33 PM
Post: #4
|
|||
|
|||
RE: (16C) Mask and Sign Extend
Sorry if this is off-topic, but are you debugging PDP-11 assembly language?
|
|||
04-13-2019, 02:32 AM
Post: #5
|
|||
|
|||
RE: (16C) Mask and Sign Extend
I spent a couple of years as a graduate student programming in PDP-11 assembly and teaching an undergraduate lab in the same. Afterwards, spent a few years with 680x0 assembly. Having recently built a PiDP-11 I'm considering getting back into RT-11/RSX-11 programming. It would probably take all of five minutes to refresh my memory of the instruction set
The program could just as easily be used with other CPUs including the 41 Nut branch instructions... ~Mark Remember kids, "In a democracy, you get the government you deserve." |
|||
04-16-2019, 01:56 AM
Post: #6
|
|||
|
|||
RE: (16C) Mask and Sign Extend
I keep going back looking at the PiDP-11, but while it is cool I have never used one and struggle to find motivate myself why I really need it. But I keep going back, looking and checking the forum about it.
While it is cool to look at and playing with the root of UNIX, any modern Linux or *BSD is probably a better choice for fun and they are easily found and dirt cheap today. If I played with the another OS on it like RT-11 it would be different. Still, I found this interesting book (Lions' Commentary on UNIX 6th Edition, with Source Code) that I never heard of before while pondering over this: http://www.lemis.com/grog/Documentation/Lions/ It was "new" to me, so maybe it is new to others too? There is a PiDP-10 in the works it seems, I have used those back in the days, but still... and the PDP-11 is way cooler looking and more historically significant. In the end I always come down to not buying the PiDP-11. The little time I can spare is probably better to do with the HP-41 and AROS. Besides, I can always play with simh for a start on the RPi and that Lion's book interests me. It is always good to see HP-16C programs, they are far between unfortunately. I could not resist making my version of it with Ladybug, but that is HP-41 so it is off-topic here. Maybe I post it later elsewhere. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)