Assembly Language Programming Rev792011

25
tulisnota.blogspot.com ASSEMBLY LANGUAGE PROGRAMMING Dat a Tr ansfer Ins tr uction, Logic Instr uction, Arithmetic Instr uction

Transcript of Assembly Language Programming Rev792011

Page 1: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 1/25

tulisnota.blogspot.com

ASSEMBLY LANGUAGE

PROGRAMMINGData Transfer I nstr uction, Logic I nstr uction,Arit hmetic Instr uction

Page 2: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 2/25

tulisnota.blogspot.com

DATA TRANSFER INSTRUCTION

I t provide to move data ei ther between i tsinternal r egister or between an internalregister and a storage location in memory

Page 3: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 3/25

tulisnota.blogspot.com

DATA TRANSFER INSTRUCTION (CONT.)1. Move byte / word (MOV)

Example: MOV DX, CS – move thecont ent s of CS int o DX

2. Exchange byte / word (XCHG)

Example: XCHG AX, DX – exchangethe cont ent s of the AX and DX

3. Translate byte (XLAT)

Page 4: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 4/25

tulisnota.blogspot.com

DATA TRANSFER INSTRUCTION (CONT.)4. Load effect ive address (LEA)

Example: LEA SI , EA – load SIregister wi th an offset address value

5. Load data segment (LDS)

Example: LDS SI , [200H]

6. Load ext ra segment (LES)

Page 5: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 5/25

tulisnota.blogspot.com

LOGIC INSTRUCTION

I t has inst ruct ion for per forming the logicoperation AND, OR, Exclusive-OR andNOT

Example: AND AX, BX – causes thecontents of BX to be ANDed wi th t hecont ents of AX. The resul t is reflected bynew cont ent of AX

Page 6: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 6/25

tulisnota.blogspot.com

LOGIC INSTRUCTION (CONT.)For instant , if AX contains 1234H and BX

contains 000FH, the resul ts is

1234H · 000FH = 0004H

The resul t is stored in dest inat ionoperand AX = 0004H

Page 7: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 7/25

tulisnota.blogspot.com

LOGIC INSTRUCTION (CONT.)Table of logic inst ruct ion

Mnemonic Meaning Format Operation

AND Logical AND AND D, S (S)· (D) = (D)OR Logical OR OR D, S (S) + (D) = (D)

XOR Logical Exclusive-OR XOR D, S (S) (D) = (D)

NOT Logical NOT NOT D (D) = (D)

Page 8: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 8/25

tulisnota.blogspot.com

LOGIC INSTRUCTION (CONT.)Example:

MOV AL , 0101 0101 B

AND AL, 0001 1111 B OR AL, 1100 0000 B

XOR AL, 0000 1111 B

NOT AL

Page 9: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 9/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION

1. Addition

Register addit ion

Immediate addit ion

I nstruction Comment

ADD AL, BX AL becomes the sum of AL + BL

ADD CX, DI CX becomes the sum of CX + DI

I nstruction Comment

ADD BL, 44 BL become sum of BL + 44H

ADD BX, 35AF BX becomes the sum of BX + 35AFH

Page 10: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 10/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)1. Addit ion (cont .)

Inst ruct ion Comment

ADD [BX], AL The data segment memory byte addressed by BXbecomes the sum of the data segment memorybyte addressed by BX + AL

ADD CL, [BP] CL becomes the sum of the stack segment byteaddressed by BP + CL

ADD BX, [SI + 2] BX becomes the sum of the data segment word

addressed by SI + 2, plus contents of BX

Page 11: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 11/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)1. Addit ion (cont .)

I nstruction Comment

ADD CL, TEMP CL becomes the sum of CL plus the data

segment byte TEMP

ADD BX, TEMP[DI] BX becomes the sum of BX plus the contentsof the data segment array TEMP plus offsetDI

ADD [BX + DI], DL The data segment memory byte addressed

by BX + DI becomes the sum of t hat byteplus DL

Page 12: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 12/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)1. Addit ion (cont .)

Example:

MOV DL, 12 ADD DL , 33

Page 13: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 13/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)2. Subtraction

Register subt ract ion

Immediate subtract ion

I nstruction Comment

ADD CL, BL CL becomes the difference of CL – BL

ADD AX, SP AX becomes the difference of AX – SP

I nstr uction Comment

ADD DH, 6F DH become di fference of DH – 6FH

ADD AX, CCCC BX becomes the difference of AX - CCCCH

Page 14: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 14/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)2. Subtract ion (cont .)

Subtract ion wi th borrow

Inst ruct ion Comment

SBB AH, AL AH becomes the di fference of AH – Al – carry

SBB AX, BX AX becomes the di fference of AX – BX – carry

SBB CL, 3 CL becomes the di fference of CL – 3 – car ry

SBB [DI], AL The data segment byte addressed by DI

becomes the dif ference of t hat byte minus Al – carry

SBB DI , [BP + 2] DI becomes the difference of t he stack segmentword addressed by BP + 2 and t he content s ofboth the DI register and carr y

Page 15: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 15/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)2. Subtract ion (cont .)

Subtract ion (others)

I nstruction Comment

SUB [DI ], CH The data segment memory byte addressed by DIbecomes the difference of the data segmentmemory byte addressed by DI – CH.

SUB CH, [BP] CH becomes the difference of the stack segmentmemory byte by BP – CH.

Page 16: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 16/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)2. Subtract ion (cont .)

Subtract ion (others)

I nstruction Comment

SUB AH, TEMP AH becomes the di fference of AH minusthe contents of memory byte TEMP locatedin t he data segment

SUB DI, TEMP[BX] DI becomes the difference of DI minus thecontents of data segment s ar ray TEMP

plus offset BX

Page 17: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 17/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)2. Subtract ion (cont .)

Example:

MOV CH, 22

SUB CH, 44

Page 18: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 18/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)3. Multiplication

8 bi t mult ipl icat ion

I nstruction Comment

MUL CL The unsigned number in AL is mul t ipl ied by CL;the product is found in AX

IMUL DH The signed number in AL is mult ipl ied by DH; theproduct is found in AX

MUL BYTEPTR[BX]

The signed number in AL mult ipl ied by the bytestored in data segment at the address indexed byBX; the product is found in AX

MUL TEMP The unsigned number i n AL is multiplied by 8-bitnumber at memory location TEMP; the product isfound in AX.

Page 19: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 19/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)3. Mult ipli cat ion (cont .)

16 bi t mul t ipl icat ion

I nstruction Comment

MUL CX The unsigned number in AX is mul t ipl ied by CX;the product is found in DX and AX

IMUL DI The signed number in AX is mult ipl ied by DH; theproduct is found in DX and AX

MUL WORDPTR [SI]

The unsigned number in AX mul t ipl ied by the 16bit number in data segment at the address point edto by SI ; the product is found in DX and AX

Page 20: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 20/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)3. Mult ipli cat ion (cont .)

Example 8 bi t :

MOV BL, 5

MOV CL, 10

MOV AL, CL

MUL BL

MOV DX, AX

Page 21: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 21/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)3. Mult ipli cat ion (cont .)

Example 16 bit :

MOV BX, 0805

MOV AX, BX

MOV CX, 0604

MUL CX

Page 22: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 22/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)4. Division

8 bi t mult ipl icat ion

I nstruction CommentDIV CL The unsigned number i n AX i s di vided by CX; t he

quot ient i s in AL, and the remainder is in AH

IDIV BL The signed number in AX is divided by BL; thequot ient i s in AL, and the remainder is in AH

DIV BYTEPTR[BP] The unsigned number in AX divided by the byte instack segment stored at the address located by BP;the quot ient i s in AL , and the remainder is in AH

Page 23: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 23/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION (CONT.)4. Division

16 bi t mul t ipl icat ion

I nstruction Comment

DIV CX The unsigned number in DX and AX is divided byCX; the quot ient is in AX, and the remainder is inDX

IDIV SI The signed number in DX and AX is divided by SI ;the quot ient is in AX, and the remainder is in DX

DIV BYTEPTR[BP]

The unsigned number in DX and AX divided bythe word stored in data segment at memorylocation DATA (a word of information)

Page 24: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 24/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION

(CONT

.)4. Division

Example 8 bi t :

MOV AL, 12

MOV CL, 3

MOV AH, 0

DIV CL

Page 25: Assembly Language Programming Rev792011

8/4/2019 Assembly Language Programming Rev792011

http://slidepdf.com/reader/full/assembly-language-programming-rev792011 25/25

tulisnota.blogspot.com

ARITHMETIC INSTRUCTION

(CONT

.)4. Division

Example 16 bit :

MOV AX, 3E14

MOV DX, 0030

MOV BX, 0805

DIV BX