The MASM Forum

General => The Campus => Topic started by: ggmasm32 on January 12, 2016, 08:10:55 PM

Title: newbie 32-bit program, it builds but crashes when run
Post by: ggmasm32 on January 12, 2016, 08:10:55 PM
Moving up the 32-bit ladder, tried to compile 32-bit console application. I managed to build but it just crashes when run, do you see anything wrong?, appreciate in advance!


.686p

;    include macros32.inc
;    include exp32.inc

; experimental asm file to test out anything in this file.
; past tests can be de-activated using DISABLE_<TESTNAME> software switch in
; exp.inc

.model flat, stdcall            ; windows is always 32-bit flat

option casemap:none

.STACK 100h

.DATA
msg db "Hello World!$"

.CODE

;   M_EXTERNDEF

exp32 PROC
;   mov     ax, @DATA
;   mov     ds, ax

    mov     ah, 02h
    mov     dl, 31h
    int     21h

    mov     ah, 4ch
    int     21h
exp32 ENDP
    END exp32




Make target:



#===32-bit programs===

LINK32FLAGS=/subsystem:CONSOLE
ASM32FLAGS=/c /coff /Fl /Zi /Zd
LINK32=link.exe
ASM32=ml

exp32: $(EXP32).exe stat

$(EXP32).exe: $(EXP32).obj
    $(LINK32) $(LINK32FLAGS) $(EXP32).obj

$(EXP32).obj: $(EXP32).asm inc
    $(ASM) $(ASM32FLAGS) $(EXP32).asm


Title: Re: newbie 32-bit program, it builds but crashes when run
Post by: jj2007 on January 12, 2016, 09:00:16 PM
Why don't you study \Masm32\examples\exampl01 instead of assuming (wrongly) that Windows will do you the favour to tolerate your 16-bit coding habits? This forum has a search function here (http://masm32.com/board/index.php?action=search;advanced;search=). Try int 21h to see that it works only for 16-bit code. If your computer is a recent model, you can't execute 16-bit code. Swallow that pill, you have to read the * manual.

Edit= Profanity.
Title: Re: newbie 32-bit program, it builds but crashes when run
Post by: Grincheux on January 12, 2016, 09:02:23 PM
It is not a console application but a ms-dos program.

Quote
Microsoft® MASM
Assembly-Language Development System
Version 6.1
For MS-DOS ® and Windows ™ Operating Systems


.MODEL small, pascal
.STACK 200h

.DATA
msg BYTE "This writes to the screen$"
.CODE
.STARTUP
mov dx, offset msg ; DS:DX points to msg
mov ah, 09h ; Request Function 9
int 21h
mov ah,4c00h
int 21h
END

Title: Re: newbie 32-bit program, it builds but crashes when run
Post by: ggmasm32 on January 13, 2016, 08:04:31 PM
Quote from: Grincheux on January 12, 2016, 09:02:23 PM
It is not a console application but a ms-dos program.

Quote
Microsoft® MASM
Assembly-Language Development System
Version 6.1
For MS-DOS ® and Windows ™ Operating Systems


.MODEL small, pascal
.STACK 200h

.DATA
msg BYTE "This writes to the screen$"
.CODE
.STARTUP
mov dx, offset msg ; DS:DX points to msg
mov ah, 09h ; Request Function 9
int 21h
mov ah,4c00h
int 21h
END


thanks!
Title: Re: newbie 32-bit program, it builds but crashes when run
Post by: ggmasm32 on January 14, 2016, 06:12:46 PM
Quote from: jj2007 on January 12, 2016, 09:00:16 PMWhy don't you study \Masm32\examples\exampl01 instead of assuming (wrongly) that Windows will do you the favour to tolerate your 16-bit coding habits? This forum has a search function here (http://masm32.com/board/index.php?action=search;advanced;search=). Try int 21h to see that it works only for 16-bit code. If your computer is a recent model, you can't execute 16-bit code. Swallow that pill, you have to read the manual.

Hey thx for pointing out! Also take it easy too!!

Edit = Profanity in quoted text
Title: Re: newbie 32-bit program, it builds but crashes when run
Post by: Mikl__ on January 14, 2016, 06:57:06 PM
or make COM-file
bat-filecls
set filename=name_of_your_asm_file
ml /c /Cp %filename%.asm
link16 /t %filename%.obj,,,,,
del %filename%.obj

asm-file.MODEL tiny
.CODE
org 100h
start:mov dx, offset msg
mov ah,9
int 21h
mov ah,0
int 16h
ret
msg BYTE "This writes to the screen$"
end start