kierenj / 0x10c-DevKit

0x10c DevKit
http://0x10c-devkit.com/
39 stars 4 forks source link

Instructions in which a is a label to a short literal still assemble to next word #148

Closed tom-kitchin closed 12 years ago

tom-kitchin commented 12 years ago

If a label is created for an address which is a short literal (so the first thirty addresses) and that label is then used as the a value in an instruction, the resulting assembled code uses the next word value and puts the short literal in the next word anyway.

e.g.,

; Beginning of code.  
SET PC, start  ; Instruction 'a' value is the start label
:start ADD A, 10  ; Doesn't matter what the instruction is, 
                  ; label 'start' should be address 0x0001 (or at least inarguably in the first thirty)

Becomes: 0x7F81, 0x0002, 0xAC02 (notice the 0x0002, the start label, in address 0x0001) But it should have become: 0x8B81, 0xAC02 (which uses the short literal form for the address in the 'a' value) Short literals are used fine if they are entered directly instead of using labels (e.g. "SET PC, 0x0001" works fine), it's just labels which don't seem to work out.

kierenj commented 12 years ago

Currently the short form literal is never used when dealing with labels. This is because to determine label positions, the size of instructions must be known. To know the size of opcodes with short-form literals, the labels must be known. This loop is possible to resolve, but hasn't been actioned just yet.

I'm implementing relative code now, which I believe most code will be compiled with, which means it's not possible to use short-form opcodes like that at all (since to be relative the extra word would be modified).

This may be re-visited later, but not currently (unless you can convince me it's crucial, I am easy to convince in that regard). I marked this as a bug because I thought you were referring to something else. So current status - may pick up in the future, but not yet, unless it proves to be crucial.

Thanks for the feedback ;)

tom-kitchin commented 12 years ago

Okay, fair enough. I only really noticed because I have a useful recursive value and the most commonly accessed subroutine in my code carefully placed in the first thirty addresses, and I'm not actually currently benefiting from doing that.

It's probably a pretty rare case in the end, since it only matters if you're using the actual address - the contents of the address is an extra cycle and word regardless. I suspect that'll usually only mean JSR and SET PC calls on stuff in the first thirty, which isn't too bad to handle manually. Probably not crucial, then, although it would be nice.

I appreciate the work on the IDE in general, by the way - the environment has been a real help, definitely the best one I've tried.