Introduce the "assembler" assignment
Specifically, introduce the high-level structure of the program that you will create
Describe the stages of program development
Handwritten diagram showing use of "as" assembler and "gcc" linker
Note Executable and Linking Format (ELF)
Handwritten diagram showing use of "myas" assembler and "gcc" linker
Diagram showing structure within the myas assembler: input(), your code, and output()
See file main.c
Note (unfortunate) reliance on global variables
Subset of SPARC assembly language
No preprocessor directives; file suffix is .s, not .S
In particular, referring to the "SPARC Assembly Language Summary" handout...
Sections
data
bss
textNo rodata section, programmer-defined sections
Directives (alias pseudo-ops)
.section
.skip
.align
.byte
.half
.word
.ascii
.asciz
.globalNo .common, .empty (rarely used anyway) (see Paul p. 255 if interested)
Mnemonics (alias executable instructions)
Load and store: all
Shift: all
Arithmetic: all
Logical: all non-synthetic, mov, tst, not
No clr, btst, bset, bclr, btog
Integer branch: almost all
No bz (same as be) and bnz (same as bne)
No annul bit
Control: jmpl, call, ret, save, restore, nop, sethi
No retl, set
Trap: ta, rett
Expressions
Constants
.skip 4 .word 18 .word 18, 3 save %sp, -96, %spConstants and operators
.skip 4 * 100 .word (18 + 5) * 3 save %sp, (-92 - 8) & -8, %spLabels
call label1 bg label2 sethi %hi(label3), %l1 or %l1, %lo(label3), %l1But not:
.word label5 call label6 + 16 bg label7 - 12 ... %hi(label8) + 24 ... ... %hi(label8 + 24) ...Most of which are unusual anyway
Example: app_01fibonacci.s
[Give handout]
[Give quick demo]
Note: uses only the specified assembly language subset
Lines 57-58: no set instruction
Line 125: Label in ble instruction
Line 116, 138: Label in call instruction
Line 57: Label as operand of hi operator
Line 58: Label as operand of lo operator
Interface defined in input.h
See The In-Memory Assembly Language Program handout
Handwritten example instructions to illustrate each structure
Interface defined in output.h
Four data structures: symbol table, data section, bss section, text section
Symbol table
A table containing bindings
Contains 1 binding for each label
key = label name (a string)
value = pointer to Elf32_Sym structure
(1) Section (data, bss, text)
(2) Offset into section
(3) Local vs. global
(4) Sequence number (unique across all sections)Implemented using Hanson's Table ADT
Data section
A slab of memory containing an appropriate sequence of bytes
Bss section
A slab of memory containing zeros
Text section
A slab of memory containing an appropriate sequence of bytes -- 4 bytes for each instruction
Relocation information
Label within an expression must be converted into an address
Some labels can be converted by assembler
Example: line 125: ble LL12
Some labels must be resolved by linker
Example: line 138: call printf
Assembler must mark such labels by creating a relocation structure
See lecture notes
See ELF manual
Need not know thoroughly to write your portion of the assembler
See the Assembler Assignment: Development Stages summary sheet
See the summary sheet
Copyright © 2002 by Robert M. Dondero, Jr.