News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Simple assembler runtime error

Started by vraifreud, September 21, 2007, 03:34:03 PM

Previous topic - Next topic

vraifreud

I'm new to 32-bit assembler and when I wrote a simple program as follows:

.386
.model flat,stdcall
.stack 100h
.code
start:
mov ah,1
int 21h
end start


The compilation and linkage all passed well, but at runtime a dialogbox displayed: "filename.exe has encountered a problem and needs to close. We are sorry for the inconvenience."

The code "mov ah,1
int 21h" makes no sense, but when it is changed to any other code the runtime error occurs all the same.

Can anybody help me?

Rockoon

The sequence..

mov ah, 1
int 21h

..is from the days of 16-bit programming. Specifically, this is an MS-DOS system call used to terminate the program.

You are however assembling a 32-bit windows program and because of that, you cannot call 16-bit MS-DOS, and that is why you get the error when you leave this code in. The code raises an exception and windows forcibly terminates your program because you have not provided your own exception handler.

The reason you get an error when you remove it, is that your program never ends. The processor just keeps fetching memory trying to execute it until it find an illegal instruction, at which point an exception is raised and windows forcibly terminates your program because you have not provided your own exception handler.

Clear?
When C++ compilers can be coerced to emit rcl and rcr, I *might* consider using one.

dsouza123

The following is 32 bit code that has standard program exit code.


.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.code
start:
  invoke ExitProcess,0
end start



  invoke ExitProcess,0

is treated as

  push 0
  call ExitProcess


vraifreud

Thank you all. I know now what the problem is and I've succeeded in running my first 32-bit assembler program by invoking ExitProcess.

sinsi

Quote from: Rockoon on September 21, 2007, 04:14:16 PM
The sequence..

mov ah, 1
int 21h

..is from the days of 16-bit programming. Specifically, this is an MS-DOS system call used to terminate the program.
Nope, it's "READ CHARACTER FROM STANDARD INPUT, WITH ECHO"
AH=0 is the (non-recommended) way to terminate a DOS program.
Light travels faster than sound, that's why some people seem bright until you hear them.

hutch--

Common problem when first migrating rom DOS assembler. DOS interrupt driven os code is not available in 32 bit protected mode.


.386                    ; ok for 32 bit
.model flat,stdcall     ; model and calling convention OK
.stack 100h             ; incorrect in 32 bit PE, stack is set in linker
.code
start:
mov ah,1
int 21h                 ; < crash is here, interrupt fatal in protected mode windows
end start               ; address range for interrupts not available
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php