I am reading this guide about Intel 8080 emulation Emulator 101 and when I'm reading the code to check what I wrote, I stumbled upon this
case 0x36: //MVI M,byte
{
//AC set if lower nibble of h was zero prior to dec
uint16_t offset = (state->h<<8) | state->l;
state->memory[offset] = opcode[1];
state->pc++;
}
break;
from a book called Intel 8080/8085 Assembly Language Programming, I read about MVI this
This instruction copies the data stored in its second byte into the memory location addressed by H and L. M is a symbolic reference to the H and L register pair.
so I'm guessing that the offset is the memory location addressed by H and L, but why do we do it that way? That is (state->h<<8) | state->l
Thanks
how is the combination of << and | gives us the 16-bit offset?
Take H
, an 8-bit register, where H7 is the most significant bit and H0 is the least significant bit:
H7H6H5H4H3H2H1H0
Take L
, an 8-bit register, where L7 is the most significant bit and L0 is the least significant bit:
L7L6L5L4L3L2L1L0
You now want to construct the 16-bit offset that results from combining H
(Highest 8-bits) and L
(Lowest 8-bits.) In C/C++/Java this can be achieved by an 8-bit shift-left <<
followed by a bitwise-or |
as follows:
H = H7H6H5H4H3H2H1H0 H<<8 = H7H6H5H4H3H2H1H00 0 0 0 0 0 0 0 H<<8|L = H7H6H5H4H3H2H1H0L7L6L5L4L3L2L1L0