Three examples of assemblers for real machines are:
1. MASM assembler
2. SPARC assembler
3. AIX assembler
The programs of x86 system views memory as a collection of segments.
Each segment belongs to a particular class corresponding to its contents. The commonly used classes are:
During program execution segments are addressed via an x86 segment register.
In most cases:
Code Segments are addressed using register CS.
Stack Segments are addressed using register SS.
* The loader automatically sets CS and SS when the program is loaded. * CS is set to indicate the segment that contains the starting label specified by the ‘END’ statement of the program. * SS is set to indicate the last stack segment processed by the loader. * The programmer can specify explicitly the segment register to be used, else the assembler selects one. * Data segments are addressed using DS,ES,FS and GS.
* By default the assembler assumes that all references to data segments use register ‘DS’, but the following statement with the assembler directive ASSUME tells the assembler to assume that register ES indicates the segment DATAEG2. ASSUME ES:DATASEG2|
* Thus any references to labels that are defined in DATASEG2 will be assembled using register ‘ES’. * It is also possible to group several segments together. The following instruction would set ‘ES’ to indicate data segment DATASEG2. MOV AX,DATASEG2MOV ES, AX| * BASE directive tells the SIC/XE assembler the contents of register ‘B’/ * ASSUME directive tells MASM the content of a segment register. Jump instructions are assembled is two ways
1. Near Jump
2. Far Jump
* It is a jump to a target location in the same code segment. * Assembled instruction for NEAR JUMP is 2 or 3 bytes.
* It is a jump to a target location in a different code segments. * Assembled instruction for FAR JUMP is 5 bytes.
Pass 1 of x86 assembler
It is more complex than SIC as, operands has to be analyzed in addition to operation codes.
Segments of MASM
* Segments of MASM source program can be written in more than 1 part. * If a segment directive has a name as a previous defined segment, then it is said to be the continuation of that segment. * The assembly process combines all the segments together. * These segments are similar to program blocks.
* Assembler handles the references between the segments.
* External references between separately assembled module is handled by the linker. MASM directives
* MASM directive PUBLIC function is similar to EXTDEF.
* MASM directive EXTRN function is similar to EXTREF.
* The SPARC assembly language program is divided into units called sections. * The assembler provides a set of predefined section names, such as the following: .TEXT
* The programmer can switch between sections at any time in the source program by using assembler directives. * The assembler maintains a separate location counter for each named section.
Similarity between Section and program blocks
* Each time assembler switches to different section, it also switches to the location counter associated with that section. In this way sections are similar to program blocks.
Difference between sections and program blocks
* References between different sections are resolved by the linker in the case of sections, and by the assembler in the case of program blocks. Symbols used in the program
* Local symbol
* Global symbol
* Weak symbol
Object file of SPARC
* The object file written by the SPARC assembler contains translated versions of thee segments of the programs and a list of relocation and linking operations that need to be...