DiztinGUIsh
DiztinGUIsh copied to clipboard
Feature request: mark a 16-bit operand as being an address
I'd like the ability to mark a 16 bit immediate value operand as being the bank or offset of a label, so that the source assembly code generated by Diztinguish would refer to the label instead of the immediate values.
Let me give an example. Here is a short excerpt of asm code as output by Diztinguish from an actual SNES ROM: LDA.W #$F714 LDX.W #$0006 STX.W $D3FE STA.W $D3FC
This code stores the ROM address 06F714 in a 32 bit variable located in WRAM at addresses $7ED3FC and $7ED3FE. In Diztinguish, I create a label named "MyData" at address 06F714, where the useful data is located.
Because #$F714 and #$0006 are immediate values, Diztinguish currently has no way to guess that these are actually two parts of an address. I would like a way to tell Diztinguish: LDA.W #$F714 "This operand is the offset of the label MyVar" LDX.W #$0006 "This operand is the bank of the label MyVar"
With this additional information (supplied manually by the reverse engineer), Diztinguish could generate improved assembly code looking like this: LDA.W #MyVar LDX.W #bank(MyVar) STX.W $D3FE STA.W $D3FC
The code above assembles correctly with asar. It is more readable and easily updated (moving the data to another location does not require updating the code as there are no more hard coded values).
In fact, this should not be limited to immediate value operands. In the following example (a call to the standard C function 'strcat'), the operand of the PEA instruction is an offset in bank 6. A text string is stored at address $06D372.
LDA.W #$0006 PHA PEA.W $D372 PEI.B ($F7) PEI.B ($F5) JSL.L strcat
I would be nice to get this output in the asm file (provided a label named 'MyString' is defined at address $06D372): LDA.W #bank(MyString) PHA PEA.W MyString PEI.B ($F7) PEI.B ($F5) JSL.L strcat
I'll read this in more depth, I think it's similar to the same idea behind #17 and #34, which is a lot of work to implement general label/expression support.
Yes this is similar to #34 (I don't understand #17 though). This does not look very hard to implement (but I'm not the expert here!). I would add an additional text column in Diz, called "Address hint" for example, where the user can manually input the information that Diz is missing to find the appropriate label. Diz needs to compute a full 24 bit address to find which label to put in the asm file (if any is defined at the computed address). Using the values from the example in my post above
- If the operand is 16 bits value #$0006 and represents a bank number, the user would input the missing offset in that bank, writing something like this in the "Address hint" column: offset(D372)
- If the operand is 16 bits value $D372 and represents an offset in a bank, the user would input the missing bank number, writing something like this in the "Address hint" column: bank(06)
When generating asm source code, Diz could then combine the operand value + address hint to get the full address, search for the corresponding label and use it if present (and just output the value as it currently does if no label is defined)
- If the operand is 8 bits the solution is described in #34 . In these case, Diz already has all the necessary information to compute the full 24 bit address (and it does so in the IA column), so finding the corresponding label is easy.