Professional Documents
Culture Documents
A12 SystemSoftware
A12 SystemSoftware
Program Development
Compiler: a) Code generator: creates symbolic assembly or machine code. b) Programming productivity is improved. Assembler: a) Translates symbolic language source into machine code. (There is a one-to-one relationship between symbols/labels and machine opcodes/addresses.) b) Higher code optimization and mission critical code timing. Interpreter: a) Executes a source language program. b) Poor performance (3x-20x) but replaces non-existent hardware. c) Processes a source language program and executes the equivalent machine code. Some compile to an intermediate format, p-codes , then execute a p-code engine
Compiler: Converts HLL source into assembly language source/equivalent intermediate file or target language. i.e. name.c to name.s Compiler Phases: pre-processor, code gen, optimization Examples: cc hello.c hello.o (C -> ASM/OBJ)
Assembler: Translates symbolic language source into machine language binary format and creates an object file, i.e. name.s to name.o/obj Uses a one-pass or two pass strategy. Forward references are a problem for one pass assemblers. A group of common object modules in a single file, i.e. name.lib Examples: asm hello.s hello.o (ASM -> OBJ)
Loader/Debug Loader: Places/relocates an executable file into memory and starts its execution. Examples: load hello.out (EXE->MEM)
System Software:
Source Files to Program Execution
hello.cpp HLL-Source Compiler hello.asm Assembly-Source Assembler hello.obj Machine-Object Code Linker hello.exe .o, .obj + library.obj(s) ( .lst,) [+.cmd] .s , .asm Librarian Machine-Object Code files .a, .lib .c, .cpp, .h (preprocessor, code gen, optimize)
Machine-Executable .out, .exe Code ( .lst, .map, .xref) Loader Relocated Memory Image . Execute (entry-point)
# exit to kernel
General Macro model/template .macro macro_name ( $p1, $p2, .. $pn) # your code goes here using macro macro_arguments .end_macro
Reminder: SPIM does not currently support a user macro capability
3)
Assembly Language Features and Limitations 1) Where and why assembly used: a) Interfaces: input/output, i.e. device-drivers b) Performance, size, optimization, i.e. OS/kernel critical c) Dedicated uses, limited resources(pwr, RAM, cost), i.e. embedded computers d) Normally used close to hardware architecture level. 2) Why not used a) Slower development cycle. Takes more lines of code for same task. Has a bigger expansion factor for lines of code. b) Lack of structure, programming oversight, built in checking c) More time to understand and difficult to maintain d) If not WELL documented, special program tricks are not obvious. e) Difficult to test and debug because there are no enforceable programming guidelines f) Dedicated to one machine. Must be rewritten for each new processor
RISC and Pseudo Instructions 1) Assembler create/treat common variations of machine language instructions as if they were a single instructions in their own right. 2) Cost/penalty for pseudo-instructions is to reserve one of the general purpose register, $at, for use by assembler. 3) 4) Helps minimize the number of actual machine instructions needed in H/W. Requires assemblers/compilers to be very machine H/W aware.
2) 3)
1)
2)
Steps for loading executable modules: 1) 2) 3) 4) 5) Reads the executable files header Allocates space from OS Copies segments into memory, with relocation if required. Copies arguments onto stack Jumps to a start up routine, entry_point, that copies
MIPS standard segment memory assignments; Segment Address vect = 0x0000 0000 - 0x003F FFFF .text = 0x0040 0000 .data = 0x1000 0000 - 0x1001 0000 $gp = 0x1000 8000 .stack = 0x xxxx xxxx - 0x7FFF FFFF $sp = 0x7FFF FFFF .ktext = 0x8000 0080 .kdata = 0x9000 0000 - 0x9001 0000 Heap Management, brk/malloc. Data => Heap => Stack
1) 2) 3) 4) 5) 6) 7)
System Software:
Organization of a simple 2-pass assembler
Pass 1: loct = 0 locd = 0 Read Line y .directive? y label? Update locx Pass 2: loct = 0 locd = 0 Update label table (label, locx) Process Directive .end
loct = 0 locd = 0 Read Line y .directive? .word init locd Process Directive .space locd .global ref/def .end copy images to object file
build instruction opcode to instruction operation fields registers to instruction operand fields immediate to instruction imm field label to instruction address field update relocation table update object file image. Update loct