COP 3402 meeting -*- Outline -*- * Assemblers Developed in the 1940s Kathleen Britten (in 1947) see ref. 7 in chapter 7 of Montagne's book ** Overview ------------------------------------------ ASSEMBLY LANGUAGE AND ASSEMBLERS def: *Assembly language* is a language def: An *assembler* translates from to ------------------------------------------ ... that directly manipulates a (virtual) machine's state and in which each statement corresponds to one machine instruction ... assembly language ... machine code ------------------------------------------ ASSEMBLERS VS. COMPILERS Statements correspond to In assembly language: In a higher-level programming language: Expressions correspond to: In assembly language: In a higher-level programming language: Names are abstractions of In assembly language: In a higher-level programming language: ------------------------------------------ ... one machine instruction ... several machine instructions ... must be explicitly programmed with many machine instructions and explicit use of temporary storage ... are implicitly computed with many machine instructions and implicit use of temporary storage ... of locations (of data) and addresses in program space ... of variables, constants or computations (procedures, functions) ** goals of Assemblers and Assembly Language Originally assemblers were called "auto-coders"... why? what do they automate? Q: Having written machine code using numbers, why is that hard? - Have to remember opcode numbers - Have to count for jumps, loads, stores, etc. ------------------------------------------ GOALS OF ASSEMBLERS - Relieve tedium of machine code by: - Help communication between people with: ------------------------------------------ ... - translating names to locations - translating mnemonics to opcodes - translating decimal numbers to binary ... - comments - symbolic names (labels) - translating decimal (or hex/octal) to binary Q: Does an assembly language programmer need to know how the machine's instructions work? Yes! Q: Does a programmer in a higher level programming language need to know that? No, except perhaps to make programs run faster ** How assemblers work ------------------------------------------ BASIC PROBLEM FOR ASSEMBLERS ... JMP ahead ; forward reference ... ahead: ; label How can assembler know the address of the label "ahead"? ------------------------------------------ ... it uses two passes... *** Two pass design ------------------------------------------ TWO PASS DESIGN OF ASSEMBLER Pass 1: count instructions determine address of each label Pass 2: check that all labels are defined generate machine code ------------------------------------------ ... enter label's address in symbol table ... looking up labels as needed *** Relative Jumps ------------------------------------------ RELATIVE JUMPS Additional task for assembler: If computer architecture has jumps to (absolute) addresses Then translate jumps relative to PC into ------------------------------------------ ... jumps to (absolute) addresses We did this in the VM, but the assembler could do it also