0
\$\begingroup\$

I have an assignment that requires me to build an 7-bit CPU. I’m done with implementing some of the requirements that includes 4 8-bit registers (the requirements say I have to store the parity bit), the ALU. I also added the Program Counter and the ROM for the instructions to be written into.

I have to now write the instructions (8 of them) into the ROM as hexadecimal and that’s where I’m confused. The way I’ve seen people do it is define the 16-bit instruction. I was planning on defining it as 1 bit to specify whether the instruction uses immediate values, opcodes (3 bits in my case), 2 for source register and 2 for destination register, and then 7 bits for if I have immediate values.

I understand how to write them into the ROM but how can I implement the logic to assign an opcode to a specific operation?

For example, lets say I have an instruction “MOV Rd, Rs”, how am I meant to write the instructions into the ROM without basically hardcoding the bits for the source and destination register.

I hope everything I said makes sense. I’m very new to all this.

\$\endgroup\$
4
  • \$\begingroup\$ You write 7-bit CPU but the only thing discussed later that matches the number 7 is the immediate constant value in a 16-bit instruction. You have 8-bit registers and 16-bit instructions? So how did this become a 7-bit CPU? Also, I suspect you are confused. No discussion about whether this is a microcoded CISC or a pipelined RISC or ??? But when you write MOV Rd, Rs there are two problems. One is just a matter of an assembler generating instructions which are just hard-coded data to the CPU. Another is the decoding of those instructions in the CPU. What's the topic here? \$\endgroup\$ Commented Apr 20 at 23:56
  • \$\begingroup\$ @periblepsis The OP explains why the register file has 8 bit registers: They shall add a parity bit. However, the data width is 7 bit. \$\endgroup\$ Commented Apr 21 at 5:46
  • \$\begingroup\$ @thebusybee Ah. So it's 7-bit data. But 16-bit instruction width. Thanks. \$\endgroup\$ Commented Apr 21 at 7:26
  • \$\begingroup\$ You need to watch Ben Eater series on building an 8 bit computer from scratch. All your questions will be answered. youtube.com/… \$\endgroup\$
    – Candid Moe
    Commented Sep 24 at 11:16

1 Answer 1

0
\$\begingroup\$

There is usually a piece of software called an "assembler" that takes human-readable mnemonic codes (from a text file) and converts them to the numeric codes ("machine code", in a binary file) that the CPU actually needs.

However, in an academic context, you are usually expected to "hand assemble" your program — i.e., write down the mnemonics, and then write down the corresponding machine code next to each one. Then you copy those numbers into your ROM so that you can run the simulation.

\$\endgroup\$
2
  • \$\begingroup\$ I understand that. However, doesn't that basically make it "hardcoded"? If I define my destination register in the instruction using the bits 10, wouldn't that always refer to the second register? \$\endgroup\$
    – maira
    Commented Apr 20 at 21:09
  • 2
    \$\begingroup\$ Well, yes. That instruction in the ROM would be addressing the second register. Isn't that what you want? Perhaps I'm not understanding what you mean by "ROM". If you're referring to a microinstruction ROM that's decoding the macroinstructions of your program, then some of the fields, such as register addresses, will be taken directly from the macroinstruction. \$\endgroup\$
    – Dave Tweed
    Commented Apr 20 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.