Hold_My_Anger
Hold_My_Anger

Reputation: 1015

printing in assembly programming using FASM

I am trying to print a message by using the code below:

org 100h
start:
    jmp begin

begin:
    mov ah, 9
    mov dx, msg
    msg db 'Ascii sign:.$'
    int 21h

finish:
    mov ax, 4c00h
    int 21h

It is able to compile but it display nothing at all. But if I move the line "msg db 'Ascii sign:.$'" below "jmp begin", the message is able to display.

I want to know the logic behind this. Does that make a difference where I declare the message ?

This is just out of curiosity, thank you!

Upvotes: 0

Views: 944

Answers (2)

Gunner
Gunner

Reputation: 5884

If you really must have your strings in the code section, then just jump over them.

begin:
    mov ah, 9
    mov dx, msg
    jmp overstring
    msg db 'Ascii sign:.$'
overstring:
    int 21h

finish:
    mov ax, 4c00h
    int 21h

Upvotes: 2

Jerry Coffin
Jerry Coffin

Reputation: 490118

Yes. Right now, msg is defined in the middle of the code, where the CPU will attempt to execute it. You normally want to define data separately, in the data segment. I don't remember the syntax for FASM, but with MASM or TASM, you'd normally do something like this:

.model small
.data

msg db 'ASCII sign: .$'

.code
main proc
     mov ah, 9
     mov dx, offset msg
     int 21h
     mov ax, 4c00h
     int 21h
main endp
     end main

Upvotes: 4

Related Questions