Assembly language is second generation low level language made up from mnemonics which can be used instead of machine codebecause its easier to use. The format of of an assembly language instruction usually consists of four parts: label, op code,operand and comments. Label: the leftmost item (e.g. Reset), it identifies each section of code and can be used as a pointer to show a jump command where to move to.
Operation (Op) code: the command to be carried out, usually shown as a mnemonic (e.g. ADD, MOV, etc).
Operands: the parts that the operation will be carried out on, they may have two parts (e.g. Acc 45 means the contents of the accumulator are moved to memory location 45).
Comments: assembly language code can be very long, so comments are used to explain what each command does as an aid to the programmer.
Addressing Modes
If data is transferred from a source register to a destination register, then this is an example of register addressing.
Immediate addressing - this is where the data apperas immediately after the op code.
Direct addressing - refers directly to a specific memory location.
Indirect addressing - uses a number inside a register( usually an index register) to point to the memory location of interest where the actual data can be found.
Indexed addressing - a number conatained in one register is usually used in combination with the number in another register to point to the actual memory location where the data is stored.
There are four main types of operation code:data transfer;arithmetic; logical;branch.
Data transfer operations -These are commands that move data between the registers and main memory.Typical instructions include:move, store, load.
Arithmetic operations - These include:add, subtract, multiply and divide ,increment(increase by 1) and decrement (decrease by 1),negate (reverse the sign) logical and arithmetic shift (moving bits left or right).
Status registers record: overflow errors in calculations sign bits.
Logical shift
This is used to carry out logical statements (AND, OR and NOT) as part of conditional statements during programming.
It is used to extract the content of one bit.
Arithmetic shift
This is used to multiply or divide numbers.
Shifting all the bits one place to the left has the effect of multiplying by two.
Shifting all the bits one place to the right has the effect of dividing by two.
Logical operations
These include the functions AND, OR and NOT.
They are used to compare values.
They can be used to mask out or ignore the contents of some bits in a byte.
For example, a 16 bit code may contain op code and an operand:
0100011110010010
You want to use the op code (first byte) again but not the operand in subsequent instructions.
A 16 bit mask can be set up where 1 allows the bit through and 0 masks it out .
When the two codes are ANDed the mask 1111111100000000 would allow the op code through but mask out the operand.
Branch operations
Branching is the ability to jump to another part of the program.
Many programs are written in a linear fashion, where one command follows the next in a logical order.
However, there are many occasions when the program needs to take different routes.
The jump command can be used in assembly language to move from one command to another.
Conditional jumps: the jump takes place if a condition is met.
For example, Jump if Zero (JIZ) so JIZ reset jumps to the line with the label called reset.
Unconditional jumps (JMP): take place regardless of any conditions.
Tuesday, 6 November 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment