Frage

in a course i am taking i need to make a basic computer on a software. Currently i have a RAM, ROM, Program Counter (PC), ALU, REG A, REG B, MUX A, MUX B, and a Control unit. Now, on the ROM i have a list of instructions in which each bit is sent to different parts, for example, the MUXs, REGs, the ALU (which can only add and substract), loadPC (to jump to an instruction). This ROM has 25 bits in each instruction and 255 instructions. Its like coding in assembly but even simpler. 1 more thing to note is that in the ALU output i have a 'z' bit which is only 1 when the ALU result is 0.

Now, from what i understund to jump i need to set the Literal to the memory i want to jump and set loadPC to 1. I want to see if B == 5 so in assembly this would be CMP B,5 JEQ (insert memory to jump)

CMP is really B-5, and if B==5, then the result is 0, then z = 1. JEQ intsruction will only loadPC if z = 1

Now, my question is, how do i implement this in my computer. Do i need an extra bit? Currently i created a new bit and set it to 0 always, except in the JEQ instruction. Lets call this bit 'v' My loadPC now goes through a logic box in which the inputs are 'v' 'z' and 'loadPC' and output is a new 'loadPC' (¬v or z) and (loadPC). However this approach doesnt seem too elegant, how can i do this in a better way?

War es hilfreich?

Lösung

The question is a little ambiguous. Are you asking how to do it or what the best practice is? In most textbooks you'll find there is a multiplexer whose output goes to the PC register. The inputs to this multiplexer are the current PC+4 (or whatever the instruction size is) and the jump target. The multiplexer is controlled by with a single bit input. This input could be the logical AND of "is the current instruction a jump" and "is the zero bit/register set". This is fine because you will always update the PC after an instruction, this isn't conditional, it's only the value that needs to be decided.

Good luck.

P.S. Don't use 'v' as this sometimes refers to an overflow flag.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top