home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / TM1632.ZIP / HEL1632.ASM next >
Assembly Source File  |  1992-12-06  |  3KB  |  103 lines

  1. TITLE OS/2 assembly language program to display Hello world!
  2. ; HEL1632.ASM
  3. PAGE 0,80
  4. .386
  5. ;For 16 bit OS/2 2.0 using DOS32WRITE
  6. N32  TYPEDEF PTR NEAR32
  7. F32  TYPEDEF PTR FAR32
  8. F16  TYPEDEF PTR FAR16
  9.  
  10. STACK16 SEGMENT DWORD STACK USE16 'STACK'
  11. STACK16 ENDS
  12.  
  13. ASSUME ds:DGROUP,ss:STACK16
  14.  
  15. DATA32 SEGMENT DWORD PUBLIC FLAT 'DATA'
  16. DATA32 ENDS
  17. ; DATA32 segment must come before DATA16 segment, otherwise FLAT selector will
  18. ; be wrong
  19.  
  20. DATA16 SEGMENT DWORD PUBLIC USE16 'DATA'
  21. msg  BYTE 0Dh,0Ah,'Hello World!',0Dh,0Ah ;length 16
  22. Nparams  BYTE ? ;value to be placed in AL on call to 32-bit API
  23. wlen DWORD ? ;receives number of bytes written
  24. OurStack DWORD ?
  25. OurDS    WORD  ?
  26. Stack32  FWORD ?    
  27. ProgAddr DWORD ?
  28. ReturnPoint DWORD ?
  29. Entry32  FWORD ?             
  30. DATA16 ENDS
  31.                                       
  32. DGROUP GROUP DATA16
  33. EXTERN DOS16SELTOFLAT:FAR16,DOS16FLATTOSEL:FAR16,DOS16EXIT:FAR16
  34.  
  35. CODE32 SEGMENT DWORD PUBLIC FLAT 'CODE'
  36. EXTERN DOS32WRITE:NEAR, DOS32EXIT:NEAR
  37. Start32:            
  38. mov   ax,SEG FLAT:DATA32
  39. mov   ds,ax ;set up FLAT context
  40. mov   es,ax                       
  41. mov   al,gs:Nparams
  42. call  N32 PTR gs:[ProgAddr]
  43. ; Designed to be usable for any call to 32-bit API, thus avoiding repetitious
  44. ; coding in the case of many different 32-bit API calls
  45. ;mov   bx,DGROUP
  46. ;mov   gs,bx ;needed only if 32-bit API resets gs without restoring
  47. ; But apparently OS/2 operating system doesn't disturb GS
  48. jmp   F16 PTR gs:[ReturnPoint]                                       
  49. CODE32 ENDS
  50.  
  51. CODE16 SEGMENT DWORD PUBLIC USE16 'CODE'
  52.  
  53. PRINT:
  54. push  ds
  55. pop   gs ;keep reference to DATA16, if this be OK with OS/2
  56. ; Apparently OS/2 uses DS, ES and FS but not GS, so we are free to use GS
  57. mov   OurDS,ds
  58. mov   ProgAddr,OFFSET FLAT:DOS32WRITE
  59. mov   WORD PTR ReturnPoint+2,cs
  60. mov   WORD PTR ReturnPoint,OFFSET Return1; set up return address
  61. mov   WORD PTR OurStack+2,ss
  62. mov   WORD PTR OurStack,sp
  63. mov   DWORD PTR Entry32,OFFSET FLAT:Start32
  64. mov   WORD PTR Entry32+4,SEG FLAT:CODE32
  65. mov   ax,DGROUP
  66. shl   eax,16; create 16:16 pointer to convert to FLAT 0:32
  67. mov   ax,OFFSET wlen
  68. call  DOS16SELTOFLAT
  69. push  eax          
  70. pushd 16 ;length of message
  71. mov   ax,DGROUP
  72. shl   eax,16
  73. mov   ax,OFFSET msg
  74. call  DOS16SELTOFLAT
  75. push  eax
  76. pushd 1; stdout handle
  77. ;mov   ax,SEG FLAT:DATA32 ;see in IPMD if this is 53 or 5B or other
  78. mov   ax,ss
  79. shl   eax,16
  80. mov   ax,sp
  81. call  DOS16SELTOFLAT
  82. mov   DWORD PTR Stack32,eax
  83. mov   WORD PTR Stack32+4,SEG FLAT:DATA32
  84. lss   esp,Stack32 
  85. mov   DGROUP:Nparams,4; number of parameters to DOS32WRITE
  86. jmp   F32 PTR DGROUP:[Entry32]; 32-bit call will be done from there
  87. ;call  Dos32Write ;OS/2 system function
  88. Return1:
  89. mov   bx,DGROUP
  90. mov   ds,bx
  91. lss   sp,ds:OurStack
  92. or    eax,eax; was write successful?
  93. jnz   Errer
  94. pushw 0;return code
  95. pushw 1; action code: end all threads in process
  96. call  DOS16EXIT
  97. Errer:
  98. pushw 1
  99. pushw 1
  100. call  DOS16EXIT
  101. CODE16 ENDS
  102. END   PRINT
  103.