home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PP0706.ZIP / CALLPRTF.ASM < prev    next >
Assembly Source File  |  1988-03-29  |  2KB  |  66 lines

  1.          name      callprtf
  2.          page      55,132
  3.          title     'CALLPRTF --- MASM call to printf'
  4. ;
  5. ; CALLPRTF.ASM --- demonstrates call to printf 
  6. ;                  from a MASM application
  7. ;
  8. ; by Ray Duncan, November 1987
  9.  
  10. cr      equ     0dh             ; ASCII carriage return
  11. lf      equ     0ah             ; ASCII line feed
  12.  
  13.         extrn   __acrtused:abs  ; drag in C startup code
  14.  
  15. DGROUP  group   _DATA
  16.  
  17.  
  18. _TEXT   segment word public 'CODE'
  19.  
  20.         assume  cs:_TEXT,ds:DGROUP
  21.  
  22.         extrn   _printf:near    ; drag in printf from the
  23.                                 ; C library, and its
  24.                                 ; dependent routines
  25.  
  26.         public  _main
  27. _main   proc    near            ; entered from C startup...
  28.  
  29.         mov     ax,DGROUP       ; make our data segment
  30.         mov     ds,ax           ; addressable
  31.  
  32.                                 ; push arguments for printf
  33.  
  34.         mov     ax,-1           ; integer: -1
  35.         push    ax
  36.  
  37.                                 ; address of message string
  38.         mov     ax,offset DGROUP:msgstr
  39.         push    ax
  40.  
  41.                                 ; address of format string
  42.         mov     ax,offset DGROUP:fmtstr
  43.         push    ax
  44.  
  45.         call    _printf         ; call C library function
  46.  
  47.         add     sp,6            ; clean up stack
  48.  
  49.         mov     ax,4c00h        ; now exit with 
  50.         int     21h             ; return code = 0
  51.  
  52. _main   endp
  53.  
  54. _TEXT   ends
  55.  
  56.  
  57. _DATA   segment word public 'DATA'
  58.  
  59. msgstr  db      'The value of x is',0   ; message string
  60.  
  61. fmtstr  db      cr,lf,'%s %d',cr,lf,0   ; format string
  62.  
  63. _DATA   ends
  64.  
  65.         end     
  66.