What is possibly wrong with this code ?

data segment
    msg db "Enter a character: "
data ends

code segment
    assume cs:code , ds:data 
    mov dx,data
    mov ds,ax
    mov dx,offset msg
    mov ax,08h
    int 21h
    mov bx,ax
    mov ax,4c00h
    int 21h
code ends
end

766258137b1795d569beae9cd872b521

   mov dx,data
   mov ds,ax
   mov dx,offset msg

What are you trying to do here?
What do you think is in the ax when you replace the data segment register with it?

The error doesn't look like connected to that, but that can cause funny things.

You should just:

mov dx, msg ; the segment is already assumed to be data

Edited 3 Years Ago by turboscrew

@turboscrew: Sorry but I dont see your point.

PS: Am a beginner in assembly language for 8086. So pardon my silly mistakes.

Sorry id I "sounded" offensive. I was just probing your way of thinking.

As I said, just replace these:

   mov dx,data
   mov ds,ax
   mov dx,offset msg

with this:

    mov dx, msg

The " assume cs:code , ds:data" tells the assembler to use "code" as
the default code segment and "data" as the default data segment.

Would this work:

data segment
    msg db "Enter a character: "
data ends

code segment
assume cs:code , ds:data

_Start:
    mov dx,offset msg
    mov ax,08h
    int 21h
    mov bx,ax
    mov ax,4c00h
    int 21h
code ends
end _Start

I couldn't really try, because 16-bit linker would have been needed, and I assembled with MASM. I didn't find old TASM to try it.

BTW, why are you using 16-bit DOS assembly?
Course or some other compelling reason?

If possible I'd recommend MASM32 SDK (it has all you need).
http://www.masm32.com/

I was initially trying with MASM32 but it wasnt linking properly thats why I was trying with TASM.

I also asked query about linking in this article. But it was in vain.

Can you solve mentioned thread ?

MASM32 has 16-bit linker in /bin, but you need to run it manually, and I didn't have time to figure the switches out.

Also watch out for differencies in assemblers: MASM/TASM/NASM and GAS.
They don't "eat" the same syntax. With GAS even the mnemonics are different (AT&T syntax).

Can you tell me in simple steps how to assemble,link and execute . . . I have tried it several times but it is just assembling program and not creating its object file.

I will be very much thankful to you.

Is that all ?

Does program need to be in the same directory as masm32 ?

I compiled and linked, but couldn't execute.
(MASM32 editor: File/Cmd prompt)

C:\masm32>bin\ml /c test.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.

Assembling: test.asm

C:\masm32>bin\link16 test.obj

Microsoft (R) Segmented Executable Linker Version 5.60.339 Dec 5 1994
Copyright (C) Microsoft Corp 1984-1993. All rights reserved.

Run File [test.exe]:
List File [nul.map]:
Libraries [.lib]:
Definitions File [nul.def]:

Running test.exe opens a popup "Unsupported 16-Bit Application":

The program or feature "\??\C:\masm32\test.exe" cannot start or run due
to incompatibility with 64-bit versions of Windows. Please contact the
software vendor to ask if a 64-bit Windows compatible version is available.

But in dosbox it works:
[http://www.dosbox.com/download.php?main=1]

My code:

.model small
.stack 100

data segment
    msg db "Enter a character: $"
data ends
code segment
assume cs:code , ds:data
_Start:
    mov dx, data
    mov ds, dx
    mov dx, offset msg
    mov ah,09h
    int 21h
    mov bx,ax
    mov ah,4ch
    int 21h
code ends
end _Start

Edited 3 Years Ago by turboscrew

This question has already been answered. Start a new discussion instead.