10
Computer Science 101 How the Assembler Works

Computer Science 101 How the Assembler Works. Assembly Language Programming

Embed Size (px)

Citation preview

Page 1: Computer Science 101 How the Assembler Works. Assembly Language Programming

Computer Science 101

How the Assembler Works

Page 2: Computer Science 101 How the Assembler Works. Assembly Language Programming

Assembly Language Programming

Page 3: Computer Science 101 How the Assembler Works. Assembly Language Programming

Translation and Loading

• Assembler – Translates a symbolic assembly language

program into machine language

– Tasks performed• Convert symbolic op codes to binary• Convert symbolic addresses to binary• Perform the assembler services requested by the

pseudo-ops• Put the translated instructions into a file for future use

Page 4: Computer Science 101 How the Assembler Works. Assembly Language Programming

Translation and Loading (continued)

• Op code table– Alphabetized list of all legal assembly language op codes

and their binary equivalents

• In assembly language:– A symbol is defined when it appears in the label field of

an instruction or data pseudo-op

• Pass– Process of examining and processing every assembly

language instruction in the program, one instruction at a time

Page 5: Computer Science 101 How the Assembler Works. Assembly Language Programming

Structure of the Opcode Table

Page 6: Computer Science 101 How the Assembler Works. Assembly Language Programming

Translation and Loading (continued)

• First pass over source code– Assembler looks at every instruction

• Binding– Process of associating a symbolic name with a

physical memory address

• Primary purposes of the first pass of an assembler – To bind all symbolic names to address values– To enter those bindings into a symbol table

Page 7: Computer Science 101 How the Assembler Works. Assembly Language Programming

Generating a Symbol Table

Page 8: Computer Science 101 How the Assembler Works. Assembly Language Programming

Generating a symbol table

.beginin xload zerocompare xjumpgt endifsubtract xstore xendif: output xhaltx: .data 0zero: .data 0.end

Page 9: Computer Science 101 How the Assembler Works. Assembly Language Programming

Translation and Loading (continued)

• Location counter– Variable used to determine the address of a given

instruction

• Second pass– Assembler translates source program into machine

language

• After completion of pass 1 and pass 2– Object file contains the translated machine language

object program

Page 10: Computer Science 101 How the Assembler Works. Assembly Language Programming

Generating machine code

.beginin xload zerocompare xjumpgt endifsubtract xstore xendif: out xhaltx: .data 0zero: .data 0.end

load 0000store 0001clear 0010add 0011increment 0100subtract 0101decrement 0110compare 0111jump 1000jumpgt 1001jumpeq 1010jumplt 1011jumpneq 1100in 1101out 1110halt 1111

Source program

Opcodetable