90 likes | 193 Views
Assembly Files. Sample program. .text This is an assembler DIRECTIVE, it tells the compiler that this section contains assembly instructions .global main
E N D
Sample program • .text • This is an assembler DIRECTIVE, it tells the compiler that this section contains assembly instructions • .global main • This must be present to tell the assembler to expect this to be called from external sources. It is customary to put it at the beginning of the program. • main: • This is where your program goes. • init: • Here go the steps to initialise memory locations, registers etc. used in the program. Your code needs to be sure everything is set correctly to begin execution. • j exit • This should be the last executable step in your program. It returns control of the REX board to the monitor program. • .data • Comprised of your data items, lookup tables, and the like. Initialised when the code is loaded.
Assembly Language Programs • Assembly Language Programs consist of: • Assembly Instructions • Labels • Directives • Comments
Labels • Labels refer to a location in memory. • Can associate a label with a WRAMP instruction or memory allocated for storage • e.g. • All WRAMP programs must start with a main label • Labels are used so the programmer does not have to keep track of memory addresses. .global main main: add $3, $4, $5
Comments • WRAMP comments are on a line basis • Any text on a line after a # is treated as comments • e.g. add $3, $4, $5 # This is a comment
Assembler Directives • Declarations are examples of Assembler Directives • Assembler Directives tell a program (assembler or compiler) how to create a program and not how to execute it • Directives also exist to allow data and instruction to be put in separate areas of Memory WRAMP C .bss int1: .word int2: .word char1: .word int int1, int2; char char1;
Section Directives • .text Indicates that this section contains assembly instructions • .data This section contains data, i.e. allocates memory space and initialises it to some value. • .bss This section allocates memory but does not initialise it. This allows bigger chunks to be allocated than in .data. (bss = block started by symbol).
Space Allocation Directives • .word n Allocates one word of memory and initialises it to the value n. Can be used in .bss without the n. • .ascii “str”Allocates enough space for a string and initialises it. • .asciiz “str”Allocates and initialises enough space for a string plus a null terminating character (0x0) • .space n Allocates n words but does not initialise the space in the .bss section
.global Directive • .global declares symbols to be accessible by outside the current file. • .global main defined the entry point into the program.