Assembly language examples :: Assembly

Assembly language examples

Assembly Language Programming

A typical line in assembly language programme might be as follows:

LOOP: MOV.B r0, #80 ;initialise counter

This line will be assembled into a single instruction (in this case 11 0000 1000 0000 in binary, or 3080); the assembly language and the machine code correspond to each other.

It has four parts; label, mnemonic, operand, comment; not all are present in every line.

The first part (LOOP in this example) is a label ; this is a word, invented by the programmer, which identifies this point in the program. It will be set equal to the value of the address where this instruction is stored. So, for example, if later in the programme there is a statement JMP LOOP, the assembler programme will replace the label LOOP with the actual value of LOOP, which is the address at which this instruction is stored. (For the assembler to recognise this as a label, the label must begin at the first character in the line., in some assemblers a colon ":" follows the label) So if the address at which the instruction is stored is 4F, LOOP takes on the value 4F. If LOOP is used later in the programme, the assembler will give it the value 4F.

The second part is the mnemonic .This corresponds to a particular kind of instruction (opcode sent by the Dispatch Unit). The intention is that the word chosen (by the manufacturers) for the mnemonic is easy to remember, and indicates what the instruction does. In this case, the instruction moves a literal value (one byte) into the register 0, hence MOV.B r0, #80

The third part of the line is an operand (there may be two); in this case the operand is the value 80 (in Hex) and the register r0.

The last part of the line is a comment. This does not affect the actual instruction at all; it is not part of the instruction, and is not assembled; instead it helps the programmer to remember what this part of the program does. The comment is preceded by a semi-colon.

When you have written a programme in assembly language, it actually consists of lots of ASCII characters; this would be stored in a file and called "source code". This then forms the input to a program called an "assembler" (MPASM for the PIC) which can translate the "source code" into machine code. or object code. When the assembler has done its work, this line of source code will have been translated into a binary pattern, associated with a particular address in the programme memory.

Addressing modes

You might also like

LWW Computers LWW ipazzport KP-810-19 Germany + English Language Mini Wireless 2.4GHz 84-Keys Keyboard - Black
PC Accessory (LWW Computers)
  • Expedited Shipping Time 6-9 Days .
  • Standard Shipping Time 15-25 days.
  • Ships from HongKong .
  • Ship By Airmail With Online Tracking Information .
  • If you have any questions, please feel free to contact me .
Your Inner Geek, LLC C Programming with The Programmable Box (Orange-Kit)
Software (Your Inner Geek, LLC)
  • This is the first in a series of educational products that teach C Programming using The Programmable Box
  • Ages 10+, home schooling, classroom instruction, self paced instruction, computer clubs, science projects
  • A fun step-by-step approach where students write interesting programs using The Programmable Box which contains LED s, buzzer, range detector, and other input/output...
  • Extensive step-by-step manual (.pdf), Arduna Nano compatible processor, ultra-sonic range detector, buzzer, 6 colored LED s, potentiometer, momentary contact switch...
  • This is the kit version (also available fully assembled). Visit .your-inner-geek.com for complete curriculum included in instruction manual. 100% Satisfaction guaranteed...

Copyright © . All Rights Reserved