Hello guys. I am having a problem with the following code. When I try to run the program the instruction int 21 causes an access violation. Can someone tell me how to fix this problem?

.386
.model flat

.stack 100h

.data

message db 'Hello World', 13, 10, '$'

.code

_start: 

lea dx, message 

mov ah, 9h ; string output

int 21h ; display string

mov ax, 4c00h

int 21h

mov ah, 1h 

int 21h ; read character into al

mov dl, al 

mov ah, 2h 

int 21h ; display character in dl

mov ax, 4c00h 

int 21h

end _start

Access violation is caused when a program attempts to
access memory reserved for the operating system.
I thought this could only happen in a windows program?

I assume your using MASM:

mov ax, seg message ; initialize the DS register so
mov ds, ax                  ; you can access variable 'message'
lea dx, message

Program flow stops before line 23, because you terminated
with 21/4C.

Access violation is caused when a program attempts to
access memory reserved for the operating system.
I thought this could only happen in a windows program?

I assume your using MASM:

mov ax, seg message ; initialize the DS register so
mov ds, ax                  ; you can access variable 'message'
lea dx, message

Program flow stops before line 23, because you terminated
with 21/4C.

Thanks a lot :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.