How does an engineer go about mapping opcodes to machine instructions? For example, say a new architecture has been designed that the engineer wants an ADD instruction to correspond to 3-bit binary code as 011. How would he/she "tell" the computer about this correspondence?

  • \$\begingroup\$ that would be baked into the entire CPU based on the ISA (instruction set architecture). \$\endgroup\$
    – jbord39
    Aug 19, 2017 at 1:49
  • \$\begingroup\$ The chip designers do that. You can roll your own CPU's on an FPGA and make whatever instructions you want \$\endgroup\$
    – Voltage Spike
    Aug 19, 2017 at 4:29
  • \$\begingroup\$ The engineer bakes it into his CPU design, and then the assembler follows suit. \$\endgroup\$
    – user207421
    Aug 19, 2017 at 9:05

1 Answer 1


Your question is pretty vague. When you say how do you map an opcode to binary, are you asking about the assembler? The assembler would read your source code, parse the words "ADD AX1 BX2" into "011" and whatever the bitfields are for those two registers, and bump out a binary file. so something along the lines of:

strtok(p_buf," ",blah blah blah)
     if (strcmp(p_buf,"ADD")
         strtok(p_buf," ",blah blah blah)
         if (strcmp(p_buf,"AX1")

An assembler is essentially just parsing your human written language, and rewriting it into the machine language, using the rules that were designed into it.

Or are you asking about the Instruction Register (IR) and Decoder? At the hardware level, Your CPU's Arithmetic and Logic Unit (ALU) is basically going to feed the operands (AX,BX,CX, et cetera) to logic functions for the various operations, and (again in very basic terms), demultiplex (or decode or switch or whatever word you use )the outputs of these various operations based on the OPCODE, so if you can imagine the outputs of the adder, subtractor, shift register, comparator, et cetera, all as inputs to DEMUX, the control input to which would be the OPCODE. In truth, the IR switches the operands on the inputs to the various logic functions as well.

This is all Microcomputer Architecture 101, and for more in depth details, any graduate or undergraduate level text should have all of this.

  • \$\begingroup\$ My apologies for being so vague. I'm new to learning the intricacies of processor architecture. The latter part of your answer was what I was looking for. Thank you for your thorough answer. \$\endgroup\$
    – Steven
    Aug 19, 2017 at 5:50

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.