IN and OUT instructions in 8086

970 views Asked by At

In 8086 the in and out instructions use a PIC port address as stored in AL or AX registers which in further is used with out instruction.
What happens if we don't give any port number in in instruction?
Does the out instruction still work?
If so, then how and what PIC port will be selected?

1

There are 1 answers

0
puppydrum64 On

Actually, the port address is stored in dx, not ax. The data you want to write goes in ax or al.

in and out work differently than most other operations in that

out dx,al
in al,dx

are perfectly valid even though the register sizes don't match. This is similar to how you're allowed to do mov al, byte ptr [bx], as your operand is using a register as a means of accessing memory, rather than storing it directly into a register itself.

I've never used an assembler that didn't have you specify a port, but since you either have to use a constant value or DX, it wouldn't be too much of a stretch to imagine there's an assembler out there that uses DX if only one operand is provided (kind of like how some 6502 assemblers make you type LSR A to do a right bit-shift on the A register when others are fine with just LSR.)

Which port you select is up to you, you're going to need to read the documentation for your associated peripheral to figure out which port number is needed. Remember that if you have a port number that is greater than 255, you'll need to use DX. Otherwise, you can just have the port number as a constant.