flat assembler
Message board for the users of flat assembler.

Index > DOS > Problem with int 21 (write string)

Author
Thread Post new topic Reply to topic
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen 13 Aug 2006, 01:56
Hello, I'm trying to print a message in the screen but I can't get it work, this is my code:

format MZ
use16

jmp main

msg: db 'Hello World!$'

main:
mov ah, 09h
lea dx, ptr msg
int 21h

; the exit fuction [4C+no error (00)]
mov ax, 4C00h
int 21h

I'm not sure if I passing correctly the string in DS:DX.

Thanks in advance.
Post 13 Aug 2006, 01:56
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 13 Aug 2006, 02:18
You set up the DX correctly (though more usual syntax is "lea dx,[msg]"), but you have not set the DS. In this case you don't define a dedicated segment for data, so DS should be the same as CS - try putting this immediately after "main" label:
Code:
push cs
pop ds    

It will set up DS=CS.
Post 13 Aug 2006, 02:18
View user's profile Send private message Visit poster's website Reply with quote
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen 13 Aug 2006, 02:58
Thank you very much Tomasz and yes, you right, DS=CS.
I've tried to dedicate a data segment using .DATA but I got an error, how can I do it ?
Post 13 Aug 2006, 02:58
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 13 Aug 2006, 08:36
See the MULTISEG example in the DOS package.
Post 13 Aug 2006, 08:36
View user's profile Send private message Visit poster's website Reply with quote
fafastrungen



Joined: 12 Aug 2006
Posts: 27
fafastrungen 13 Aug 2006, 13:42
Tomasz Grysztar wrote:
See the MULTISEG example in the DOS package.


Thanks again man.
Post 13 Aug 2006, 13:42
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2 12 Oct 2006, 07:50
I don't really know much about this?

Why not do this?

Code:
use16
org 256

mov ah, 09h 
mov dx,msg
int 21h 

int 20h 
msg: db 'Hello World!$' 
    


Is there some strange reason for adding format MZ? I think you're
trying to make an EXE. When I assembled that original code,it gave
me problems. It seems making DOS COM files is easier and
they are smaller.
Post 12 Oct 2006, 07:50
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.