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
Take
H, an 8-bit register, where H7 is the most significant bit and H0 is the least significant bit:Take
L, an 8-bit register, where L7 is the most significant bit and L0 is the least significant bit:You now want to construct the 16-bit offset that results from combining
H(Highest 8-bits) andL(Lowest 8-bits.) In C/C++/Java this can be achieved by an 8-bit shift-left<<followed by a bitwise-or|as follows: