411 REFERENCE · Wikibooks
Microprocessor Design/Assembly Language
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Assemblers
Assemblers take in human-readable assembly code and produce machine code.
Image:Assembler.png
Assembly Language Constructs
There are a number of different assembly languages in existence, but all of them have a few things in common. They all map directly to the underlying hardware CPU instruction sets.
CPU instruction set is a set of binary code/instruction that the CPU understands. Based on the CPU, the instruction can be one byte, two bytes or longer. The instruction code is usually followed by one or two operands.
Instruction Code operand 1 operand 2
How many instructions there are depends on the CPU.
Because binary code is difficult to remember, each instruction has as its name a so-called mnemonic. For example 'MOV' can be used for moving instructions.
MOV A, 0x0020
The above instruction moves the value of register A to the specified address.
A simple assembler will translate the 'MOV A' to its CPU's instruction code.
Assembly languages cannot be assumed to be directly portable to other CPU's. Each CPU has its own assembly language, though CPU's within the same family may support limited portability
Load and Store
These instructions tell the CPU to move data from memory to a CPU's register, or move data from one of the CPU's register to memory.
register is a special memory located inside the CPU, where arithmetic operations can be performed.
Arithmetic
Arithmetic operations can be performed using the CPU's registers:
Increment the value of one of the CPU's registers
Decrement the value of one of the CPU's registers
Add a value to the register
Subtract value from the register
Multiply the register value
Divide the register value
Shift the register value
Rotate the register value
Jumping
During a jump instruction, the program counter is loaded with a new address that is not necessarily the address of the next sequential instruction. After a jump, the program execution continues from the new location in memory.
Relative jump the instruction's operand tells how many bytes the program counter should be increased or decreased.
Absolute jump the instruction's operand is copied to the program counter; the operand is an absolute memory address where the execution should continue.
Branching
During a branch, the program counter is loaded with one of multiple new values, depending on some specified condition. A branch is a series of conditional jumps.
Some CPUs have skipping instructions. If a register is zero, the following instruction is skipped, if not then the following instruction is executed, which can be a jumping instruction. So Branching can be done by using skipping and jumping instructions together.
Further reading
Assembly Language