Home > Back-end >  Is microcode and machine code the same thing?
Is microcode and machine code the same thing?

Time:11-28

I had my first class of micro code few days back and noticed that some syntax of micro coding Atmel AVR microcontroller is quite similar to that of Assembly Level Language. However there are some syntax which do not match for common instructions. So are they the same?

For what I know, Assembly Level Language is just a programming language where the compiler translates that to machine language. Where is microcode coming in here?

Also what does the following sentence mean? "The assembler instruction ADD R1,R0 corresponds to the binary instruction word in Hexadecimal: OC(for Add) 01 (0001 for register 1 and 0000 for register 0)"

I know that the data/operands in the registers are in hexadecimal during ADD instruction but what is that 0C01?

CodePudding user response:

No, they are not the same thing.

noticed that some syntax of micro coding Atmel AVR microcontroller is quite similar to that of Assembly Level Language.

You are not writing microcode for an AVR - you will be writing assembly.

For what I know, Assembly Level Language is just a programming language where the compiler translates that to machine language. Where is microcode coming in here?

Microcode is not coming into play here. Assembly is indeed, a language (though a machine-specific language) that implements that machines instruction set. However, your statement oversimplifies it somewhat - you have described part of a typical build process.

More commonly, you will be programming an AVR using C (likely the avr-gcc toolchain).

A C program is compiled (which in turn takes several steps; pre-processing, linking etc) into assembly (if you're building a solution in Microchip Studio, look at the .lss output file, this is your generated assembly).

This assembly is then further processed into machine code.

Therefore, the same C will result in different assembly during the build process, when the target machine changes. I.e. whether you're building for an AVR, PIC, STM, SAM etc, as will the machine code.

However, small/simple microcontrollers typically do not implement microcode.

Microcode is more commonly 'used'/implemented on much more complex/powerful CPUs. To understand this, you must first be confident you understand what an instruction set is, if not - I suggest doing some digging there.

On complex CPUs, microcode is a layer of software which emulates a given instruction set, using often simpler underlying hardware. I.e., allows a machine whose hardware does not directly implement a given instruction, to support that instruction by using it's own instruction set to implement that of another.

For example, a CPU without hardware divide instruction (let's call this instruction DIV for now...), could 'pretend' to support a DIV, by executing a series of instructions that it's own hardware really can execute, to emulate the behaviour of a DIV, i.e. lots of adds, shifts, rotates, carries etc.

However, on an AVR - your instruction set is fixed, it is what it is, and it isn't what it isn't. For example, a divide on AVR is performed by the compiler generating the appropriate instructions, as there is no divide instruction, nor any microcode on the device that will perform a divide, using it's underlying native instructions.

  • Related