User Tools

Site Tools


spo600:assembler_basics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
spo600:assembler_basics [2024/05/14 06:33] – external edit 127.0.0.1spo600:assembler_basics [2025/02/11 11:58] (current) chris
Line 5: Line 5:
 =====  Format of an Assembly Language program  ===== =====  Format of an Assembly Language program  =====
  
-The traditional extension for assembly-language source files is ''.s'' (e.g., ''example.s''), or ''.S'' for files that need to go through the C preprocessor (''cpp'').+The traditional extension for assembly-language source files that will be used as input to an assembler is ''.s'' (or __.asm__ on some platforms), or ''.S'' for files that need to go through the C preprocessor (''cpp'') and possibly the compiler (''cc'').
  
 An assembly-language program consists of: An assembly-language program consists of:
Line 62: Line 62:
 =====  6502 Assembly Language in the Emulator  ===== =====  6502 Assembly Language in the Emulator  =====
  
-The [[6502 Emulator]] provides a very simple assembler for [[6502]] code:+The [[6502 Emulator]] provides a very simple assembler for [[6502]] code. Each line contains one instruction in assembly language, or one of these directives: 
   *  Simple text-substitution macros can be defined with ''define //name// //value//'' like this:   *  Simple text-substitution macros can be defined with ''define //name// //value//'' like this:
 <code> <code>
Line 72: Line 73:
   dcb "A"   dcb "A"
   dcb "T","e","s","t",$20,"4",".",0</code>   dcb "T","e","s","t",$20,"4",".",0</code>
-  *  The current assembly pointer starts at $0600 and increments with output bytes; it can be changed with this syntax:+  *  The current assembly pointer starts at $0600 and increments with output bytes; it can be changed with this directive:
 <code> <code>
   *=$0800</code>   *=$0800</code>
Line 81: Line 82:
  
 On a Linux system, you will need to meet three requirements to get your assembly language program to work: On a Linux system, you will need to meet three requirements to get your assembly language program to work:
-  -  Code must be placed in the ''.text'' section of the ELF file.+  -  Code must be placed in the ''.text'' section of the ELF file. (Think of this as the //program text// rather than //string text//).
   -  Data must be placed in either the ''.rodata'' (read-only data) or ''.data'' (read/write data) sections of the ELF file.   -  Data must be placed in either the ''.rodata'' (read-only data) or ''.data'' (read/write data) sections of the ELF file.
   -  There must be a globally-defined symbol which the linker (''ld'') will use to find the entry point to your program. If the code is being directly compiled by the assembler, this symbol must be ''_start'' -- but if the code is being compiled by gcc, this symbol must be called ''main'' (a preamble will be located at ''_start'' which will then transfer control to ''main'').   -  There must be a globally-defined symbol which the linker (''ld'') will use to find the entry point to your program. If the code is being directly compiled by the assembler, this symbol must be ''_start'' -- but if the code is being compiled by gcc, this symbol must be called ''main'' (a preamble will be located at ''_start'' which will then transfer control to ''main'').
Line 92: Line 93:
   -  Run the linker: ''ld //test//.o -o //test//''   -  Run the linker: ''ld //test//.o -o //test//''
  
-Note that the ''-g'' option assembles the program with symbolic debugging information included.+Note that the ''-g'' option assembles the program with symbolic debugging information included (just as it does in most C compilers).
  
 ====  Compiling an Assembly Language Program using the NASM Assembler  ==== ====  Compiling an Assembly Language Program using the NASM Assembler  ====
Line 100: Line 101:
  
 Notes: Notes:
-   NASM only works with x86 code. +   NASM only works with x86 code. 
-   The source file must be written using NASM syntax (which is substantially different from the GNU assembler syntax). +   The source file must be written using NASM syntax (which is substantially different from the GNU assembler syntax). 
-   The ''-f elf64'' option instructs NASM to assemble the code for a 64-bit target (x86_64). +   The ''-f elf64'' option instructs NASM to assemble the code for a 64-bit target (x86_64). 
-   The ''-g'' option assembles the program with symbolic debugging information included.+   The ''-g'' option assembles the program with symbolic debugging information included.
  
 ====  Compiling an Assembly Language program using GCC  ==== ====  Compiling an Assembly Language program using GCC  ====
spo600/assembler_basics.1715668390.txt.gz · Last modified: 2024/05/14 06:33 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki