1

Does reading a CPU port (through the in/out instructions) have any side effects whatsoever?

For example:

  1. Does it "tell" a device that the port has been read?

  2. Could reading an arbitrary port carelessly cause any harm?

I'm assuming it shouldn't, but then something doesn't make sense to me:

If there is no side effect, then how does an ATA drive, when doing programmed I/O, "know" when a word has been read, so it can supply the next word of data?

user541686
  • 205,094
  • 128
  • 528
  • 886
  • 1
    Perhaps I misunderstand, but isn't reading I/O the very definition of a side effect? – Kilian Foth May 18 '12 at 09:06
  • @KilianFoth: It's an input port... if it's simply reading a voltage, by definition it shouldn't change the value, right? Or maybe not, that's why I'm asking... either way, something doesn't make sense to me... – user541686 May 18 '12 at 09:07
  • It *shouldn't*, but CPUs are complicated and have all sorts of proprietary weirdness. Your best bet is to try it and see what happens. – Polynomial May 18 '12 at 09:08
  • @Polynomial: Well, if that's the case, I probably won't try it, since I don't wanna fry anything haha. That's one reason why I asked, thanks for the info. :P – user541686 May 18 '12 at 09:09

1 Answers1

4

Yes, reading a port can have side effects, but whether it does (and if so, what they are) varies between devices.

I've never heard of a device that could be damaged by reading a port. A few (but mostly old ones) could be damaged/cause damage by writing an incorrect value, but I don't know of any that reading could cause damage. In most cases, the side-effects of reading are fairly mild.

The act of reading can tell a device it's being read. To read from a device, you place a command and an address on the bus. If the command is "read" and the address corresponds to the device, then the device is being read.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111