Assembling & Running a Program in DOS: MASM/NASM/TASM

In summary, to write assembly language program in DOS environment, you need to know the DOS interface and the segmented vs. flat memory model. You can use Borland's Turbo C to write your code, and you can use their assembler, tasm.exe and their linker, tlink.exe to assemble and link your code. You can use their debugger, tdbug.exe or tdebug.exe to debug your code. Microsoft Visual Studio includes a dos console (command) option under "tools" folder in the start / programs / ... folder.
  • #1
pairofstrings
411
7
How to write assembly language program in DOS environment? I want to type my assembly language program in some interface and compile and link and execute it. How do I do that? Should I use one of those Masm/Nasm/Tasm assemblers or what?
 
Last edited:
Technology news on Phys.org
  • #2
pairofstrings said:
How to write assembly language program in DOS mode? I want to type my assembly language program in some interface and compile and link and execute it. How do I do that?

Hey pair of strings and welcome to the forums.

I wrote DOS based assembly a long time ago (when DOS was the only thing for games), so I can give you some pointers.

If you want to write DOS based code, one thing you need to know is the DOS "interface" and by interface I mean the interrupt calls.

The interrupt calls are used for everything from opening files, to setting your video mode, to playing CD audio, to allocating memory, to basically everything!

Also you have to be aware of segmented memory model vs the flat memory model. When I did DOS programming back then, segments were the model over flat. Segments in my view are really stupid since segments actually overlap, where as with the flat model memory addresses are unique: don't ask me why they did the segmented model the way they did, but yeah that's just the way it is.

I can't help you out any more unless you be more specific about it is that you want to do. If you want to write library code for some platform like say BASIC (with CALL ABSOLUTE), then you just have to basically restore the state before you leave your call.

If you want to write an entire program in complete assembler, you will need to really get a good grasp of the DOS dev environment (i.e, the interrupts). You will probably have to implement some custom interrupt code for the keyboard and that requires writing an ISR and getting DOS to use that ISR when you're code is running.

If you want to do things like write a joystick or sound driver (to play wave files) you need to get specs for IO port calls and the like. Same if you want to do graphics stuff in 256 color mode.

Then on top of your code that deals with files, memory, input and so on, you need your program specific code.

Maybe you can tell me what you want to do so I can give you some specific advice. Also I'm wondering why you want to want to code in DOS: you can write code in assembly using something like windows, but I guess if you want the kind of low level control that the DOS environments offers (no protected memory!) then I can understand.
 
  • #3
I need a stand-alone interface which will help me to write my program at low level using assembly.
like the way i do to write a C program
c:\>cd tc
c:\>tc\cd bin
c:\>tc\bin\tc.exe
opens up an interface where I can type my program and do stuff.
Similarly, I need some interface where I can type assembly language program then compile it then link it and execute it, if I am right with the order.
I want to do this in DOS environment, not in OS
 
Last edited:
  • #4
It appears that you are using Borland's Turbo C. The last version of Turbo C that I had, included their assembler, tasm.exe, and their linker, tlink.exe. If you have those tools, you should be able to write your assembly code using the same interface that can be used to write C code, but you will need to assemble and link your code from the DOS command line.

You can debug your assembly code using their debugger, tdbug.exe or tdebug.exe. I think that's what it is called.
 
  • #5
Microsoft Visual Studio includes a dos console (command) option under "tools" folder in the start / programs / ... folder. Once there you can use ML to assemble code. You don't get a toolbox like Programmers Workshop + Codeview though.

You could use the normal VS windows interface and create a dos console program, but you'd have to set a break point at the end of the program. or call a console input function at the end of the program to prevent the console window from closing when the program completes.
 
  • #6
thank you all of you, i have found the solution. thanks.
 

What are the different types of assemblers available for running a program in DOS?

There are three main types of assemblers used for programming in DOS: MASM (Microsoft Macro Assembler), NASM (Netwide Assembler), and TASM (Turbo Assembler). MASM is the most commonly used assembler and is compatible with Microsoft's Visual Studio development environment. NASM is a popular open-source assembler used for creating 32-bit and 64-bit programs. TASM is an older assembler that is still used for legacy applications.

What are the steps for assembling and running a program in DOS using MASM?

The steps for assembling and running a program in DOS using MASM are as follows:

  • Write the program in a text editor and save it with a .asm extension.
  • Open the MS-DOS prompt and navigate to the directory where the program is saved.
  • Use the MASM command to assemble the program (e.g. MASM program.asm).
  • Use the LINK command to link the assembled program with any necessary libraries (e.g. LINK program.obj).
  • Finally, use the program's executable file to run the program (e.g. program.exe).

How do you assemble and run a program in DOS using NASM?

To assemble and run a program in DOS using NASM, follow these steps:

  • Write the program in a text editor and save it with a .asm extension.
  • Open the MS-DOS prompt and navigate to the directory where the program is saved.
  • Use the NASM command to assemble the program (e.g. NASM -f obj program.asm).
  • Use the GCC command to link the assembled program with any necessary libraries (e.g. GCC program.obj).
  • Finally, use the program's executable file to run the program (e.g. program.exe).

What are the benefits of using an assembler for programming in DOS?

Assemblers allow programmers to write code at a low level, directly manipulating the computer's hardware. This can result in faster and more efficient programs. Assemblers also provide more control and flexibility compared to higher-level languages, allowing for precise optimization and customization.

What are some common errors to watch out for when assembling and running a program in DOS?

Some common errors to watch out for when assembling and running a program in DOS include typos in the code, missing or incorrect library files, and incorrect use of assembler directives. It's also important to make sure the program is compatible with the specific assembler being used and the version of DOS being used.

Similar threads

Replies
6
Views
1K
  • Programming and Computer Science
4
Replies
122
Views
12K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
12
Replies
397
Views
13K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
4
Views
497
  • Programming and Computer Science
Replies
14
Views
4K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
2
Replies
60
Views
16K
  • Programming and Computer Science
2
Replies
65
Views
2K
Back
Top