unit 3 assembler and processor

23
Assembly Language Prakash Khaire UTU

Upload: abha-damani

Post on 06-May-2015

1.550 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Unit 3   assembler and processor

Assembly Language

Prakash KhaireUTU

Page 2: Unit 3   assembler and processor

Assembly LanguageAssembly Language A programming language that is one step away from machine

language.

Each assembly language statement is translated into one machine instruction by the assembler.

Programmers must be well versed in the computer's architecture, and, undocumented assembly language programs are difficult to maintain.

It is hardware dependent; there is a different assembly language for each CPU series.

Page 3: Unit 3   assembler and processor

Assembly LanguageAssembly Language

It was introduced in 1952 Helped to overcome machine language

programmingDefinition : “A language that allows

instructions and storage locations to be represented by letters and symbols instead of numbers is called assembly language or symbolic language”

Page 4: Unit 3   assembler and processor

Assembly Language ModelAssembly Language Model

…add r1,r2sub r2,r3cmp r3,r4bne I1sub r4,1I1: jmp I3…

ALUPC

Registers Memory

Page 5: Unit 3   assembler and processor

Assembly Language InstructionsAssembly Language Instructions

Built from two piecesAdd R1, R3, 3

OpcodeWhat to do with

the data(ALU operation)

OperandsWhere to get data and put the results

Page 6: Unit 3   assembler and processor

Types of OpcodesTypes of Opcodes

Arithmetic, logicaladd, sub, multand, orCmp

Memory load/storeld, st

Control transferjmpbne

Complexmovs

Page 7: Unit 3   assembler and processor

OperandsOperandsEach operand taken from a particular

addressing mode:Examples:Register add r1, r2, r3Immediate add r1, r2, 10Indirect mov r1, (r2)Offset mov r1, 10(r3)PC Relative beq 100

Reflect processor data pathways

Page 8: Unit 3   assembler and processor

Advantages over Machine LanguageAdvantages over Machine Language

Easier to understand and useEasier to locate and correct errors.Easier to modifyNo worry about addressesEasily relocatableEfficiency of machine language

Page 9: Unit 3   assembler and processor

Limitations of Assembly LanguageLimitations of Assembly Language

Machine DependentKnowledge of hardware requiredMachine level coding

Page 10: Unit 3   assembler and processor

Architecture of 8086Architecture of 8086

Page 11: Unit 3   assembler and processor

Registers in 8086 CPURegisters in 8086 CPU

There are four general purpose registers AX [divided into AH/AL] – the accumulator registerBX [divided into BH/BL] – the base address registerCX [divided into CH/CL] – the count registerDX [divided into DH/DL] – the data register

Other registersSI – source index registerDI – destination index registerBP – Base pointerSP – Stack pointer

Page 12: Unit 3   assembler and processor

Registers in 8086 CPURegisters in 8086 CPU

This registers are of 16 bits and divided into two 8 bit registers For Example

If AX = 0011000000111001b then AH = 00110000b and AL=001111001b

Registers are located in CPU, Segment Registers

Used for special purpose pointing at accessible blocks of memory It stores any data Four segment registers during execution

CS – Points the segment storing the current program DS – Points the segment where variable are defined ES – Extra Segment register, depends on the usage of coder SS – Points to the segment containing the stack

Along with general purpose registers, segment registers work to access any memory value.

Page 13: Unit 3   assembler and processor

FlagsFlags FLAG : The FLAG register is the status register in the Intel 8086

microprocessor that contains the current state of the microprocessor. This register is 16 bits wide. carry flag (CF)- indicates a carry after addition or a borrow after subtraction, also

indicates error conditions. parity flag (PF)- is a logic “0” for odd parity and a logic “1” for even parity. auxiliary carry flag (AF)- important for BCD addition and subtraction; holds a carry

(borrow) after addition (subtraction) between bits position 3 and 4. Only used for DAA and DAS instructions to adjust the value of AL after a BCD addition (subtraction).

zero flag (ZF)- indicates that the result of an arithmetic or logic operation is zero. sign flag (SF)- indicates arithmetic sign of the result after an arithmetic operation. overflow flag (OF)- a condition that occurs when signed numbers are added or

subtracted. An overflow indicates that the result has exceeded the capacity of the machine.

Page 14: Unit 3   assembler and processor

OffsetOffset

The offset address in an 8086/8088 is the logical address that the program "thinks about" when it addresses a location in memory.

The Execution Unit (EU or CPU) is responsible for generating the offset address.

The Bus Interface Unit (BIU), on the other hand, takes the offset address and adds it to four times the selected segment register value in order to determine a real address, which is now 20-bits in length.

Page 15: Unit 3   assembler and processor

Registers in 8086 CPURegisters in 8086 CPU

Programmers access various memory locations on combining BX, SI, DI and BP registers. The value in segment registers[CS, DS, SS,ES] is called “segment” The value in purpose registers [BX, SI, DI, BP] is called “offset”

For Example DS contains value 1234h and SI contains the value 7890h it can also be recorded as

1234:7890

Two special purpose registers IP – Instruction Register Flags Register – determines the current state of the processor

Page 16: Unit 3   assembler and processor

Registers in 8086 CPURegisters in 8086 CPU

IP works along with CS register and points to the currently executing instruction

Flags register is modified by CPU, while performing mathematical operations

Page 17: Unit 3   assembler and processor

Assembler Design ApproachAssembler Design Approach

Assembler generates object code.Role of assembler – Translates the source

code into target codeDuring this translation process it uses various

table likeMachine Opcode TableSymbol tableLiteral table

Page 18: Unit 3   assembler and processor

Assembler Design ApproachAssembler Design Approach

Machine Opcode Table It holds opcode used by the processor for

different instructions mnemonics

MnemonicMnemonic size Opcode

Holds various instructions

Size of instructions in bytes

Size of instructions in bytes

Page 19: Unit 3   assembler and processor

Symbol TableSymbol Table

It is data structure used by assmebler It keeps into account attributes of the identifier and other

information. Attributes : type, value, scope and address

It also performs the function of book keeping. It is composed of multiple word entries in fixed format

NameName Value Type

Page 20: Unit 3   assembler and processor

One Pass AssemblerOne Pass Assembler

Does everything in one passProblem: How do we handle forward references?Could eliminate forward references

easy for data – just define the data areas before they are referenced

not easy in code – how do we handle selection or loop statements which have forward jumps?

Two types of one pass assemblers: produce object code directly in memory produce object program for later execution

Page 21: Unit 3   assembler and processor

One Pass AssemblerOne Pass Assembler

Assembler generates object code instructions as it scans source program

If an operand symbol has not yet been defined operand address is set to 0 in instruction symbol is entered into the symbol table (unless it is already

present) entry is flagged to indicate the symbol is undefined address of instruction is added to list of forward references

associated with this symbol When symbol definition is encountered

forward reference list is scanned, and proper address is inserted in any instructions previously generated (in memory)

Page 22: Unit 3   assembler and processor

One pass assembler that produces object programsOne pass assembler that produces object programs

Use the same procedureWhen the definition of a symbol is encountered

if instruction which made the forward reference is still in memory, then fix it

if not, the instruction has already been written out in a Text record, so generate a new Text record with the correct operand address

(could also use a modification record)The loader will fix up the address field

Page 23: Unit 3   assembler and processor

One pass assembler that produces object programsOne pass assembler that produces object programs

Problem : Forward Reference It be eliminated by declaring variable before using them However, elimination can’t be done easily because sometimes

program needs a forward jump.