Hey All,

Just wanted to know how to correctly use the OUT instruction for the x86 instruction set

I'd like to output some data on the serial port which for me is 3F8h IRQ4.
So I set up a test program as follows:

.model flat,stdcall

main PROC

  mov eax,1
  mov dx,3F8h
  out dx,al
  jmp L1

main ENDP

END main

Compiles and links fine, but when run it crashes.

How would I go about sending just a simple loop of 1's across a serial pin?


6 Years
Discussion Span
Last Post by miker00lz

In addition to what ^^ said you can't just send a byte out the serial port. The port has to be set up first with stop bits, data bits, parity and baud rate and those must match whatever is on the other end of the serial port.


in addition to that, you also have to have routines in between each byte you send that polls the serial controller's status port to know when the other system has received the data, and it's safe to send the next byte. if you neglect to do this, the data coming in on the other end will just show up as random garbage. even a lowly 8088 can send data out to the controller WAYYYYYyyyyyyyyyyyyy faster than it can move it along to the remote system.

it's tricker than it may seem at first glance, but not too bad.

Edited by miker00lz: n/a


Soooooo what you're all saying is.... C# System.IO.Ports is the way to go? Hahaha, yeaaaaaa since it's access is blocked it would appear to be way more hassle than it's worth... frustrating though because it's all about the learning potential rather than doing it the stupid easy way..


yeah, you cant really easily access it directly in windows. you'd need your code running in kernel mode, but don't let that deter you. if you want to learn how it really works at a low level, i think you should. use an emulator and write the code in DOS, or even better, if you have an old 486 or something similar sitting in storage somewhere.. set it up and code on real metal.

Edited by miker00lz: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.