home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c220 / 7.ddi / EXAMPLES / DOSEXT / RMHELLO.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-05-29  |  2.7 KB  |  130 lines

  1. title hel386.asm
  2. ;************************************************************************/
  3. ;*    Copyright (C) 1986-1988 Phar Lap Software, Inc.            */
  4. ;*    Unpublished - rights reserved under the Copyright Laws of the    */
  5. ;*    United States.  Use, duplication, or disclosure by the         */
  6. ;*    Government is subject to restrictions as set forth in         */
  7. ;*    subparagraph (c)(1)(ii) of the Rights in Technical Data and     */
  8. ;*    Computer Software clause at 252.227-7013.            */
  9. ;*    Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138    */
  10. ;************************************************************************/
  11.  
  12. comment #*****************************
  13. This program demonstrates how to write
  14. a program that uses 32-bit registers 
  15. and addressing modes, and 80386 
  16. instructions, but that will execute 
  17. in Real Mode on the 80386. The program
  18. writes a "hello world" message to
  19. the screen.
  20.  
  21. This program must be assembled for the
  22. 80386, but linked for the 8086.
  23. #*************************************
  24.  
  25.     assume    cs:cseg,ds:dseg
  26.  
  27. cseg segment para public use16 'CODE'
  28. ;
  29. ; The USE16 use attribute causes 
  30. ; override bytes to get generated for 
  31. ; 32-bit registers and addressing 
  32. ; modes
  33. ;
  34.     public    main
  35. main    proc    near
  36.  
  37.     mov    ax,dseg    ; Init DS
  38.     mov    ds,ax
  39.  
  40. ;
  41. ; Load the offset of the hello 
  42. ; message into EDX, and check to 
  43. ; make sure the 16 MSBs are zero.
  44. ; An override byte is generated on
  45. ; the MOV instr to allow us to
  46. ; reference EDX, and to get a
  47. ; 32-bit offset to the string.
  48. ;
  49.     mov    edx,offset hellomsg
  50.     call    chk_edx
  51.     cmp    eax,0    ; jump if
  52.     jne    #finish    ; error
  53.  
  54. ;
  55. ; Output the "hello world" message
  56. ; Use the 80386 SHLD instruction to
  57. ; get the DOS function code into AH
  58. ;
  59.     mov    al,09h    ; load DOS
  60.     xor    bx,bx    ; func code
  61.     shld    ax,bx,8    ; into AH
  62.     int    21h    ; call DOS
  63.  
  64. #finish:
  65.     mov    ax,4c00h ; Call DOS
  66.     int    21h    ; to terminate
  67.  
  68. main    endp
  69.  
  70. chk_edx    proc    near
  71. ;
  72. ; This procedure checks the EDX reg
  73. ; to see if any of the 16 MSBs are set
  74. ; If so, it outputs an error message.
  75. ; Return status in EAX:
  76. ;    0    16 MSBs of EDX all 0
  77. ;    1    At least one bit set
  78. ;
  79.     mov    eax,edx    ; Check 16 
  80.     xor    ebx,ebx    ; MSBs of
  81.     shrd    eax,ebx,16 ; EDX
  82.     je    all_zero ; jump if 0
  83.  
  84.     call    far ptr emsg ; output
  85.     mov    eax,1    ; error msg
  86.     ret
  87.  
  88. all_zero:
  89.     mov    eax,0    ; no error
  90.     ret
  91.  
  92. chk_edx    endp
  93.  
  94. cseg    ends
  95.  
  96. cseg2 segment para public use16 'CODE'
  97.  
  98. emsg proc    far
  99. ;
  100. ; Example of calling a far proc.
  101. ; This procedure just outputs an
  102. ; error message
  103. ;
  104.     mov    dx,offset errmsg
  105.     mov    ah,09h
  106.     int    21h
  107.     ret
  108.  
  109. emsg endp
  110.  
  111. cseg2    ends
  112.  
  113. dseg    segment    para public 'DATA'
  114.  
  115. errmsg    db "16 MSBs of EDX were not zero"
  116.     db    0dh,0ah,'$'
  117.  
  118. hellomsg db 'Hello world.....'
  119.     db    0dh,0ah,'$'
  120.  
  121. dseg    ends
  122.  
  123. stack segment para stack 'STACK'
  124.     
  125.     db    1000 dup (?)
  126.  
  127. stack    ends
  128.  
  129.     end main
  130.