cria
cria

Reputation: 205

MASM32, display string and integer

I am using MASM32 (version 10), and I would like to know what is the easiest way to output a string and an integer on screen. Please provide the full source code, and not just the specific lines.

Thank you.

Edit:

.386
.model flat, stdcall
.stack
.data
stest db "This is a test", 0
.code
main proc
    mov ah, 09h
    lea dx, stest
    int 21h
main endp
end main

It crash without outputting anything. I tried several other things, with different problems, the only common thing is that I don't get the string displayed on screen :)

Upvotes: 1

Views: 9911

Answers (3)

Brian Knoblauch
Brian Knoblauch

Reputation: 21369

Use the built-in "print" function/macro. It'll insert the appropriate call for you.

print "This is a test",13,10,0

Upvotes: 1

Jester
Jester

Reputation: 58762

Note that int21/09 requires the string to be terminated by a dollar sign ($). Also, even if your code did print something, it would crash immediately afterward since you don't terminate your program at all (see int21/4c) so it continues executing undefined memory. Depending on memory model and environment, you might also have to set up the segment registers and the stack for yourself first. All of this assumes that you indeed have access to int21 services to start with.

Finally, as a general advice, get a debugger working and trace your program.

Upvotes: 1

Greg Hewgill
Greg Hewgill

Reputation: 993343

You appear to be using DOS interrupts (int 21h) but have also used .model flat, which indicates you're not building a DOS program (DOS doesn't support the flat model).

If you intend to build a 32-bit console mode program suitable for running on Windows, you cannot use DOS interrupts. Here's an article which presents a 32-bit "hello world" Windows example using Win32 calls: 32-Bit Flat Memory Model MASM Code for Windows NT.

If you intend to build 16-bit DOS code, you probably want to start with the "small" memory model.

Upvotes: 3

Related Questions