CPSC 2310 - DAY 3 AUGUST 22, 2016 ================================================================================ High Level Language (HLL) assembly language - one-to-one correspondence with machine instructions. represented by 0/1 patterns Compiler - A translator that translates statements written in HLL into assembly code, performing various optimizations and register allocations along the way. Interpreter - A translator that translates and executes all at the same time. Assembler - A program that takes assembly instructions and converts them into machine code that the computer's processor can use to perform its basic operations. The result is called an object file. Compiler calls Assembler ASSEMBLY LANGUAGE ----------------- . an instruction is composed of .operation code (opcode) .operands (names of registers and/or information needed to generate a memory address) labels are placeholders to addresses each label must be unique symbolic program (human readable) ----------> machine code (binary) symbolic labels -> memory addresses opcodes -> bit patterns in instructions operand id -> bit patterns in instructions immediate operand values (constants) -> bit patterns in instructions Assemblers have a two-pass structure. .instructions can have forward or backward references to labels .note that a forward reference requires a two-pass assembly structure since you encounter a "use" before its definition and thus cannot immediately translate the label into its memory address Two pass structure because FORWARD REFERENCES! thus: pass 1 - increment a location counter as you read each assembly language statement and collect any label definitions into a symbol table with the corresponding location counter values pass 2 - translate the assembly language statements using the symbol table. SIMPLIFIED: pass 1 - build the symbol table & keep track of location counter. pass 2 - Translates into machines code, DOES NOT EXECUTE! LOCATION COUNTER HOLDS THE COUNTER FOR WHERE WE ARE IN THE PROGRAM DURING TRANSLATION! (NOT EXECUTION!) SYMBOL TABLE ----------------------------------------- | NEXT | 103 | | X | 106 | | ... | | ----------------------------------------- IF you keep all the translated code in memory, you can translate in one pass. ACCUMULATOR MACHINE -------------------