Port I/O?

I want to learn how the IN and OUT instructions work. I've searched here on programmersheaven but can't find any good newbie guide or code, or am I just blind? :)

Could you tell me how they work or if it's too much writing you perhaps know a good link or tutorial that I can try?

Comments

  • : I want to learn how the IN and OUT instructions work. I've searched here on programmersheaven but can't find any good newbie guide or code, or am I just blind? :)
    :
    : Could you tell me how they work or if it's too much writing you perhaps know a good link or tutorial that I can try?

    For a short cut description, try

    http://courses.ece.uiuc.edu/ece291/archive/spr2002/books/labmanual/inst-ref-in.html

    For the best description, get .pdf Intel or AMD manuals (big, for free):

    http://developer.intel.com/design/pentium/manuals/

    http://www.amd.com/us-en/Processors/TechnicalResources/0,,30_182_739_7044,00.html
  • : : I want to learn how the IN and OUT instructions work. I've searched here on programmersheaven but can't find any good newbie guide or code, or am I just blind? :)
    : :
    : : Could you tell me how they work or if it's too much writing you perhaps know a good link or tutorial that I can try?
    :
    : For a short cut description, try
    :
    : http://courses.ece.uiuc.edu/ece291/archive/spr2002/books/labmanual/inst-ref-in.html
    :
    : For the best description, get .pdf Intel or AMD manuals (big, for free):
    :
    : http://developer.intel.com/design/pentium/manuals/
    :
    : http://www.amd.com/us-en/Processors/TechnicalResources/0,,30_182_739_7044,00.html
    :

    Ok, this is how I understand the use of IN and OUT:

    [code]IN eax, dx[/code]
    This reads 1 byte and stores the byte in EAX register. The address to the parallel port is located in DX.

    [code]OUT dx, eax[/code]
    This is like IN but it reads 1 byte from the port. DX contains the address to the parallel port.

    How do I get the corect address to the parallel port in my program?
    (32-bit Windows app, no DOS)


  • : Ok, this is how I understand the use of IN and OUT:
    :
    : [code]IN eax, dx[/code]
    : This reads 1 byte and stores the byte in EAX register. The address to the parallel port is located in DX.


    Not quite. Since EAX is a 32bit register, it'll read 4 bytes.
    Likewise, if you just did "IN ax, dx" it'd read 2 bytes and 1 byte for just "in al, dx"


    OUT works exactly the same way.

    Here's some more information:

    There are 65536 I/O "ports", numbered from 0 to FFFF. Each port is always 8bits or 1 byte in length.

    Your parallel port for example is located at port 378h. Doing an "in eax, dx" would provide you with the contents of port 378h, 379h, 37ah, and 37bh, all stuffed into the eax register.

    Think of read/writing I/O ports just like you would memory. Each "location" in memory is 1 byte in length too, but you can access it as 16bit words or 32bit dwords.

    hope that helps,

    -jeff!

  • : : Ok, this is how I understand the use of IN and OUT:
    : :
    : : [code]IN eax, dx[/code]
    : : This reads 1 byte and stores the byte in EAX register. The address to the parallel port is located in DX.
    :
    :
    : Not quite. Since EAX is a 32bit register, it'll read 4 bytes.
    : Likewise, if you just did "IN ax, dx" it'd read 2 bytes and 1 byte for just "in al, dx"

    Aah! Great THANKS!

    : Your parallel port for example is located at port 378h. Doing an "in eax, dx" would provide you with the contents of port 378h, 379h, 37ah, and 37bh, all stuffed into the eax register.

    Huh? You mean it will read from all 4?


  • [b][red]This message was edited by Moderator at 2003-10-9 16:16:40[/red][/b][hr]
    Paste the following diagrams into notepad or other text editor and set it to a fixed width font to see them correctly.

    Assuming:
    DX = 378h
    Port 378h = 0Fh
    Port 379h = 78h
    Port 37Ah = 0Ch
    Port 37Bh = FFh (can mean that the port doesn't exist)

    IN AL,DX:
    [code]

    Port 378h (=0Fh) --------------+
    |
    /

    |33322222|22222111|11111110|00000000|
    |10987654|32109876|54321098|76543210|

    | |
    +-----------------+-----------------+
    |
    EAX --------------+
    [/code]

    IN AX,DX:
    [code]

    Port 378h (=0Fh) --------------+
    |
    Port 379h (=78h) -----+ |
    | |
    / /

    |33322222|22222111|11111110|00000000|
    |10987654|32109876|54321098|76543210|

    | |
    +-----------------+-----------------+
    |
    EAX --------------+
    [/code]

    IN EAX,DX:
    [code]

    Port 378h (=0Fh) --------------+
    |
    Port 379h (=78h) -----+ |
    | |
    Port 37Ah (=0Ch) | |
    | | |
    | | |
    | | |
    Port 37Bh | | |
    (=FFh) | | |
    | | | |
    / / / /

    |33322222|22222111|11111110|00000000|
    |10987654|32109876|54321098|76543210|

    | |
    +-----------------+-----------------+
    |
    EAX --------------+
    [/code]




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories