Also here's a nice 16bit addition subroutine:
The dataloop that DIO 2 uses has context switchable registers from addresses 100 to 111
As illustrated above, you could use the context switch to hold two bytes of related information at the same address. Depending on how you use your registers in your program, you can theoretically hold 4 8-bit numbers and 4 16-bit numbers in the dataloop.
I will probably have a separate instruction to perform a context switch on the regSelect addresses. Doing this would allow passing arguments as two sets of register addresses to the dataloop and this opens a LOT of possibilities!
Actually I found another way to do the 16bit addition function. The above method is more linear, but the below method is a bit faster if there is no ripple between the two bytes:
the penalty for a true 16bit addition is much higher, but if there is no ripple between the two bytes it is considerably faster.
It's a bit odd though as I add the top byte before the bottom byte xD
I will talk about the contextSet instruction in more detail later. I will also describe how the interrupt instructions will be used. I am heading off to London in like an hour and need to pack though, so I gotta go! :O
Code:
disableInterrupts
regSel r100 r101
add r111
branchIf Cout $enableCin
contextSet c100
add r111
jump $endFunc
#enableCin
contextSet c100
addC r111
#endFunc
contextSet c000
enableInterrupts
return
The dataloop that DIO 2 uses has context switchable registers from addresses 100 to 111
As illustrated above, you could use the context switch to hold two bytes of related information at the same address. Depending on how you use your registers in your program, you can theoretically hold 4 8-bit numbers and 4 16-bit numbers in the dataloop.
I will probably have a separate instruction to perform a context switch on the regSelect addresses. Doing this would allow passing arguments as two sets of register addresses to the dataloop and this opens a LOT of possibilities!
Actually I found another way to do the 16bit addition function. The above method is more linear, but the below method is a bit faster if there is no ripple between the two bytes:
Code:
disableInterrupts
regSel r100 r101
contextSet c100
add r111
contextSet c000
add r111
branchIfNot Cout $endFunc
contextSet c100
addC r111
contextSet c000
#endFunc
enableInterrupts
return
It's a bit odd though as I add the top byte before the bottom byte xD
I will talk about the contextSet instruction in more detail later. I will also describe how the interrupt instructions will be used. I am heading off to London in like an hour and need to pack though, so I gotta go! :O