• How to: instruction only available for subset of regs

    From erwin.matthijssen@gmail.com@21:1/5 to All on Sun Mar 12 03:22:36 2017
    Hi,

    I am retargeting LCC for a hobby cpu with 8 registers. I am stuck on the following:

    I have an instruction 'ldw reg1, offset(reg2)' that loads a memory word located at reg2+offset into reg1. However, this instruction can only target a subset of registers. It cannot for example target reg5.

    The thing I can't figure out is how to tell LCC that this instruction can only be used for certain regs (reg1 to reg4 in my case). And that it should use another instruction in all other cases: ldw tgt (base, index) can target any register.

    Any insight on how to achieve this would be greatly appreciated.
    Erwin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From bill rowe@21:1/5 to erwin.ma...@gmail.com on Sun Mar 12 05:09:44 2017
    Probably use the range syntax. For example to handle small constants specially you often see something like:
    consm: CNSTU2 "%a" range (a,1,4)
    reg: ADDU2(reg,consm) "?\tcpy2 R%c,R%0\n\tincm R%c,%1\n" 1

    or maybe the range qualification could go right on the instruction definition. Alternatively emit a macro and let the assembler choose the addressing mode.

    Could you just ignore this for now and only use regs 1-4 for your gprs? use 5-8 for things where you directly control the instructions - parameters, return values, program counter etc.


    On Sunday, March 12, 2017 at 6:22:36 AM UTC-4, erwin.ma...@gmail.com wrote:
    Hi,

    I am retargeting LCC for a hobby cpu with 8 registers. I am stuck on the following:

    I have an instruction 'ldw reg1, offset(reg2)' that loads a memory word located at reg2+offset into reg1. However, this instruction can only target a subset of registers. It cannot for example target reg5.

    The thing I can't figure out is how to tell LCC that this instruction can only be used for certain regs (reg1 to reg4 in my case). And that it should use another instruction in all other cases: ldw tgt (base, index) can target any register.

    Any insight on how to achieve this would be greatly appreciated.
    Erwin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)