TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Todd Cohen
from: Richard Hulme
date: 1995-05-17 20:16:00
subject: ASM

Hello Todd!

03 May 95, Todd Cohen writes to All:

 TC> Can someone please post me an example on how to write a program in
 TC> assembly under os/2 that will print "Hello" in a full
screen session.
 TC> Thanks. (BTW--If you replied to my last one(not sure if it got out), I
 TC> didn't get it because my feed was down. Can you please repost it. Thank
 TC> You

Ok, this'll assemble under MASM 6.00 for OS/2, link with LINK386:

---------------------------------cut here-------------------------------------
.386
.model flat, syscall

HSTDOUT equ     1                       ;Handle of Standard Out

DosExit         proto   near syscall,:dword,:dword
DosWrite        proto   near syscall,:dword,:dword,:dword,:dword

DGROUP group _DATA,STACK

STACK   segment dword stack flat 'STACK'
        db      4096 dup (?)            ;You could remove this line if you
                                        ;you use /STACK:4096 with LINK386
                                        ;instead
STACK   ends

_DATA   segment dword public flat 'DATA'

HelloString:
        db      'Hello',13,10,0
HelloStringLen  equ     $-HelloString

_DATA   ends

        assume  CS:FLAT, DS:FLAT, ES:FLAT, SS:FLAT

_TEXT   segment dword public flat 'CODE'
HelloWorld proc near syscall

local   {at}{at}BytesWritten:dword

        lea     eax,[{at}{at}BytesWritten]    ;Holds number of bytes actually written
        push    eax
        push    HelloStringLen          ;Number of bytes to write
        push    offset HelloString
        push    HSTDOUT                 ;File handle (StdOut)
        call    DosWrite                ;Print string
        add     esp,32                  ;Remove parameters from the stack
        push    0                       ;Result code (==ERRORLEVEL)
        push    1                       ;Terminate all threads in this process
        call    DosExit
HelloWorld endp
_TEXT   ends
        end     HelloWorld
---------------------------------cut here-------------------------------------

There are a couple of things to note:

I've pushed all the parameters onto the stack.  If you want, you could use
'invoke' instead of the pushes and the call.  This will push all the
parameters in the correct order (you have to push them on back to front)
and also clean up the stack afterwards.  This is really up to you. 
Personally, I prefer the method above as I have a little more control over
things.

Also, I've not 'include'd os2.inc.  Normally you would do this so that you
don't need to declare the prototypes manually.

Hope this helps.

bcnu,

Richard.

--- GoldED 2.40
* Origin: Floating Point/2 (2:250/109.10)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 250/109 25/10 250/107 255/1 440/4 141/209 270/101 105/103 42 712/515
@PATH: 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.