Author Topic: Problem with OUT opcode  (Read 5709 times)

Offline ben321

  • Full Member
  • **
  • Posts: 182
Problem with OUT opcode
« on: August 13, 2015, 10:50:38 AM »
According to http://wiki.osdev.org/VGA_Hardware#Port_0x3C4.2C_0x3CE.2C_0x3D4 to control certain aspects of your VGA hardware in DOS, you need to use ports 0x3XX, but there's a problem with that. To output to one of these ports, the apparant way to do it

MOV ax,0x0005
OUT 0x3C4,ax

doesn't work. It says that the first operand is only a byte in size. How do I output to a port who's port-number is greater than 255, if the first operand only accepts byte-sized input? I have searched the internet for about 2 hours trying to find out how to do this, but I've turned up absolutely nothing. I'm hoping that some assembly-code experts here on this forum could could help me.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Problem with OUT opcode
« Reply #1 on: August 13, 2015, 12:07:27 PM »
If the operand fits in a byte, it can be an immediate. If it's two bytes, it has to go in dx.
Code: [Select]
mov dx, 0x3C4
mov ax, 5
out dx, ax
Plain as mud.

Best,
Frank


Offline ben321

  • Full Member
  • **
  • Posts: 182
Re: Problem with OUT opcode
« Reply #2 on: August 13, 2015, 11:39:03 PM »
If the operand fits in a byte, it can be an immediate. If it's two bytes, it has to go in dx.
Code: [Select]
mov dx, 0x3C4
mov ax, 5
out dx, ax
Plain as mud.

Best,
Frank

Thanks for the help. Don't know why I didn't think of that. I saw on another website where I was reading about graphics functionality for VGA and somebody had some sample code that had 2-byte immediate value for both of the parameters of the OUT command. That didn't work when I tried it, so I decided I needed to use the AX register for the data value parameter, but thought that I could still send an immediate 2-byte value for the port number parameter. I guess I was mistaken on that.