0

I want to create macro in FASM, which could directly print string (int DOS) like this:

prints 'hey there!!!!'

I have written such code:

format MZ

use16
stack 0x100
entry _TEXT@16:_start

;
macro prints str
{
    call @f
    db str, 0x24

    @@:
        pop dx
        mov ah, 9
        int 0x21
}

segment _DATA@16 use16
    msg db 'hi!', 0xd, 0xa, 0x24

segment _TEXT@16 use16
    _start:
        push _DATA@16
        pop ds

        prints 'hi there))) !!!!'
        prints 'me'

        mov ax, 0x4c00
        int 0x21
    ret

The problem is: when I leave my _DATA@16 segment empty (without any variables) all is fine. But when I define new variable in that segment some raw extra symbols begin to appear like this: http://board.flatassembler.net/files/err_758.png

So can you help me? where is my mistake? Maybe I have chosen the wrong way to achieve that thing I want? Help please....

deathmood
  • 113
  • 6

1 Answers1

2

As far as I understood it is because int 21h expects offset in _DATA@16 segment but not _CODE@16 segment. So, the easiest way - to use only one segment in program or just using .com files. Here is sample:

use16
org 0x100

macro prints [str*]
{
    pusha

    if str in <0xd, 0xa, 9>\
        | str eqtype ''

        call @f
        db str, 0x24

        @@:
            pop dx
    else
        mov dx, str
    end if

    mov ah, 9
    int 0x21

    popa
}

_start:
    prints 0xd, 0xa, 9
    prints 'hi!', 0xd, 0xa
    mov ax, msg
    prints ax, 0xd, 0xa
    prints msg

    int 0x20
ret

msg db 'hey there!', 0x24

It can accept strings directly, addresses of strings in registers and variables. It can also handle 3 special characters - 0xd (CR), 0xa (LF) and 9 (TAB).

If I find the way to display string directly in multi-segment programs, I will post the answer.

deathmood
  • 113
  • 6