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:

.386
.model flat,stdcall

.code
main PROC

L1:
  mov eax,1
  nop
  mov dx,3F8h
  nop
  out dx,al
  jmp L1
ret

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?

Thanks!

Window program? You cannot write directly to a serial port AFAIK. You would need to write a driver to do it in RING 0 in order to use OUT in 32 bit windows. Otherwise you would have to use the Windows API CreateFile, here is some reading:
http://msdn.microsoft.com/en-us/library/ms810467.aspx

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.