Can anyone help me with port I/O


I am new to assembler programming and would apreciate any help. I need to write to a port on my video card, but as far as I understand the process of writing to a port is to write a value to a specific address, the specification talks about indexes and other stuff, could anyone explain it to me?


Register Type: Read/Write

Read/Write Port: 3D5, Index E0h, Index 00h

3D5, Index E1h

Default: 00h

D[7:5] FSEL, TV antiflicker mode selection

000: No filtering

001: Light filtering

010: Median filtering

011: Strong filtering

1xx: Adaptive filtering

D4 COMPN, Composite signal out

0: Enable Composite TV siganl out

1: Disable Composite TV signal out


I would like to enable/disable the TV signal out.



  • The VGA registers are setup so that they don't take up a lot of port locations.

    The setup is this.

    You out the index to port 3D4h and then you can read/write a byte at 3D5h.

    so one way of doing this is:

    mov dx, 3D4h

    mov al, 0E0h

    out dx, al

    inc dx

    mov al, [data] ;or whatever

    out dx, al

    That would write the data to port 3D5 index E0h

    A simpler way is to...

    mov dx, 3D4h

    mov al, 0E0h

    mov ah, [data] ;or whatever

    out dx, ax

    this will do the samething as the previous example.

    When you use the WORD or DWORD forms of out ie out dx, ax/eax

    it doesn't write a word to the port specified by dx, but it writes the low byte to the port specified by dx, then the next byte at dx+1 etc.

    In effect, this is just like memory. The reason for this is that the IO ports are from the CPU's perspective just another chunk of memory. And it accesses just like memory. The only difference is that it uses the opcode out instead of mov.

  • Thanks Darius

    That makes it alot clearer. I will try to get it working this weekend. However, how did you know when to use what index?

    If I have it right you get the 3D4h form:

    "D4 COMPN, Composite signal out"


    "D[7:5] FSEL, TV antiflicker mode selection"

    What does the D[7:5] mean then? Do I need to write to two ports 3D7h and 3D5h?

    I'm not realy going to use the antiflicker selection but it'll be good to know.


  • Use use the index they tell you, in this example it should be 0E0h.

    The D[7:5] and D4 are bit fields.

    Which means that bits 7-5 are the bits that determine TV AntiFlicker modem selection

    Bits [7:5] FSEL,TV Antiflicker mode selection

    and bit 4 is a flag determining wether the composite signal is enabled or not.

    So if bits 7-5 are

    000 - No filtering is done

    001 - Light filtering

    010 - Median filtering

    011 - Strong filtering

    1XX -Adaptive filtering

    The 1XX simple means that it ignores the 6-5 bits if the 7th bit is set, so




    111 are all adaptive filtering, and all equaivalent.

    The index value is told to you.

    I've checked the Intel Specification and Ralph Brown's port list and haven't found this particular register yet, so my best guess on how you use it is...

    To read it:

    output the value 0E0h to 3D4h which is the CRT indexing register

    then you can read the value at 3D5h which is the data register and changes depending on what was just outputted to the indexing register.

    To write it:

    output the value 0E1h to 3D4h

    then you can write the value at 3D5h

    I'm not sure what the Index 00h is for, and I can't seem to find any reference to this port being used for this.

    So here's a code snippet that should (hopefully) change Bit 4 from 1 (TV Out Disabled) to 0 (TV Out Enabled)

    mov dx, 3D4h

    mov al, 0E0h

    out dx, al ;Send 0E0 to 3D4

    inc dx ;DX=3D5

    in dx, al ;Get byte from 3D5 index 0E0

    and al, NOT 32 ;And out 4th bit

    push ax ;save the value while we change registers

    mov dx, 3D4h

    mov al, 0E1h

    out dx, al ;Send 0E1 to 3D4

    inc dx ;DX=3D5 now

    pop ax ;Get back the anded value

    out dx, al ;Send byte to 3D5 index 0E1

    If this doesn't work then you can just try treating the port like a normal port and see what happens. Or you can check your documentation to see if it has any examples of similiar cases.

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!