.MODEL small 
	.STACK 100h		; defines a stack 100h (256) bytes long 
	.DATA 
	
String  DB "Hello World!",'$'	; variable declaration 
	.CODE 

Start:  mov dx,offset String	; point dx to the storage location for the first character
        mov ah,9		; dos function for string  output
        int 21h

Stop:   mov ax,4C00h		;exit dos 
           int 21h 
END Start

The output of this program is:

I♦K☺I♦V☺I♦I♦☺☺☺ ☻               <♣Φ ë♣¶ ↑ w♣        ♣               ═!╦
                                                 ║♀ ┤      ═!╕ L═!Hello World!

What am I missing here?Can anyone help me?

Put a colon : after the label string
String:

That seems to make matters worse.

hello.asm(5): error A2108: use of register assumed to ERROR
hello.asm(5): error A2008: syntax error : DB

I don't think "string" is a label here(it is a string variable) so there should not be any colon following it.

Edited 5 Years Ago by D33wakar: n/a

If you step through the original code with a debugger, what value is being used for DX when the string is to be printed?
Also, what is the first command shown in the debugger?

I will see if I can get masm or tasm and see what's going on with the .DATA

This works using the a86 compiler.

.MODEL small 
	.STACK 100h		; defines a stack 100h (256) bytes long 
	.DATA 
	.CODE 

Start:  mov dx,offset String	; point dx to the storage location for the first character
        mov ah,9		; dos function for string  output
        int 21h

Stop:   mov ax,4C00h		;exit dos 
           int 21h 
String  DB "Hello World!",'$'	; variable declaration 
END Start

Edited 5 Years Ago by thines01: clarity

I will see if I can get masm or tasm and see what's going on with the .DATA

This works using the a86 compiler.

.MODEL small 
	.STACK 100h		; defines a stack 100h (256) bytes long 
	.DATA 
	.CODE 

Start:  mov dx,offset String	; point dx to the storage location for the first character
        mov ah,9		; dos function for string  output
        int 21h

Stop:   mov ax,4C00h		;exit dos 
           int 21h 
String  DB "Hello World!",'$'	; variable declaration 
END Start

I'm using masm16 assembler.
Here's what the debug utility showed:

-u
0B80:0000 BA0C00        MOV     DX,000C
0B80:0003 B409          MOV     AH,09
0B80:0005 CD21          INT     21
0B80:0007 B8004C        MOV     AX,4C00
0B80:000A CD21          INT     21
0B80:000C 48            DEC     AX
0B80:000D 65            DB      65
0B80:000E 6C            DB      6C
0B80:000F 6C            DB      6C
0B80:0010 6F            DB      6F
0B80:0011 20576F        AND     [BX+6F],DL
0B80:0014 726C          JB      0082
0B80:0016 64            DB      64
0B80:0017 2124          AND     [SI],SP
0B80:0019 47            INC     DI
0B80:001A 182A          SBB     [BP+SI],CH
0B80:001C E4A9          IN      AL,A9
0B80:001E FD            STD
0B80:001F FF7404        PUSH    [SI+04]

The DX points to address 000C which contains the code DEC AX ,but I thought the string starts from addr 000D .
Then I dumped it which gave the following:

0B80:0000  BA 0C 00 B4 09 CD 21 B8-00 4C CD 21 48 65 6C 6C   ......!..L.!Hell
0B80:0010  6F 20 57 6F 72 6C 64 21-24 47 18 2A E4 A9 FD FF   o World!$G.*....

Here you can see the first character "H" in corresponds to the 48 in hex dump.
So what's the problem?

Your code should start at 100h instead of 0, right?
Is there a preprocessor directive to tell it to ORG 100h?

That hex(48) at offset 0C is the 'H' in the string, so that part is OK.

Your code should start at 100h instead of 0, right?
Is there a preprocessor directive to tell it to ORG 100h?

That hex(48) at offset 0C is the 'H' in the string, so that part is OK.

Did you mean to include ORG 100h in the .code segment?
Well, I did that but nothing much happened.
But the problem's soved now .I was missing

mov ax,@data
mov ds,ax     ;ds points to .data

Thanks anyways.

Edited 5 Years Ago by D33wakar: n/a

This article has been dead for over six months. Start a new discussion instead.