user133466
user133466

Reputation: 3415

The machine code in LC-3 are also known as assembly?

I'm a little confused over the concept of machine code... Is machine code synonymous to assembly language? What would be an example of the machine code in LC-3?

Upvotes: 1

Views: 2532

Answers (3)

ty.
ty.

Reputation: 11132

Assembly instructions (LD, ST, ADD, etc. in the case of the LC-3 simulator) correspond to binary instructions that are loaded and executed as a program. In the case of the LC-3, these "opcodes" are assembled into 16-bit strings of 1s and 0s that the LC-3 architecture is designed to execute accordingly.

For example, the assembly "ADD R4 R4 #10" corresponds to the LC-3 "machine code":

0001100100101010

Which can be broken down as:

0001 - ADD.
100 - 4 in binary
100 - 4 in binary
10 - indicates that we are adding a value to a register
1010 - 10 in binary

Note that each opcode has a distinct binary equivalent, so there are 2^4=16 possible opcodes.

The LC-3 sneakily deals with this problem by introducing those flag bits in certain instructions. For ADD, those two bits change depending on what we're adding. For example, if we are adding two registers (ie. "ADD R4 R4 R7" as opposed to a register and a value) the bits would be set to 01 instead of 10.

This machine code instructs the LC-3 to add decimal 10 to the value in register 4, and store the result in register 4.

Upvotes: 3

Seva Alekseyev
Seva Alekseyev

Reputation: 61378

The above stands true for any high level language (such as C, Pascal, or Basic). The differece between HLL and assembly is that each assembly language statement corresponds to one machine operation (macros excepted). Meanwhile, in a HLL, a single statement can compile into a whole lot of machine code.

You can say that assembly is a thin layer of mnemonics on top of machine code.

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 882171

An "Assembly language" is a symbolic (human-readable) language, which a program known as the "assembler" translates into the binary form, "machine code", which the CPU can load and execute. In LC-3, each instruction in machine code is a 16-bit word, while the corresponding instruction in the assembly language is a line of human-readable text (other architectures may have longer or shorter machine-code instructions, but the general concept it the same).

Upvotes: 3

Related Questions