Being able to examine compiled code can help in identifying obscure bugs and gaining a deeper understanding of how things work. For this a decompiler is rather useful.
This can be useful, but the output doesn't help a lot. Consider an example:
5162 2049
5163 4593
5164 1
5165 4
5166 1
5167 5173
5168 7
5169 2049
5170 4634
5171 2049
5172 4352
5173 10
The left column is the offset, the right is the stored value.
It'd be much more useful to map the stored values to instruction names. This is complicated by the fact that Nga allows for packing up to four instructions per cell. To decompile effectively we need a way to unpack them.
````
{{
:mask #255 and ;
:next #8 shift ;
:reorder (abcd-dcba)
rot push rot push swap pop pop swap ;
---reveal---
:unpack (n-dcba)
dup mask swap next
dup mask swap next
dup mask swap next
reorder ;
}}
````
With this I can then proceed to write a quick and dirty function that maps opcodes to a symbolic short name. As with the *Naje* assembler, I use two characters for each (this is sufficient to identify all of the Nga instructions).
The NOP instruction is represented by two periods (I do this for readability purposes). Unrecognized values are rendered as two question marks.