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.
1 Answer 1
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.
-
\$\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\$luna– luna2024年04月20日 21:09:42 +00:00Commented Apr 20, 2024 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– Dave Tweed2024年04月20日 21:29:28 +00:00Commented Apr 20, 2024 at 21:29
Explore related questions
See similar questions with these tags.
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 a7-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 writeMOV 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\$