Article View: comp.os.os2.programmer
Article #3120Re:32 bit programming using MASM 6.00b
From: Nelson Yu
Date: Sun, 20 Dec 1992 07:06
Date: Sun, 20 Dec 1992 07:06
129 lines
3874 bytes
3874 bytes
TR>Is there anyone out there who has experience assembling 32-bit OS/2 v2.0
TR>programs using Microsoft's MASM 6.00b. I thought that I could use the
TR>flat memory model but LINK386 chokes on the object code. LINK386 does not
TR>complain if I use the normal segmented model but the EXE created generates
TR>a 000E trap.
TR>Any pointers would be greatly appreciated.
TR> Jake
Wow! finally another MASM 6.00b OS/2 programmer. I have had limited success with flat(32 bits) mode programs. I continuously received a "Relative frame fix-up" error along with a "No automatic data segment." I have fixed neither, yet they run most of the time without causing an error.
TR>------------- hello.asm ------------------------
TR> title filecomp.asm
TR> .386
You alternatively could use .MODEL FLAT,SYSCALL,OS_OS2
TR>INCLUDE hello.inc
Add INCLUDELIB OS2.lib or DOSCALLS.lib
TR>cr equ 0dh
TR>lf equ 0ah
TR>stdin equ 0
TR>stdout equ 1
TR>stderr equ 2
TR>DGROUP group _DATA
DGROUP no longer exist in flat mode. All code and data are merged into one 'flat' segment. The 'group' statement does not help, it in fact is the main reason your program fails to run properly.
TR>_DATA segment dword public use32 'DATA'
'use32' changed to 'flat'
TR>testmess db cr,lf,'Hello World',cr,lf
TR>testmess_len equ $-testmess
TR>wlen dw ?
TR>_DATA ends
TR>_TEXT segment dword public use32 'CODE'
TR>main proc near
TR> push stdout
TR> push ds
TR> pushd offset DGROUP:testmess
TR> push testmess_len
TR> push ds
TR> pushd offset DGROUP:wlen
TR> call DosWrite
Use PROTO and INVOKE. They make code easier to read and modify.
The prototype
DosWrite PROTO(FAR??) SYSCALL
hf:HFILE,bBuf:PVOID,cbBuf:WORD,pcbBytesRead:PWORD
The function call
INVOKE DosWrite,
1,
ADDR testmess,
LENGTHOF testmess, ;or testmess_len
ADDR wlen
TR> or eax,eax
TR> jnz error
TR> push 1
TR> push 0
TR> call DosExit
TR>error: push 1
TR> push 1
TR> call DosExit
Another problem is that the procedures/functions in OS2.LIB are still using 16 bit segments therefore some may require thunking(Your API calls are actually addresses of the function in the DLL.
Try using the newer DOSCALLS.LIB, then replace DosWrite with Dos32write.
TR>main endp
TR>_TEXT ends
TR> end main
TR>------------- hello.inc ------------------------------------
TR>externdef DosWrite:near
TR>externdef DosExit:near
You at least understand the internal workings of flat mode
programs.
TR>------------- hello.def ------------------------------------
TR>NAME HELLO WINDOWCOMPAT
TR>DESCRIPTION "OS/2 2.0 Test Program"
TR>PROTMODE
TR>STACKSIZE 4096
I noticed in my PM programs written in assembly. They required 8192 bytes of stack space. If you did not meet this requirement, PM rudely send the application a SYS3175? error message.
TR>------------- assemble commands --------------------------
TR>ml /c /Zi /W3 hello.asm
TR>link386 /NOE /NOD /ALIGN:16 /M /DE
hello,,,c:\os2\doscalls,hello;
Nirvana has weeds. MASM 6.00b is still very buggy. I have been search for a suitable replacement with no luck. I personally rather move on to a subject like Object-oriented assembly, but if you prefer to continue on just ask me to post up some more example code.
---
X SLMR 2.1a X
1200
3
..
900
* Origin: Mach2 Vulcan OS/2 Systems 1-403-489-4250 (42:100/20)
Technical Details
Message-ID:
<724862369.0@ttlg.ttlg.UUCP>Path:
arc1-ca.pugleaf.net!sparky!uunet!noc.near.net!hri.com!spool.mu.edu!caen!destroyer!cs.ubc.ca!alberta!nebulus!ttlg!postmasterShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!noc.near.net!hri.com!spool.mu.edu!caen!destroyer!cs.ubc.ca!alberta!nebulus!ttlg!postmaster From: Nelson.Yu@ttlg.UUCP (Nelson Yu) Newsgroups: comp.os.os2.programmer Subject: Re:32 bit programming using MASM 6.00b Message-ID: <724862369.0@ttlg.ttlg.UUCP> Date: 20 Dec 92 07:06:24 GMT Sender: postmaster@ttlg.UUCP Lines: 129