hlorenzi / customasm

💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
Apache License 2.0
720 stars 56 forks source link

Using two banks #83

Closed rolf-electronics closed 3 years ago

rolf-electronics commented 3 years ago

Hi, I am trying to use two banks with customasm. I use it for my 8 bit breadboard computer, https://github.com/rolf-electronics/The-8-bit-SAP-3.

I use the following code:

bankdef bank1

{ #addr 0x8500, #size 0xff, #outp 0x0 }

bankdef bank2

{ #addr 0x8600, #size 0xff, #outp 0x0 }

include "8bit_cpu.def"

bank bank1

jmp section2

bank bank2

section2: mov# a, 0 mov# b, 1 loop: add b out a jmp loop

So pritty straightforward, when I run the assembler I get the error message: error: output regionoverlaps with bank1.

I do not see what I am doing wrong, each bank is 0xff bytes.

Hopefully, you can help me out, thanks in advance

pol-rivero commented 3 years ago

The #outp directive indicates the position (in bits, not bytes) on the output file where the assembled data should be written. If you want the contents of the output file to be bank1 followed by bank2, then you should do:

#bankdef bank1
{ #addr 0x8500, #size 0xff, #outp 0x0 }

#bankdef bank2
{ #addr 0x8600, #size 0xff, #outp 0xff * 8 }

Edit: Are you sure that the size of your banks isn't 0x100 instead of 0xff?

rolf-electronics commented 3 years ago

Thanks for the quick reply, it now works. I now realize that each page is 256 bytes, which codes as 0x100. The maximum adress in the page is 0xff. What I don't understand is why #outp 0xff * 8 needs to be this value. I had expexted that bank1 starts at 0x8500 and is size 0x100, which then defines the exact location of the bank.

pol-rivero commented 3 years ago

#addr and #outp do completely different things: #addr is the pc value at the start of the bank and #outp is the physical location in your output file where customasm should write the result. Since bank1 is 0x100*8 bits long, you need to start writing bank2 at location #outp 0x100 * 8. I originally used #outp 0xff * 8 since that's the #size you used, but the correct value is 0x100 instead of 0xff.

rolf-electronics commented 3 years ago

Thanks for the quick reply, this is fun to use to program these self build breadboard computers.