flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > self purging

Author
Thread Post new topic Reply to topic
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
How can I purge a macro after it's first use?

Code:
macro BootCode makeInstaller
{
local ..bootCode
    if 1

    macro ends
    \{
    end if
        if $ - 7c00h > 510
             display "Boot code exceeds 510 bytes"
             err
        end if

        rb 510 - ($ - 7c00h)
        dw 0aa55h
    \}

    struc IntHandler origin
    \{
    .:
    org origin
        if 1
        macro ends
        \\{
        end if

        org $ - origin + .

        purge ends
        \\}
    \}


match makeInstaller, any
\{
    match `makeInstaller, "makeInstaller"
    \\{
    org 100h
        mov     ax, 0301h
        mov     bx, ..bootCode
        mov     cx, 1
        xor     dx, dx
        int     13h

        jc      .writeError
        int     20h

    .writeError:
        mov     ah, 09h
        mov     dx, errorMsg
        int     21h
        xor     ax, ax
        int     16h
        int     20h

    errorMsg    db "Write error", "$"
    \\}
\}

..bootCode:
org 7c00h
}
    
Code:
BootCode

  int13 IntHandler

  ends ; Here it's used "ends" from IntHandler

ends ; Again it's used "ends" from IntHandler    


Another example
Code:
BootCode

  int13 IntHandler 0

  ends ; Here it's used "ends" from IntHandler
  purge ends

ends ; Illegal instruction!!
end if    
Post 18 Mar 2006, 14:06
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
The macro can be purged only from outside of itself.
Post 18 Mar 2006, 14:10
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Sad

OK, I will rename "ends" of "IntHandler" to "endi" then. Of course I wish to use "ends" always to be consistent on the macro name to end block though Sad

Thanks for the reply!!

Regards
Post 18 Mar 2006, 14:33
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
You can make commons "ends" macro that would call some other macro appropriately to what block is currently to close.
Post 18 Mar 2006, 14:48
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
And using some kind of currBlockType equate to track which type of block is it and which action to take and then restoring that equate after the action, right? I will try something around that and I will post it when it finished

Thanks again!!
Post 18 Mar 2006, 15:14
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.