Software Types and Language Translators: Question 8

Syllabus 4.2

Structured 7 marks

An engineer is writing a very small program directly in assembly language to control a robot arm's motor. The program uses mnemonics such as LDA, ADD and STA, each one standing for a single operation the processor can carry out.

(a) Name the type of translator needed to convert this assembly language program into a form the processor can execute, and describe, in general terms, how it processes the mnemonics to produce machine code. [3]

(b) State one way in which this translation process differs from how a compiler translates a program written in a high-level language such as Python. [2]

(c) Explain why the assembly language program, even though it is already a low-level language, still cannot be run directly by the processor without this translation step. [2]

Show worked solution Hide worked solution

Worked solution

Part (a): The translator needed for assembly language

Assembly language mnemonics, such as LDA, ADD and STA, need an assembler to translate them. The assembler reads through the assembly language source code and converts each mnemonic into its corresponding machine code instruction, generally with one assembly language instruction producing one machine code instruction, so that the whole program ends up as a machine code version ready to be executed.

Part (b): How this differs from a compiler’s translation

The key difference is in how instructions map to machine code. An assembler’s translation is a close, roughly one-to-one correspondence: each mnemonic becomes essentially one machine code instruction. A compiler translating a high-level language such as Python has to do much more work per instruction, because a single high-level statement (for example, one line of a loop or a complex expression) usually has to be expanded into several machine code instructions to have the same effect. (Both an assembler and a compiler translate the complete program before it runs. The distinguishing feature here is the ratio of source instructions to machine code instructions, not whether translation happens all at once or line by line.)

Part (c): Why assembly language still needs translating

Even though assembly language is a low-level language that maps closely to the processor’s own instruction set, the mnemonics themselves are still text written for people to read, such as LDA meaning “load the accumulator”. The processor’s circuitry can only recognise and carry out instructions in binary machine code, the specific pattern of 0s and 1s wired into its instruction set. Because a mnemonic is not itself that binary pattern, it must be translated by the assembler into machine code before the processor can execute it.

Final answers

  • (a) An assembler translates the assembly language mnemonics into machine code, generally producing one machine code instruction for each assembly instruction.
  • (b) An assembler’s translation is a close, roughly one-to-one match between source and machine code instructions; a compiler must expand each high-level statement into several machine code instructions.
  • (c) The processor can only execute binary machine code, not the human-readable mnemonics, so translation is still required even though assembly language is low-level.