Upload
asher-doyle
View
218
Download
3
Embed Size (px)
Citation preview
Joseph L. Lindo
Assembly Programming
Sir Joseph LindoUniversity 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
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
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
Joseph L. Lindo
Data
+ and -
Registers
Assembly Programming
Data Transfer Mnemonics
Data
Joseph L. Lindo
Data
+ and -
Registers
Assembly Programming
Addition andSubtraction
+ and -
Joseph L. Lindo
Assembly Programming
--end--
Sir Joseph LindoUniversity of the Cordilleras
Joseph L. Lindo
Assembly Programming
--end na to--
Sir Joseph LindoUniversity 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
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.
Joseph L. Lindo
General Purpose Registers
Registers
Joseph L. Lindo
MOV
Data Transfer
Moves data fro source to destinationSyntax:
MOV destination,source
Rules: Destination should not be an immediate
operand
Joseph L. Lindo
MOV
Data Transfer
.datacount BYTE 100wVal WORD 2
.codemov bl,countmov al,wValmov ax,wValmov count,almov ax,countmov eax,count
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
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.
Joseph L. Lindo
XCHG
Data Transfer
.datavar1 WORD 1000hvar2 WORD 2000h
.codexchg ax,bxxchg ah,alxchg var1,bxxchg 3,100xchg eax,ebxxchg var1,var2
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
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
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
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
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
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
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
Joseph L. Lindo
MOV and XCHG
Comprehension Check
Joseph L. Lindo
INC, DEC ADD and SUB
Comprehension Check
Joseph L. Lindo
Assembly Programming
--end--
Sir Joseph LindoUniversity of the Cordilleras
Joseph L. Lindo
Back
Integer Expressions
Joseph L. Lindo
INC and DEC
MOV
Reserved Word and Identifiers
Directives
Character and String Constants
ADD and SUB
More
XCHG