ngahu daniel
ngahu daniel

Reputation: 69

Using assembly language to print string variables

This might sound common to many. I just need help declaring and printing string in assembly language Using visual studio. Am just trying out some assembly code, and while I can work on many mathematic based stuffs. Am not able to handle String related function.

Am trying to run some code which I found online on the same. BUt its showing some errors. Am using visual studio visualc++ 2013

main proc
 MOV AX, @DATA                ; initialize DS
 MOV DS, AX

 LEA DX, STRING_1             ; load & display the STRING_1  
 MOV AH, 9            
 INT 21H

Error 1 error A2004: symbol type conflict .asm 11 1 Project

Upvotes: 1

Views: 1036

Answers (1)

Martin Rosenau
Martin Rosenau

Reputation: 18493

Am using Visual Studio Visual C++ 2013

... which probably means that you are creating a 32-bit or 64-bit Windows program.

However, the code you have posted is obviously 16-bit code. Normally, you cannot mix 16-bit, 32-bit and 64-bit code.

The users "prl" and "rkhb" left two comments:

In Windows you can’t use DOS or BIOS software interrupts ...
...
to be exact: some versions of Windows

In 16-bit Windows programs you used a combination of functions in .DLL files and BIOS and MS-DOS interrupts the same time. The function AH=3Eh of INT 21h was used to close a file handle.

However, in 32- and 64-bit Windows programs using the INT instruction was never allowed. Instead, the .DLL files contained all necessary functions (e.g. CloseHandle, which replaced AH=3Eh, INT 21h in 32- and 64-bit programs).

And 16-bit Windows programs never had access to the console, so function AH=9 of INT 21h would not work in a 16-bit Windows program, but only in an MS-DOS program.

Am just trying out some assembly code, and while I can work on many mathematic based stuffs.

And what do you want to do?

  • Use assembly code in a 32- or 64-bit program for performance reasons?

    In this case you should learn the differences between 16-, 32- and 64-bit x86 assembler and write your program in 32- or 64-bit assembly. You cannot call the operating system functions (e.g. string output) "directly" but you have to call functions from .DLL files (which is simply done using the CALL instruction).

  • Learn 16-bit x86 assembly?

    In this case you will need a 16-bit compiler and a 16-bit assembler creating MS-DOS programs (so Visual Studio 2013 will get you nowhere). And if your computer runs Windows 7 or newer, you will need some MS-DOS emulator or a virtual machine running some DOS operating system because recent Windows versions do not support running DOS programs.

Upvotes: 1

Related Questions