![]() ![]() You can still have relative jumps (add an 8-bit value to the PC) and page-relative jumps (loading the lower 8 bits only) without needing any extra registers.Īlso, how would this work for jump instructions? If I want to jump to a specific instruction in the program, but don't know the address in memory because of all the other multi-length instructions To save having a WZ register, a different idea is to make the programmer load the address into a register, then jump to the address in the register. So it loads the halves into WZ and then transfers WZ to PC. But when you are loading into the program counter, you can't do this, because if you load the first half of the program counter then it messes up the address you load the second half from. Normally you would load 16 bits from memory into a register by loading one half, then the other half. If you use a ROM chip instead of combinational logic, the contents of the ROM are called microcode.įor jump and call instructions specifically (with 16-bit addresses), the Z80 CPU uses an extra, hidden 16-bit register called WZ. Then you can use the opcode register and the step counter and combinational logic to select what the CPU should do in the current clock cycle. To keep track of the steps, you might find it helpful to add a step counter "mini-register" which increments each cycle, except at the end of the instruction when it resets. load the MAR with the PC address, increment the PC, load from memory into the ALU right input, load from register B into the ALU left input, set the ALU mode to ADC (add-with-carry), store from the ALU output into register B.load the MAR with the PC address, increment the PC, load from memory into the ALU right input, load from register C into the ALU left input, set the ALU mode to ADD, store from the ALU output into register C.load the MAR with the PC address, increment the PC, and load from memory into the opcode register.An instruction like ADD BC, 1234 might process the bytes like this: Instead, the instructions are designed so only the opcode needs to be stored in the opcode register is needed, and the operand bytes can go directly to their final destination. ![]() But 8-bit CPUs generally do not have 3-byte instruction registers. In the 8-bit era it was typical that a CPU would read a 1-byte opcode, and then the operands (if any) would be in the next 1 or 2 bytes.Īlmost. So multi-byte instructions are a necessity. If they have 4-bit operands (not enough) you can only fit 16 instructions (also not enough). You can only fit 256 instructions, in fact. The instructions are often bigger than they need to be, but the simplicity can be worth it.Ĩ-bit processors don't do this, because you can't really fit enough instructions in only 8 bits. ![]() All the instruction operands are included as part of the instruction. This works for them because 32 bits is enough to fit plenty of instructions, and it makes it easy for the processor to load instructions. Some processors - generally, 32-bit RISC ones - make sure that all instructions fit in one location in memory. I would appreciate feedback on any of these questions. Or, is there a different way to store the instructions to get around this? Just to note, my processor also doesn't use any caching, meaning it has to get instructions and data exclusively from RAM.Īlso, how would this work for jump instructions? If I want to jump to a specific instruction in the program, but don't know the address in memory because of all the other multi-length instructions. loading the MAR with the PC address, incrementing the PC, and loading from memory into part of the instruction register, repeated up to three times. However, when fetching an instruction from memory, does this mean that the processor has to make up to 3 memory calls just for the fetch stage? For example, a 2 byte instruction could store the opcode-byte in one address, and a one-byte data value in the following. I've been researching, and I found that instructions generally span across multiple addresses in memory. ![]() The address length of 14 bits, and an instruction lengths ranging from 1 to 3 bytes. It doesn't make use of anything advanced as pipelining, as my knowledge isn't at that level yet to know how to implement it. I've recently been designing a simple 8-bit microprocessor, similar to the Intel 8008. ![]()
0 Comments
Leave a Reply. |