Home

Assembly Language Programming

Assembly Language Programming

 

 

Assembly Language Programming

    • Introduction to the Assembler

An assembly language is a language that controls the primitive operations on binary data within a computer.
An assembly language program is made of two types of statements: executable instructions and assembler directives.

  • An executable instruction is one of the processor’s valid instructions and is translated into the appropriate machine code form by the assembler.
  • Assembler directives cannot be translated into machine code; they indicate the assembler specific information about the program and its environment. They link symbolic names to actual values (EQU), allocate storage for data in memory (DS), set up pre-defined constants (DC) and control the assembly process (ORG, END)
      • Simple “Hello World” and binary count-down

 

Let’s look at an example of an assembly language program that prints a zero-terminated string on simulates a binary counter using an array of 8 LEDs:

delay  equ                 500                 *500ms delay between counts
start   equ                 %11111111 *starts count down from 255

*Display to LCD

            org                  $4000                        *Program origin
            lea                  msg,a0          *a0 points to the starting memory location of zero-
                                                           *terminated string to display
trap                #7                   *displays the zero-terminated string pointed by a0
*on the top line of the LCD Display
*Countdown using LED
           
move.w         #start,d1      *d1 <- $FF
loop    move.b          d1,$30000    *LED array <- [d1]
            move.w         #delay,d0     *d0 <- $1F4
            trap                #$d                *Delay by the number of milliseconds specified in d0
            dbra               d1,loop          *Decrement d1 and goto to loop if result greater
* than zero
            trap                #0                   *returns control of the CPU back to the Robot’s OS

msg    dc.b                'Hello World',$0      *zero-terminated string
end
4.1.2 Program organisation

The assembly language program is written in four columns (or fields):

  • an optional label that must begin in column 1;
  • an up-code instruction field;
  • an field for the associated operands;
  • and an optional comment field used by the programmer to document a program.

A word beginning in the left-most column is a programmer-defined label and is used by the assembler as a reference to that line. E.g.: delay, start, loop and msg.
A line beginning with an asterisk in its first column is a comment and is entirely ignored by the assembler.

Consider the line:
loop                            move.b          d1,$30000                *LED array <- [d1]

This is the comment field and is entirely ignored by the assembler.

 

“move.b d1,$30000” is the actual instruction to be assembled.

 

“loop” is a label that refers to this line.

 l

 

The assembler requires at least one space to separate the label and comment field from the actual instructions.

4.1.3   Decimal, Hexadecimal, binary and ASCII representation

  • A number without a prefix in an assembly language program is treated as a decimal value. e.g.:  delay  equ 500.
  • Prefixing a number with a $ symbol indicates a hexadecimal value. e.g.: org $4000
  • Prefixing a number with a % indicates a binary value. e.g.: start equ %11111111
  • Enclosing a text string in single quotes indicates a sequence of ASCII characters. eg.: msg dc.b            'Hello World'.

 

      • Assembler listing file

The program is assembled producing a listing file. The following listing file contains the original assembly language and the machine code (in hexadecimal) produced by the assembler.

 

 

 

 

 

 

 

 

    • Main assembler directives

 

We now describe the five major assembler directives.

      • EQU

 

  • The equate directive links a name to a value, making the program easier to read. For example, it might be better to equate the name “delay” to $1f4 and use this name in the program, rather than writing $1f4 and leaving the reader to figure out that it is the number of milliseconds to wait between consecutive counts.
  • The use of names makes the code more meaningful to the programmer and facilitates future modifications and updates.
  • Most 68000 assemblers permit the programmer to employ an expression as valid name.
      • DC

 

  • DC means define a constant and is qualified by .B, .W or .L, depending on the size of the constant (8, 16 or 32 bits).
  • The constant defined by this directive is loaded in memory at the current location.
  • E.g.: the assembler directive DC.B ‘Hello World’,$0 loads the bytes $48, $65, $6C, $6C, $6F, $20, $57, $67, $72, $6C, $64 and $00 into memory starting at address $401E.
  • Constants can be stored in consecutive locations by separating each one with a comma.
      • DS

 

  • The define storage directive, DS, reserves storage locations in memory. It has a similar effect to DC, but no information is stored in memory.
  • DC is used to set up constant values that are to be loaded into memory before the program is executed, whereas DS reserves memory space for variables that are generated by the program at runtime.
  • DS is also qualified by .B, .W or .L and takes the same types of operands as DC.
  • A label in the label field can be used to refer to the first address of the defined storage. The label references the lowest address of the define storage value.
      • ORG

 

  • The origin assembler directive sets up the value of the location counter that keeps track of where the next item is to be located in the target processor’s memory.
  • The operand following ORG is the absolute value of the origin.
  • ORG can be located at any point in a program.
      • END

 

  • The end directive indicates the assembler that the end of a program has been reached and that there are no further instructions or directives to be assembled.

 

 

    • Conclusion

At this stage, we have some familiarity with the organisation of a 68000 assembly language program. We saw that programs are composed of assembler directives and executables instructions and we described five of the most important directives: EQU, DC, DS, ORG and END. Executable instructions are composed of an up-code and operands. We will later explain the main mechanisms indicating the address of operands to the assemblers.

 

REFERENCES

  • A. Clements; Introduction to Computer Architecture and Assembly language, In: 68000 Family Assembly Language; pp. 61-75; PWS Publishing Company; 1994.
  • Dr. Mike Brady, Microprocessor Systems 1, dept. of Computer Science, Trinity College Dublin: http://www.tcd.ie/Engineering/Courses/BAI/JS_Subjects/3D1/.
  • Look on the Web at http://www.mee.tcd.ie/~assambc/3D1.

 

 

Source: http://www.mee.tcd.ie/~assambc/3d1_l04n.doc

Web site to visit: http://www.mee.tcd.ie

Author of the text: indicated on the source document of the above text

If you are the author of the text above and you not agree to share your knowledge for teaching, research, scholarship (for fair use as indicated in the United States copyrigh low) please send us an e-mail and we will remove your text quickly. Fair use is a limitation and exception to the exclusive right granted by copyright law to the author of a creative work. In United States copyright law, fair use is a doctrine that permits limited use of copyrighted material without acquiring permission from the rights holders. Examples of fair use include commentary, search engines, criticism, news reporting, research, teaching, library archiving and scholarship. It provides for the legal, unlicensed citation or incorporation of copyrighted material in another author's work under a four-factor balancing test. (source: http://en.wikipedia.org/wiki/Fair_use)

The information of medicine and health contained in the site are of a general nature and purpose which is purely informative and for this reason may not replace in any case, the council of a doctor or a qualified entity legally to the profession.

 

Assembly Language Programming

 

The texts are the property of their respective authors and we thank them for giving us the opportunity to share for free to students, teachers and users of the Web their texts will used only for illustrative educational and scientific purposes only.

All the information in our site are given for nonprofit educational purposes

 

Assembly Language Programming

 

 

Topics and Home
Contacts
Term of use, cookies e privacy

 

Assembly Language Programming