flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Single-liner subroutine caller macro

Author
Thread Post new topic Reply to topic
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie 05 Oct 2008, 06:22
Just a simple macro ("mcall") that enables labeled subroutines that expect up to four parameters in registers to be called in a single line. It will accept registers, quoted strings, values or memory references.
The example code is a complete program with example useage of some simple subroutines.

Code:
org 100h
 
macro mcall sub,arg1,arg2,arg3,arg4  
{
   local str

       if      arg1    eqtype ""                     ; quoted literal
            jmp     @F
          str     db      arg1,0,"$"
        @@:
             mov     eax,str
     else if arg1    eqtype 0 | arg1 eqtype eax      ; value or register      
           mov     eax,arg1
    else if arg1    eqtype [a]                      ; memory
            mov     eax,arg1
    end if

  if      arg2    eqtype ""                       
          jmp     @F
          str     db      arg2,0,"$"
        @@:
             mov     ebx,str
     else if arg2    eqtype 0 | arg2 eqtype eax    
              mov     ebx,arg2
    else if arg2    eqtype [a]
          mov     ebx,arg2
    end if

  if arg3 eqtype ""  
               jmp     @F
          str     db      arg3,0,"$"
        @@:
             mov     ecx,str
     else if arg3    eqtype 0 | arg3 eqtype eax 
         mov     ecx,arg3
    else if arg3    eqtype [a]
          mov     ecx,arg3
    end if

  if arg4 eqtype ""   
              jmp     @F
          str     db      arg4,0,"$"
        @@:
             mov     edx,str
     else if arg4    eqtype 0 | arg4 eqtype eax 
         mov             edx,arg4
    else if arg4    eqtype [a]
          mov     edx,arg4
    end if

  call sub
}

mcall szCopy,"Hello",temp
mcall  stdout,temp
mcall    stdout," World"
mov        ah,4ch
int   21h

temp db 20 dup(?)

szCopy: ; eax=source, ebx=dest
      mov     esi,eax
     mov     edi,ebx
     mov     edx,-1
 @@:
  inc     edx
 mov     al,byte[esi+edx]
    mov     byte[edi+edx],al
    cmp     al,0
        jne     @B
  mov     byte[edi+edx+1],0
   ret

stdout:  ; eax=source
        mov     esi,eax
     mov     edi,0
 @@:
   mov     al,byte[esi+edi]
    cmp     al,0
        je      @F
  mov     dl,al
       mov     ah,2
        int     21h
 inc     edi
 jmp     @B
 @@:       
       ret
    
Post 05 Oct 2008, 06:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20629
Location: In your JS exploiting you and your system
revolution 05 Oct 2008, 06:39
What happens if you have:
Code:
mcall somewhere,"one","two","three","four"    
can it be assembled without any error?
Post 05 Oct 2008, 06:39
View user's profile Send private message Visit poster's website Reply with quote
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie 05 Oct 2008, 09:12
Quote:
What happens if you have:
Code:
mcall somewhere,"one","two","three","four"



can it be assembled without any error?


In its present form it cannot assemble with multiple quoted strings because there will be a label duplication.
Post 05 Oct 2008, 09:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20629
Location: In your JS exploiting you and your system
revolution 05 Oct 2008, 09:20
Did you intend it to be like that? Is it a bug or a feature?
Post 05 Oct 2008, 09:20
View user's profile Send private message Visit poster's website Reply with quote
ChrisLeslie



Joined: 04 Jun 2006
Posts: 50
Location: Australia
ChrisLeslie 05 Oct 2008, 09:42
It is only like that because I had no need to have muliple quoted strings. Come to think of it, no examples of that ability to readily to mind. However, I have just tried using four unique local string labels and it appears to work fine.
Post 05 Oct 2008, 09:42
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.