Post Reply 
(newRPL) Hex dump
10-29-2021, 09:33 PM
Post: #1
(newRPL) Hex dump
Curious about internal representation of newRPL objects but can't stand reading code?
Retroengineering is your hobby?

Here's a quick aid for your investigation, meet HEXDUMP: given an object it will return its size and the classic hex dump divided in 8 bytes chunks (a small font is advised).

E.g. 1_mm HEXDUMP

Code:

24
"00: 05 00 68 03 01 00 E0 00  ..h...à.
08: 01 00 08 02 6D 6D 00 00  ....mm..
10: 01 00 E0 00 01 00 E0 00  ..à...à."

Enjoy!

Code:

« → o
  « o BYTES SWAP DROP                                           @ Compute size
    DUP MKBINDATA                                               @ Create suitable BINDATA object
    0 o BINPUTOBJ                                               @ Store object in it
    'bin' LSTO
    'size' LSTO
    size LN 16 LN / CEIL 'dgt' LSTO                             @ How many hex digits is size?
    0 size 1 - FOR 'i'
      "00000000" #0h i + →STR TAIL RTAIL +                      @ Format the offset string: a field of
      DUP SIZE DUP dgt - 1 + SWAP SUB ":" +                     @ 'dgt' digits, rhs justified and trailed by ":"
      bin size i -                                              @ How many bytes remain? More than 8 or less?
      8 MIN                                                     @ i.e. necessarily 4, since newRPL objects are
      i SWAP BINGETB                                            @ word aligned. Take a chunk for the byte dump
      BINGETB                                                   @ and another one for the char dump
      IF DUP SIZE 8 - THEN                                      @ If 4 bytes remain, pad them with #0000h
        { #0h #0h #0h #0h } ADD
      END
      DUP 1 « →STR TAIL RTAIL "0" SWAP +                        @ Remove "#" and "h" from bytes,
              DUP SIZE DUP 1 - SWAP SUB                         @ pad them with "0"'s and add a leading space
              " " SWAP + » DOLIST
      "  " ADD                                                  @ Add some space
      SWAP 1 « IF DUP 32 < THEN DROP #2Eh END →UTF8 » DOLIST    @ Turn bytes into printable characters
      ADD ADD 10 →UTF8 ADD                                      @ Concatenate lists and add a new line
      ΣLIST                                                     @ Concatenate all strings
    8 STEP                                                      @ Next 8 bytes
    size 8 / CEIL →LIST ΣLIST RTAIL                             @ Concatenate all lines, trim last newline
    size SWAP                                                   @ Return original size and hexdump
  »
»
Find all posts by this user
Quote this message in a reply
11-02-2021, 02:27 PM
Post: #2
RE: (newRPL) Hex dump
This may very well be the first contribution in this library that works exclusively on newRPL!

Program is great, perhaps one suggestion:
How about 2 lines per 8 bytes? The first one as you have it, with individual bytes and text, and then immediately below just add another line showing the same 8 bytes but grouped in two 32-bit words. Because everything is word aligned, you'll never be wrong, and it's much easier for example to identify a prolog of an object by looking at the first word than looking at individual bytes.
Another suggestion: "smart" recognition of a real number prolog, then only for real numbers you can show the 32-bit words above in decimal instead of hex. It will nicely show all the digits of the number stored in memory, as well as the exponent.

Anyway, just some ideas, keep up the good work!
Find all posts by this user
Quote this message in a reply
11-02-2021, 09:14 PM
Post: #3
RE: (newRPL) Hex dump
(11-02-2021 02:27 PM)Claudio L. Wrote:  This may very well be the first contribution in this library that works exclusively on newRPL!

Actually the second... long ago I posted a small library which did a little trick with keyboard assignments and complex numbers

Quote:Program is great, perhaps one suggestion:
How about 2 lines per 8 bytes? The first one as you have it, with individual bytes and text, and then immediately below just add another line showing the same 8 bytes but grouped in two 32-bit words. Because everything is word aligned, you'll never be wrong, and it's much easier for example to identify a prolog of an object by looking at the first word than looking at individual bytes.
Another suggestion: "smart" recognition of a real number prolog, then only for real numbers you can show the 32-bit words above in decimal instead of hex. It will nicely show all the digits of the number stored in memory, as well as the exponent.

Anyway, just some ideas, keep up the good work!

Nice idea, I'll work on it!
Find all posts by this user
Quote this message in a reply
11-05-2021, 08:09 PM
Post: #4
RE: (newRPL) Hex dump
(11-02-2021 09:14 PM)JoJo1973 Wrote:  Actually the second... long ago I posted a small library which did a little trick with keyboard assignments and complex numbers

I stand corrected! Smile
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)