flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro and access of data

Author
Thread Post new topic Reply to topic
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 17 Mar 2012, 15:19
I need some help for following task with FASM Z80 version (used for ZX81 developments)

I try to integrate BASIC commands/structures to mix BASIC and ASM code.
Normally the ZX81 does understand only BASIC but one trick to let ASM code run on it would be to put the code after a REM statement. Now I use following structure:

Code:
  REM 10,0,0,'Some text to identify program'
  REM 20,asm_start,asm_end
asm_start:
  LD BC,$1234
  RET
asm_end:
  REM 30,0,0,'any following statement'
    


Just an example. The number is the line number of the BASIC statement and the code to add. I created a macro with name REM which does following:

Code:
macro REM line,start,ed,val
  {
  local .x,.length
             db      line shr 8      ; line number of REM statement
              db      line and $FF   ; line number of REM statement
          if val eq
                dw      ed-start+2     ; lenght of line
             db      $EA             ; REM statement (token code)
           else
             db      .length+2
           db      $EA             ; REM statement (token code)
  .x            db      val
  .length = $-.x
             db      NEWLINE
        end if
  }
    


This structure works but the first example looked not very nice if you have several ASM code blocks which appear within the BASIC program.

So is there any possibility to just use the simple line with the macro
REM <lineno.>,asm_start,asm_end
do some more following BASIC statements (macros) and to define the ASM code somewhere else (maybe after all BASIC code or a separate file, i am not sure, at the end of the BASIC file would be okay) ?

I thought about using virtual which would work for the length calculation of the ASM code sequence but does not transfer the code at the memory location needed (directly after the db $EA if val/text is not passed to macro). Okay have to put correct ORG values too but I think this could be resolved with FASM in some more passes. Shocked

Thanks for help.
Post 17 Mar 2012, 15:19
View user's profile Send private message Send e-mail Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 17 Mar 2012, 21:16
Not sure I understand this fully but it looks like there's a few things you can do:

- Define macros containing the asm before the code and provide the macro name as a parameter, which then gets used in "val"

- Use something like "file `val" to include an external file containing the asm

- Use a list/table of locations to load/store code between locations (you can load from a virtual address space and store in actual address space)

Hope that helpful Question
Post 17 Mar 2012, 21:16
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 18 Mar 2012, 18:47
cod3b453 wrote:
Not sure I understand this fully but it looks like there's a few things you can do:

- Define macros containing the asm before the code and provide the macro name as a parameter, which then gets used in "val"

- Use something like "file `val" to include an external file containing the asm

- Use a list/table of locations to load/store code between locations (you can load from a virtual address space and store in actual address space)

Hope that helpful Question


I think you did understand right.
Exactly I want to define the code at the end of the program but put in the output file somewhere in the beginning or middle of other data. That's why I thought about "virtual" which I did use before.

Your last proposal sounds very good to me.
"Use a list/table of locations to load/store code between locations (you can load from a virtual address space and store in actual address space) "

Can you or anybody else provide a simple example of that technique ?
I think this is exactly what I want.
Does it work with ORG statement ? So give an ORG to virtual adress space ?

I don't like to separate the code to other files. Maybe optional but could be solved by includes. In general you have in many cases only a few basic lines to invoke the code and the rest of the file would be ASM code.
Post 18 Mar 2012, 18:47
View user's profile Send private message Send e-mail Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 19 Mar 2012, 18:13
OK I tried using the list example from the FASM manual but that didn't work Sad seems that a constructed list can't be used to feed macro parameters the way I thought.

Here's an idea of what I meant for the first version:
Code:
macro REM line,val
  { 
  local .x,.length,.len
                db      line shr 8      ; line number of REM statement 
                db      line and $FF    ; line number of REM statement
           if val eq
                virtual at 0
                        _asm_#line
                        .len = $
                end virtual
                dw      .len+2      ; lenght of line
                db      $EA             ; REM statement (token code)
                _asm_#line
           else 
                db      .length+2 
                db      $EA             ; REM statement (token code) 
  .x            db      val 
  .length = $-.x 
                db      NEWLINE 
           end if 
  }

macro _asm_20
{
  LD BC,$1234
  RET
}

REM 10,'Some text to identify program'
REM 20,
REM 30,'any following statement    
Post 19 Mar 2012, 18:13
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 19 Mar 2012, 23:09
cod3b453 wrote:

Here's an idea of what I meant for the first version:
Code:
macro REM line,val
  { 
  local .x,.length,.len
                db      line shr 8      ; line number of REM statement 
                db      line and $FF    ; line number of REM statement
           if val eq
                virtual at 0
                        _asm_#line
                        .len = $
                end virtual
                dw      .len+2      ; lenght of line
                db      $EA             ; REM statement (token code)
                _asm_#line
           else 
                db      .length+2 
                db      $EA             ; REM statement (token code) 
  .x            db      val 
  .length = $-.x 
                db      NEWLINE 
           end if 
  }

macro _asm_20
{
  LD BC,$1234
  RET
}

REM 10,'Some text to identify program'
REM 20,
REM 30,'any following statement    


Thanks, look good but didn't you miss something ?
How to get _ams_20 into the first macro ?
Maybe put the "call" in line 20 ?
Shocked
Post 19 Mar 2012, 23:09
View user's profile Send private message Send e-mail Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 19 Mar 2012, 23:26
In this case leaving the second parameter blank automatically tries to use macro "_asm_#line" -> _asm_20. You can add another parameter to do the same thing:
Code:
macro REM line,val,str
  {  
  local .x,.length,.len 
                db      line shr 8      ; line number of REM statement  
                db      line and $FF    ; line number of REM statement 
           if str eq
                virtual at 0 
                        val
                        .len = $ 
                end virtual 
                dw      .len+2      ; lenght of line 
                db      $EA             ; REM statement (token code) 
                val
           else  
                db      .length+2  
                db      $EA             ; REM statement (token code)  
  .x            db      str
  .length = $-.x  
                db      NEWLINE  
           end if  
  } 

macro _asm_20 
{ 
  LD BC,$1234 
  RET 
} 

REM 10,,'Some text to identify program'
REM 20,_asm_20
REM 30,,'any following statement'    
Question
Post 19 Mar 2012, 23:26
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.