PASM reconstruction
Bocephus
Posts: 58
As a learning exercise, I have started coding a program to read a binary file and separate the various bit fields with the purpose of reconstructing my PASM code from the binary source. Currently all code is PASM except a cognew from spin to run the code. It appears that two of the longs represent my cognew but I'm unsure and would like verification or correction. Also, if anyone knows the significance or meaning of each byte within these longs please explain. Here is a snip of the output. The COG_INIT and COG_NEW are the lines in question.
ADDR HEX ZCRI CON INST DEST SRC EFFECT LONG# ========================================================================================= 0064 23 52 BC F8 0010 ---- WAITCNT 0029 0023 -- 0013 0068 13 54 FC E4 0011 ---- DJNZ 002A #0013 -- 0014 006C 08 00 7C 5C 0001 ---- JMP 0000 #0008 NR 0015 0070 01 4C FC 2C 0011 ---- SHL 0026 #0001 -- 0016 0074 20 50 FC A0 0011 ---- MOV 0028 #0020 -- 0017 0078 01 48 FC 2C 0011 ---- SHL 0024 #0001 -- 0018 007C 25 4C BC E1 0110 ---- CMPSUB 0026 0025 WC 0019 0080 01 48 F0 80 0011 IF_C ADD 0024 #0001 -- 001A 0084 01 4C FC 2C 0011 ---- SHL 0026 #0001 -- 001B 0088 18 50 FC E4 0011 ---- DJNZ 0028 #0018 -- 001C 008C 00 00 7C 5C 0001 ---- JMP 0000 #0000 NR 001D 0090 04 00 00 10 0000 DAT_VAR DAT_0 LONG 10000004 001E 0094 10 00 00 00 0000 DAT_VAR DAT_1 LONG 00000010 001F 0098 20 00 00 00 0000 DAT_VAR DAT_2 LONG 00000020 0020 009C 00 00 FF 00 0011 DAT_VAR DAT_3 LONG 00FF0000 0021 00A0 00 00 00 01 0100 DAT_VAR DAT_4 LONG 01000000 0022 00A4 00 7D 00 00 0000 DAT_VAR DAT_5 LONG 00007D00 0023 00A8 00 00 00 00 0000 DAT_VAR DAT_6 LONG 00000000 0024 00AC 00 B4 C4 04 0011 DAT_VAR DAT_7 LONG 04C4B400 0025 00B0 70 94 00 00 0000 DAT_VAR DAT_8 LONG 00009470 0026 00B4 34 C7 08 35 0100 COG_INIT COG_INIT LONG 3508C734 SP06 00B8 2C 32 00 00 0000 COG_NEW COG_NEW LONG 0000322C SP07 00BC 00 00 00 00 ---- ---- VAR_0 RES 1 -- 0027 00C0 00 00 00 00 ---- ---- VAR_1 RES 1 -- 0028 00C4 00 00 00 00 ---- ---- VAR_2 RES 1 -- 0029 00C8 00 00 00 00 ---- ---- VAR_3 RES 1 -- 002A
Comments
The object offset for your PASM program is 8, even though your PASM program is at the beginning of the DAT area. This is because the method table is in the first 8 bytes of your object. The parameter of -1 for coginit says that it should use the next available cog (i.e. cognew).
Dave
Dave
The attached file lists the Spin bytecode mnemonics with some descriptions. I need to work more on this document. The memory mnemonics have the following format:
{ld, st, la, ex}{l, m, w, b}{l, v, o, a, i}{c, x, 0, 1, m1}
Each field has the following meanings:
{ld, st, la, ex} - Load, Store, Load Address, Execute
{l, m, w, b} - Long, Medium, Word, Byte (Medium is 3 bytes)
{l, v, o, a, i} - Local offset, Var offset, Object offset, Absolute address, Immediate
{c, x, 0, 1, m1} - Compact, Indexed, zero, one, minus one
The third variable on a the stack would be loaded with "ldllc 12" or "ldll 12" The ldllc generates a one-byte code and the ldll generates two bytes. An indexed byte in the DAT area would be stored with "stbox $111".
The "ex" memory instruction perform an additional operation on a memory location, and can optionally load the result onto the stack. The additional instruction is one of the 32 math operations or it could pre or post decrement or increment, sign extension or the random function. An example of an ex instruction would be "exllc 12 preinc load", which would increment stack variable number 3 and load the result on the stack.
Dave
Your mnemonics format seems logical, and I appreciate the explanation along with the opcodes text.
After searching the forum for some time, I see I am well behind the curve, but I think the fog is slowly lifting.