Introduccion al asembler

Páginas: 13 (3209 palabras) Publicado: 22 de abril de 2010
An Introduction to the GNU Assembler
The GNU Assembler, part of the GNU Tools software suite, is the assembler used in the Digital Systems Laboratory to convert ARM assembly language source code into binary object files. This assembler is extensively documented in the GNU Assembler Manual (which can be found on your CD-ROM in the gnutools/doc directory). This Introduction is a summary of thatmanual, specifically for the Laboratory.

Example and Template Files
The examples directory and its subdirectories on your CD-ROM contain many examples of assembly language programs that you can study. And you are encouraged to do so! Please see the end of this document for more details. One of the subdirectories in examples is templates. You are strongly encouraged to use the files providedthere as a starting point in writing your computer programs. In particular, the file template.s should be used for all of your ARM assembly language programming. This file, stripped of most of its comments, appears below:
.text _start: .global _start .global main b main: ; Insert your code here mov .end pc,lr ; Return to the caller main ; Executable code follows ; "_start" is required by the linker ;"main" is our main program ; Start running the main program ; Entry to the function "main"

Invoking the Assembler
You can assemble the contents of any ARM assembly language source file by executing the arm-elf-as program. This can be invoked as: arm-elf-as -marm7tdmi --gdwarf2 -o filename.o filename.s Naturally, replace filename with whatever is appropriate for your project. The command-lineoption -marm7tdmi instructs the GNU Assembler that your target CPU is the ARM7TDMI (ARMv4T architecture). The option --gdwarf2 requests the assembler to include information in the output file that is helpful for debugging—it does not, incidentally, alter your program in any way. Chapters 1 and 2, as well as section 8.4, of the GNU Assembler Reference list other command line options. For largerprojects, you should modularise your code into multiple source files. Each source file (which has the extension .s) is then assembled using a command line similar to the one shown. Once you have assembled all of your source files into binary object files (with the extension .o), you use the GNU Linker to create the final executable (extension .elf). This is done by executing: arm-elf-ld -ofilename.elf filename.o Once again, replace filename with whatever is appropriate for your project. If you are using multiple source files (and hence multiple object files), replace filename.o with a list of all object files in your project.

Typing these commands again and again becomes rather tedious (even though the Unix shell allows you to use the Up Arrow key to retrieve previous command lines). Forthis reason, a template Makefile has been supplied that you can modify to suit your own purposes (it can be found as examples/templates/Makefile.template-asm on the CD-ROM). Once you have modified this file (and renamed it to Makefile), all you need to do to recreate the executable is type: make

Assembly Language Syntax
The GNU Assembler is actually an assembler that can target many differentCPU architectures, not just the ARM. For this reason, its syntax is slightly different from other ARM assemblers; the GNU Assembler uses the same syntax for all of the 45odd CPU architectures that it supports. Assembly language source files consist of a sequence of statements, one per line. Each statement has the following format, each part of which is optional: label: instruction ; comment Alabel allows you to identify the location of the program counter (ie, its address) at that point in the program. This label can then be used, for example, as a target for branch instructions or for load and store instructions. A label can be any valid symbol, followed by a colon “:”. A valid symbol, in turn, is one that only uses the alphabetic characters A to Z and a to z (case does matter, ie, is...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Problemas asembler
  • Practica de asembler
  • Asembler
  • Asembler
  • Programa en codigo asembler
  • Ordena una cadena de caracteres asembler
  • Asembler
  • Interruptores de dos para asembler

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS