2

I am trying to emulate the Intel 8080 instruction set, and I got stuck on this instruction OUT D8, which according to the book Intel 8080/8085 Assembly Language Programming it says that The

OUT instruction places the contents of the accumulator on the eight-bit data bus and the number of the selected port on the sixteen-bit address bus. Since the number of ports ranges from 0 through 255, the port number is duplicated on the address bus.

The thing is I didn't understand what this does. Can someone explain it to me, or refer me to an article or a book that explains it.

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
hakuna matata
  • 3,243
  • 13
  • 56
  • 93
  • IMHO they try to say that only the lower 8 bits of an I/O addres are significant. The higher bits of the register used to address the port are put on the address bus, but should be ignored by the I/O devices on the bus. (the 8080 uses the same bus for memory and I/O, de distinction is made my an extra MEM/IO line) – wildplasser Nov 25 '12 at 14:40

2 Answers2

2

One way to think about it is that the 8080 and derivatives have a 17-bit address bus rather than the normally cited 16-bit bus. The top bit of that address bus is the chip's input/output request line (IORQ).

When you use the normal loads and stores the top bit is always reset. When you perform an in or out the top bit is always set.

Intel named the line and expected it to be used for communicating with peripheral chips, hence the name, the much more limited form of available addressing, the extended costs of access and the fact that neither the program counter nor the stack pointer can point into that area of address space.

That leaves Intel with the problem that they've got 16 bits of address bus to fill but have taken only an 8-bit parameter. What they actually do is they load the accumulator into the top 8 bits. So if you had:

LD A, 0xfe
OUT (0xdc)

Then the value 0xfe would be output to the port address 0xfedc.

(aside: apologies for the Zilog syntax rather than Intel; possibly interestingly the Z80 adds a bunch of instructions like OUT (C), A that really dump the entirety of BC onto the address bus rather than merely C and most Z80 micro manufacturers were perfectly happy to use the full 16-bit address as it allowed them to use the simplified logic of 'component is being addressed if this address line is low' while still having a decent range left over for external peripherals)

Tommy
  • 99,986
  • 12
  • 185
  • 204
  • 1
    Are you sure that 8080 do load accumulator in higher 8 address bits of IO cycle? Z80 does exactly this, but AFAIK 8080 just doubles 8-bit address twice at address bus. – lvd Mar 29 '16 at 19:44
  • I'm going to have to check my sources on that; the implication that I've conflated the two is quite possibly correct. – Tommy Apr 03 '16 at 17:26
1

for emulation it's mean
when IN/OUT ports exist in emulated device - simple IN/OUT data in port
when emulated device has memory mapped ports -
then
OUT AB -> to STA ABAB
IN 12 -> LDAX 1212

for hardware developer it's mean that when in/out executed, address bus has a15-8 = a7-a0 and =portNum

  • This would probably require that glue logic does *not* distinguish between memory and IO cycle. – lvd Mar 29 '16 at 19:46