I have been playing with my DM16C and finding it useful. Often I am working with data formats that encode values in bit fields with odd numbers of bits. For example, MPEG 2 transport streams are used for sending video over satellites. I can look at a hex dump of a stream but there are fields that don't line up with the hex digits. The DM16C is useful for this.
My program lets me type in the hex digits and pull out individual fields to registers, or else plug in the values and see the resulting hex.
I'll put the raw mnemonics below so that you can paste them into http://www.swissmicros.com/nut_decoder/ but for the full explanation and commented code see https://github.com/RobFisher/hp_calcula ... encode.txt
Aside: What I find quite fun about the 16C is manipulating the stack so as to avoid using registers for intermediate values. It might make the code harder to understand, though. At some point I might see if I can document a toolkit of stack manipulations.
Anyway, briefly, to use this you program in the sizes of the fields in bits into registers .1 to .F, using 0 to indicate there are no more fields. The values for the fields are (left to right) read from or written to registers 1 to F. You can GSB A to parse X into fields stored in the registers, or GSB E to encode the fields in the registers and store them in X.
To read an MPEG2 transport packet header, set the word length to 32
and the complement to unsigned. Store the number of bits in each
field in registers as follows:
.1 = 8 (for the sync byte)
.2 = 1 (for the transport error indicator)
.3 = 1 (for the payload unit start indicator)
.4 = 1 (for the transport priority)
.5 = 13 (for the PID)
.6 = 2 (for the transport scrambling control)
.7 = 2 (for the adaptaion field control)
.8 = 4 (for the continuity counter)
.9 = 0 to indicate that there are no more fields.
Set the window size to 32 bits by pressing DEC 32 [f] WSIZE.
Store the transport stream header in X, e.g. 47ABCDEF h
Run the program with GSB A
When it terminates, the sync byte (0x47) will be stored in register 1,
the transport error indicator in register 2, and so on.
You can convert the other way with GSB E. It's quite handy to parse the field values, change one of the fields by changing a register, then re-encode.
Here is the program for pasting, but see the above link for a readable version:
Code: Select all
LBL A HEX 0 STO I Rv LBL B x<>I 11 + x<>I RCL (i) x=0 RTN x<>I 10 - x<>I GSB F STO (i) Rv GTO B LBL F x<>y ENTER ENTER R^ RLn LST X x<>y ENTER Rv x<>y MASKR AND x<>y Rv RTN LBL E HEX 11 STO I 0 LBL C RCL (i) x<>y ENTER ENTER R^ MASKR ENTER LST X x<>I 10 - x<>I x<>y RCL (i) AND R^ OR x<>I 11 + x<>I RCL (i) x=0 GTO D RLn GTO C LBL D Rv RTN