home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / advos2 / ch14 / masm / portio.asm next >
Encoding:
Assembly Source File  |  1988-12-12  |  2.4 KB  |  91 lines

  1.     title    PORTIO --  Read/Write I/O Ports
  2.         page    55,132
  3.         .286
  4.  
  5. ;
  6. ; PORTIO.ASM
  7. ;
  8. ; General-purpose port read/write routines for C or MASM programs.
  9. ;
  10. ; Assemble with:  C> masm portio.asm;
  11. ;
  12. ; When this module is linked into a program, the following lines
  13. ; must be present in the program's module definition (DEF) file:
  14. ;
  15. ; SEGMENTS
  16. ;   IO_TEXT IOPL
  17. ;
  18. ; EXPORTS
  19. ;   RPORT 1
  20. ;   WPORT 2
  21. ;
  22. ; The SEGMENTS and EXPORTS directives are recognized by the Linker
  23. ; and cause information to be built into the EXE file header for
  24. ; the OS/2 program loader.  The loader is signalled to give I/O
  25. ; privilege to code executing in the segment IO_TEXT, and to build
  26. ; call gates for the routines 'rport' and 'wport'.
  27. ;
  28. ; Copyright (C) 1988 Ray Duncan
  29. ;
  30.  
  31. IO_TEXT segment word public 'CODE'
  32.         
  33.         assume  cs:IO_TEXT
  34.  
  35.  
  36. ; RPORT: Read 8-bit data from I/O port.  Port address
  37. ; is passed on stack; data is returned in register AX
  38. ; with AH zeroed.  Other registers are unchanged.
  39. ; C syntax:     unsigned port, data;
  40. ;               data = rport(port);
  41.  
  42.         public  rport
  43. rport   proc    far
  44.  
  45.         push    bp              ; save registers and
  46.         mov     bp,sp           ; set up stack frame
  47.         push    dx
  48.  
  49.         mov     dx,[bp+6]       ; get port number 
  50.         in      al,dx           ; read the port
  51.         xor     ah,ah           ; clear upper 8 bits
  52.                 
  53.         pop     dx              ; restore registers
  54.         pop     bp
  55.  
  56.         ret     2               ; discard parameters,
  57.                                 ; return port data in AX
  58. rport   endp
  59.  
  60.  
  61. ; WPORT: Write 8-bit data to I/O port.    Port address and
  62. ; data are passed on stack.  All registers are unchanged.
  63. ; C syntax:     unsigned port, data;
  64. ;               wport(port, data);
  65.  
  66.         public  wport
  67. wport   proc    far
  68.  
  69.         push    bp              ; save registers and
  70.         mov     bp,sp           ; set up stack frame
  71.         push    ax
  72.         push    dx
  73.  
  74.         mov     ax,[bp+6]       ; get data to write
  75.         mov     dx,[bp+8]       ; get port number
  76.         out     dx,al           ; write the port
  77.  
  78.         pop     dx              ; restore registers
  79.         pop     ax
  80.         pop     bp
  81.  
  82.         ret     4               ; discard parameters,
  83.                                 ; return nothing
  84. wport   endp
  85.  
  86. IO_TEXT ends
  87.  
  88.         end
  89.