assembly
TRANSCRIPT
![Page 1: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/1.jpg)
1
![Page 2: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/2.jpg)
2
A FEW BASIC A FEW BASIC INSTRUCTIONSINSTRUCTIONS
![Page 3: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/3.jpg)
Presented By
![Page 4: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/4.jpg)
Contents
![Page 5: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/5.jpg)
There are over a hundred instructions in the instruction set for the 8086 CPU.
Here we discuss 7 of the most useful instructions for transferring data and doing arithmetic.
The discussed instructions are…….. MOV,XCHG,ADD,SUB,INC,DEC,NEG.
5
IntroductionIntroduction
![Page 6: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/6.jpg)
MOVMOV Transfer data
◦ Between registers◦ Between register and a memory location◦ Move a no. directly to a register or a memory
location Syntax MOV destination, source
ExampleMOV AX, WORD1
6
How?
![Page 7: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/7.jpg)
XCHGExchange the contents of
◦ Two registers◦ Register and a memory location
Syntax XCHG destination, sourceExample
XCHG AH, BL
7
AL
BL
00 1A
05 00AH AL
BH BL
How?
![Page 8: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/8.jpg)
Legal Combinations of Operands for MOV Legal Combinations of Operands for MOV And XCHG And XCHG
Destination Operand
Source Operand
Legal
General Register
General Register
YES
General Register
Memory Location
YES
Memory Location
General Register
YES
Memory Location
Memory Location
NO
Destination Operand
Source Operand
Legal
General Register
General Register
YES
General Register
Memory Location
YES
General Register
Segment Register
YES
General Register
Constant YES
Memory Location
General Register
YES
Memory Location
Memory Location
NO
Memory Location
Segment Register
YES
Memory Location
Constant YES
MOVXCHG
![Page 9: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/9.jpg)
ADD InstructionADD InstructionTo add contents of:
◦ Two registers◦ A register and a memory location◦ A number to a register◦ A number to a memory location
ExampleADD WORD1, AX
9
How?
![Page 10: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/10.jpg)
SUB InstructionSUB InstructionTo subtract the contents of:
◦ Two registers◦ A register and a memory location◦ A number from a register◦ A number from a memory location
ExampleSUB AX, DX
10
How?
![Page 11: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/11.jpg)
Legal Combinations of Operands for Legal Combinations of Operands for ADD & SUB instructions ADD & SUB instructions
11
Destination Operand
Source Operand Legal
General Register General Register YES
General Register Memory Location YES
General Register Constant YES
Memory Location General Register YES
Memory Location Memory Location NO
Memory Location Constant YES
![Page 12: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/12.jpg)
INC & DECINC & DEC INC (increment) instruction is used to add 1 to the
contents of a register or memory location.◦ Syntax: INC destination ◦ Example: INC WORD1
DEC (decrement) instruction is used to subtract 1 from the contents of a register or memory location.◦ Syntax: DEC destination ◦ Example: DEC BYTE1
12
Destination can be 8-bit or 16-bits wide.Destination can be a register or a memory
location.
![Page 13: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/13.jpg)
13
INC WORD1
DEC BYTE1
INC & DECINC & DEC
How?
How?
![Page 14: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/14.jpg)
NEGNEGUsed to negate the contents of destination.Replace the contents by its 2’s complement.Syntax:
NEG destinationExample:
NEG BX
14 How?
![Page 15: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/15.jpg)
ExamplesExamples Consider instructions: MOV, ADD, SUB, INC, DEC,
NEG A and B are two word variables Translate statements into assembly language:
15
Statement Translation
A =-( A+1)
MOV AX,A INC AX NEG AX MOV A,AX
B= 3B-7
MOV AX,B ADD AX,B ADD AX,B SUB AX,7 MOV B,AX
Example:1
Example:2
Statement
Translation
A = B – A-1
MOV AX,B SUB AX,A DEC AX MOV A,AX
Example:3
![Page 16: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/16.jpg)
16
ApplicationApplication .datamsg1 DB 'Input Any number From 1 To 9:$' ; Data segmentmsg2 DB 'The Series Summation Is:$'.code
main proc mov AX,@DATA ; Data segment mov DS,AX lea dx,msg1 ;showing msg1 mov ah,9 int 21h mov ah,1 ;taking input int 21h xor ah,ah sub al,30h XOR CX,CX ;loop same as input mov cx,ax XOR bx,bx
## A series summation of n numbers where 1<=n<=9
![Page 17: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/17.jpg)
17
sub bx,0Ah add ax,1 ;counter=ax=3 CMP bx ,39h ;bx<39h JL DISPLAY sub bx,0Ah add ax,1 ;counter=ax=4 CMP bx ,39h ;bx<39h JL DISPLAY DISPLAY: add al,30h mov cl,al lea dx,msg2 ;showing msg2 mov ah,9 int 21h mov ah,2 mov dl,cl int 21h mov dl,bl int 21h
ApplicationApplication TOP: add bx,cx ;adding LOOP TOP mov ah,2 mov dl,0Dh int 21h ;printing new line mov dl,0Ah int 21h xor ax,ax add bx,30h CMP bx ,39h ;bx<39h JL DISPLAY sub bx,0Ah add ax,1 ;counter=ax=1 CMP bx ,39h ;bx<39h JL DISPLAY sub bx,0Ah add ax,1 ;counter=ax=2 CMP bx ,39h ;bx<39h JL DISPLAY
![Page 18: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/18.jpg)
18
![Page 19: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/19.jpg)
? ?
<
![Page 20: Assembly](https://reader035.vdocument.in/reader035/viewer/2022070514/5881219d1a28abb9388b70bb/html5/thumbnails/20.jpg)