Click here to Skip to main content
15,900,461 members
Articles / Programming Languages / C#

Z80 CPU - Extended Addressing

Rate me:
Please Sign up or sign in to vote.
4.75/5 (4 votes)
11 May 2016CPOL 7.2K   2  
Z80 CPU - Extended Addressing
So since the last post, I have been working my way through the Load Operations, which follow a very similar format to the ones we have already discussed.

However, the next operation I need to add is LD A, (nn); which means populate the Accumulator register with the value in the memory address nn where nn is the operands of the operation.

When the address to use is specified as the operands of the operation it is known as Extended Addressing.

Addresses in the Z80 Architecture are made up of 16 Bits, which allows them to have a much greater addressable space (More Memory) than using just 8 Bits.

In terms of actually implementing this, it's very similar to the memory load operation we have already done, but instead of loading the values into registers, first we can simply get the address from the operands.

C#
[TestMethod]
public void LoadNNAddressValueIntoA()
{
    var memory = new ListOfActionsMemory();
    var cpu = new CPU(memory);

    var lowByte = new ZByte(Bit.Zero, Bit.One, Bit.Zero, Bit.Zero, Bit.Zero, Bit.Zero, Bit.One, Bit.Zero);
    var highByte = new ZByte(Bit.Zero, Bit.Zero, Bit.Zero, Bit.One, Bit.One, Bit.One, Bit.Zero, Bit.Zero);

    var value = new ZByte(Bit.Zero, Bit.One, Bit.Zero, Bit.One, Bit.Zero, Bit.One, Bit.Zero, Bit.Zero);

    memory.ReadValues.Add(new SixteenBitAddress(highByte, lowByte), value);

    cpu.PerformInstruction(LoadCommand.NNIntoA, lowByte, highByte);
    cpu.PerformInstruction(LoadCommand.AIntoMemory, null, null);
         
    Assert.AreEqual(value, memory.Saved[0].Item2);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --