ISA & Assembly

What is the relationship between assembly language and machine code?

  1. AAssembly instructions are translated almost one-to-one into machine instructions by an assembler
  2. BAssembly is the same for every CPU and runs unchanged on any of them
  3. CMachine code is an interpreter that reads assembly line by line at run time
Show answer and explanation

Answer: A. Assembly instructions are translated almost one-to-one into machine instructions by an assembler

Assembly language writes machine instructions as readable mnemonics such as "add a0, a0, a1", and an assembler converts them into instruction bit patterns. Because it maps almost one-to-one onto instructions, a different ISA means a different assembly language. Pseudo-instructions such as "li" and "mv", however, are replaced by the assembler with one or more real instructions. Turning labels into addresses is also the assembler's job.

  • A. Correct. It writes the instructions as readable mnemonics.
  • B. Assembly differs for each ISA.
  • C. Machine code is the bit pattern the CPU executes directly.
Practice this topic Back to topic

More ISA & Assembly questions

  1. Which real instruction does the assembler use for the RISC-V pseudo-instruction "nop" (do nothing)?
  2. What is the difference between the RISC-V "add" and "addi" instructions?
  3. After running the RISC-V code above, what is the value in register a2?
  4. What does the RISC-V instruction "lw t0, 8(sp)" do?
  5. In the RISC-V conditional branch "beq a0, a1, label", how is the target address of label encoded?