Ayesha
Ayesha

Reputation: 39

MASM Commands - Problems on DOSBox

I am new on this forum and wanted some assistance on MASM programming. Currently I am learning MASM from my course instructor and he has told us to use MASM 6.15 (works easily for other Windows versions but not for Windows 7 & 8) for compiling our programs. I use Windows 8, so I was not able to compile those programs. So I came across a site that said to use a DOSBox emulator to use MASM on Windows 8! I have installed it and have done all the required tasks to make it work properly but I am still not able to compile my MASM program on DOSBox! When I try to compile, it gives the error that this program cannot be run in DOS made. Any assistance would be really appreciated!

I got MASM from this link: http://www2.hawaii.edu/~pager/312/masm%20615%20downloading.htm

...and another site from which I got its commands is: http://ansmachine.blogspot.com/2013/12/masm-using-dos-box-in-windows-8.html#.U3c8JvmSy27

Upvotes: 1

Views: 23560

Answers (1)

rkhb
rkhb

Reputation: 14409

DOSBox is appropriate to run 16 bit DOS programs, not 32/64 bit Windows programs. MASM can produce Windows programs since version 6.x. So you don't need DOSBox if you don't explicitly want to make DOS programs.

Your example is a 16 bit DOS program ("INT 21h"). To build it you have to open a "Windows Command Prompt" aka console, not DOSBox. If you don't know how, search at Google. I assume the path to your assembler is c:\masm615\bin. Now type:

c:\masm615\bin\ml.exe prog.asm

Note that I used ml.exe instead of masm.exe.

Now you can run prog.exe in DOSBox.

Search in the net for 32 bit MASM programs which you can assemble in the same way, but run in the current Windows console. Then you can and should forget anything with INT 21h!


And now let us do it with Visual Studio (VS). I'll show it with VS 2010 Express, but other versions of VS should be similar.

You need a Windows program (.MODEL FLAT), let's call it prog.asm:

.686p
.MODEL FLAT

includelib msvcrt.lib
extern _printf:PROC
extern _exit:PROC

.DATA
    format1 db "%s",10,0
    string1 db "Hello world!",0
    format2 db "The square root of %f is %f.",10,0
    double1 REAL8 10.0
    double2 REAL8 ?

.CODE
_main PROC

    push OFFSET string1
    push OFFSET format1
    call _printf

    fld double1
    fsqrt
    fstp double2

    push DWORD PTR double2 + 4
    push DWORD PTR double2
    push DWORD PTR double1 + 4
    push DWORD PTR double1
    push OFFSET format2
    call _printf

    push 0
    call _exit

_main ENDP

END _main

Open a console. First you need to know the location of vcvarsall.bat. Type in:

dir /s /b \vcvarsall.bat

After a few minutes you should get something like C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat. Type in this line in double quotes and press ENTER. Everything is okay when you see: Setting environment for using Microsoft Visual Studio 2010 x86 tools.

Now you can assemble and run prog.asm:

ml prog.asm
prog.exe

Upvotes: 2

Related Questions