Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

28
Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras

Transcript of Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Page 1: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

Assembly Programming

Sir Joseph LindoUniversity of the Cordilleras

Page 2: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

Data

+ and -

Section 1

Assembly Programming

Registers• Named storage locations inside the CPU, optimized for speed.

• High speed storage locations directly inside the MPU

Registers

Page 3: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

Data

+ and -

Section 1

Assembly Programming

Registers• There are 8 general purpose registers, 6 segment registers, Eflags registers and instruction pointers.

Registers

Page 4: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

Data

+ and -

Registers

Assembly ProgrammingInstruction

Operand Types:Immediate – a constant integer (8,

16, or 32 bits)Register – the name of a register is

converted to a number and encoded within the instruction

Memory – reference to a location in memory

Data

Page 5: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

Data

+ and -

Registers

Assembly Programming

Data Transfer Mnemonics

Data

Page 6: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

Data

+ and -

Registers

Assembly Programming

Addition andSubtraction

+ and -

Page 7: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

Assembly Programming

--end--

Sir Joseph LindoUniversity of the Cordilleras

Page 8: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

Assembly Programming

--end na to--

Sir Joseph LindoUniversity of the Cordilleras

Page 9: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

CPU vs MPU

Online Task

Provide the differences between CPU and MPU. Post it as comment on our FB Group. (COAL)

Due on February 21, 2012

Page 10: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

General Purpose Registers

Registers

Primarily used for arithmetic and data movement.

Each register could be addressed as either 8, 16 or 32 bit value.

Page 11: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

General Purpose Registers

Registers

Page 12: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

MOV

Data Transfer

Moves data fro source to destinationSyntax:

MOV destination,source

Rules: Destination should not be an immediate

operand

Page 13: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

MOV

Data Transfer

.datacount BYTE 100wVal WORD 2

.codemov bl,countmov al,wValmov ax,wValmov count,almov ax,countmov eax,count

Page 14: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

MOV

Data Transfer

Code AX BX

MOV ah,10

MOV ax,35

MOV bh,al

MOV bx,1234

MOV bl,04

MOV bh,55

Page 15: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

XCHG

Data Transfer

XCHG exchanges the values of two operands. Syntax:

XCHG operand1,operand2

Rules:

At least one operand must be a register.

No immediate operands are permitted.

Page 16: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

XCHG

Data Transfer

.datavar1 WORD 1000hvar2 WORD 2000h

.codexchg ax,bxxchg ah,alxchg var1,bxxchg 3,100xchg eax,ebxxchg var1,var2

Page 17: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

XCHG

Data Transfer

Code AX BX

MOV bx,4810

MOV ax,35

XCHG bh,bl

XCHG bh,ah

MOV bl,04

XCHG bl,al

Page 18: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

INC and DEC

Add and Sub

Add 1, subtract 1 from destination operandoperand may be register or memory

INC destinationLogic: destination destination + 1

DEC destination Logic: destination destination – 1

Page 19: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

INC and DEC

Add and Sub

.datamyWord WORD 1000hmyDword DWORD 10000000h

.codeinc myWord dec myWordinc myDwordmov ax,00FFhinc axmov ax,00FFhinc al

Page 20: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

INC and DEC

Add and Sub

Code AX BX

MOV ah,10

MOV al,35

INC al

MOV bx,1234

DEC bl

INC bh

Page 21: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

ADD and SUB

Add and Sub

ADD destination, sourceLogic: destination destination + source

SUB destination, sourceLogic: destination destination – source

Same operand rules as for the MOV instruction

Page 22: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

ADD and SUB

Add and Sub

.datavar1 DWORD 10000hvar2 DWORD 20000h

.codemov eax,var1add eax,var2add var2,var1 add ax,0FFFFhsub 1,2sub var1,var2add eax,1sub ax,1

Page 23: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

ADD and SUB

Add and Sub

Code AX BX

MOV ah,10

MOV al,35

ADD ah,al

MOV bx,1294

SUB bl,ah

ADD ax,bh

Page 24: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

MOV and XCHG

Comprehension Check

Page 25: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

INC, DEC ADD and SUB

Comprehension Check

Page 26: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

Assembly Programming

--end--

Sir Joseph LindoUniversity of the Cordilleras

Page 27: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

Back

Integer Expressions

Page 28: Joseph L. Lindo Assembly Programming Sir Joseph Lindo University of the Cordilleras.

Joseph L. Lindo

INC and DEC

MOV

Reserved Word and Identifiers

Directives

Character and String Constants

ADD and SUB

More

XCHG