You are on page 1of 14

8086 80486 Instruction set ② ALP

Different
-

MOV options

location R -

Register
E Swap the word at memory 24000N R ← M

with 25000 n
M -

Memory
M R

I -
Immediate data
24000h 2 Memory is

Ag

]
:
organised R ← R
byte
24001 n
but we need M ← I

to swap word

, , , , g, , any
µ ← ,
,

M←M①
25000h
so we swap

2500 In 2 bytes

M0VDsT,sRC_
① Initialize segment register
contents of source to destination
→ Copies tire

MOV AX , 2000h → No
flags affected
Size

MOV DS , AX Serc ⑧ dat m u s t be some
of
.

Source can be R M @ I
② Initialize offset resisters
→ ,

be
# Can't transfer → Destination can R
@ M
MOV SI 4000

directly form
n
,

MOV DI 5000h menus


to
,
one
another
INC Destination ( Instruction) ( this uses ALU )

① Transfer data from ref to men temporarily


→ Destination -

Register @ memory location ( specified in

Mov BX § I ] 24
diff ways )
,

MOV DX [ DI ]
, →
( AF ,
of ,PF ,
Sf ,zF affected ,
CF not affected )

Store back the data in mem


Ex : INC BL

INC BX
Mov [SI ] ,
DX

I]
MOV
④ ,
✗ →
Similarly DEC Destination

→ INC increments the content of destination by 1

E¥ :
MOV BX ,
2000h E± Bx has 56 ,
after INC ,
it has 57 n ,

MOV DI ,
10h →
DEC decrements tire contents of destination by I.

B- ✗ + DI ]
MOV AL ,
[
/
Inc Dec
the contents of a memory location
MOV DI , Lon

ani→mtim%""t①*
data

specify the
size in
memory
MOV [ BX + DI ] AL
, the

use assembler directives →
assembler and n ot to Mp
fbit
Keeps

put
PTR PTR
AI Copied , data from DS : 2010 to DS : 2020 ☒ BYTE PTR * WORD * DWORD

d- d- T '

← 2010 @
DS : 2020 DS :

it whatever 32 bit for MP


means
,, bit
he memory location
I'm
talking about now

INC resists tire


is be
pointing In
,

going to
assembler
towards a byte 18 bit ) knows tie size
But for M
, you
need

E INC WORD PTR [BX ] directive


to give
INL BYTE PTR [ BX]
( update only 1 byte of data
?⃝
?⃝
BX -

1000m DS -2000h
SI
]⑥
,
INC SI -

2001

INC DI DI -
4001
21000 FF

21001 00
'

DEC CX CX -0031 ]① To show that one

byte of data has been

]
JNZ ✗1
transferred
NXT :
" " ""
① " "" " ""

✗ 1 is the branch
Bit

210004
lover
00

Bit
21001 01 higher
Machine Code

For instruction ②
10111000 40 D8 40

(
00 00

① 1000 I 110 11011000 8 F- D8


00
21000
20
101 I 11 10 8 E 00

②[
00 zo
21001 00
40
to 111111 ooo yo 8f 00

③( 10 111001 32 00
B. 9 32 00

Flags

]
④ ( 8A I C
100010110 00011 too

±" " ° " " ^ "" ±" B" " " " " "" °&
③[
" " "° " ° " " " " "

is also
Cf 46
Of → of 0 →
but 01000110

⑥[
-

→ 0
affected
-

47
S F
internally
O 0 1000111
SF →
-

→ -
O

→ zf -
0 → ZF -

I it is
not
( 01001001 49

→ Pf -
1 ( follows only low byte) → PF -

I reflected
⑧[ 01110101 75 displacement
→ Af -

I

Af -

I displacement

Branch Instructions ( conditional taraxch instruction ) * Mp will always point towards the next instruction that is

same to be executed
→ going
[ Jump
.

JE / JZ Displacement (-128101-127) if Equal /


to
Jump ifzao]

* JNEIJNZ Displacement C- 128 to -1127) [ -
not -
1 - Not]
displacement =) 0000 En → Address it has to
go
to

talk about conditional branching the conditional



Generally when we ,

°°°÷
"

→ Address
current
branch instructions are
going
to ex a m i n e some flag -

→ which is -

g
E JZ examines ze ro flag
so
,
it branches to a particular address provided the zf is set

JNZ branches to location @ the program control


* a
memory
is transferred to a
memory location provided the ZF is reset
ADD
-

Destination Source
,

→ positive displacement is when


you skip some instructions and

m ove forward .

→ Negative displacement
is
you more backward .
* ( source ) + ( Destination ) → ( Destination)

be I
/ RIM specified by of

8bitdisplaame@
p source may any one

the 24 addressing modes

tests the condition


→ Doesn't affect any flag rather
Destination RIM
P
specified by
be
may a
any one

of the
flag .

E± 12346 .

If JZ 6

- of the
123461-6 = 1234 Cn
24
addressing methods .

Destination in instruction cannot


Both ④
an
source
f Copy a block of data from one
memor y
a re

be memory locations
to another memory a re a -

from 42000ha 5-0 data .

bytes 32h
to 44000h * gonna ⑧ Destination must be of same
size .

As All flags affected


!
MOV AX , 4000N count P
]
( is
① ✗
.

-
resister
MOV DS , AX normally
(labels
Ex=ple
:
MOV 2000
can have
MOV CL 73h 0111 0011
SI
]
,
, ② value )
any
MOV DI 4000
, MOV BL
,
Yfn 0100 I 111

] ③ Store count so
CX 0032,1
Labels MOV
,
ADD CL BL
XT ⑦
,

Mov BL ,§I ] ] BLE 4000 : 2000

MOV CDI ] ,
BL ]⑤ 4000 : 4000 = BL
?⃝
AI 0010g ✗1 [ SI ]
:
Result in CL = C2 1100 : MOV AL
n >

(
,

Plinth
( 19yd if unsigned -62A if signed )
^" ^ "
Increment
any

g)
the
In , g,
affect gag
]
won't
want to of DI
* If you
use
unsigned form , ignore
the
INC → They

cc
else DEC
for signed ,
consider it .

JNZ ✗1

CF = 0
,
Pf -0
-

,
AF = 1
,
zf = 0
,
SF = 1
,
of =L JNE

INC BL
✗ 2 →

[Jump if no
carry ]

✗ 2 : MOV ④ I ] ,
BL →
Carry is moved to next byte

( ie
7th byte after 6 byte
ADC Destination Source , ( Acted with Carny instruction calculation )

P ( Sowa) -1 ( Destination) +
( ( f) →
( Destination)

* useful for multi -

byte addition of data Subtract

SUB Destination Source


E
,
ADD two data ok size each 6 bytes
) ( Destination )
(Destination) (
' , ,
0
, -

source →

98 34 AB Ef FA ①
AI 56

71 f- 3 67 90 10 21
① SBB Destination ,
Source (Subtract with borrow )
3C 1B ( Sorce ) ✗ f) ( Destination )
1 0 A 27 BE 00
(Destination) -
-

Source Destination

Lower byte yoooo FA →


④← 41000 21
EI :
MOV BX , 8021h

SUB BX , 8190h

/
40001 Ef 41001 10

40002 AB 41002 90

40003 56 41003 67 Ars : BX = 8021-8190


-

40004 34 41004 f- 3
7

higher byte
40005 98 41005 71
f

☒ to 12 I
⑨ 80 2 I

-
8 1 90 1- 7 E 7 0

* Even first instruction can be ADC by clearing


¥-91 ¥-1
the CF before starting the addition
°
.

zf -0 CF -1
zf 0 (f O AF -0

-0J
-
-

, ,
, , ,

Pf -

✗ SF -1
OF pf × sf -

1. of - 0
CLC flag )
-

( clear
, , ,
* carry -

I
ignore matters
bits
bye 16
with 8 bit
Add 2- 6 byte nos stored in location 20000h
nos .

store the result starting from


an d zlooon

location add of
21000h
Q write a
program
to an
array bytes stored

the result
Ans : MOV AX 2000N in memory starting at 40000h and store

,
-

in 41000h
MOV DS, AX
.

No of elements in the
.

array sod
MOV SI 0000N
,
AI MOV AX ,
4000 n D8
0040

MOV DI 10001A Mov DS , AX 8 F- D8


,

5od= 32h
Mov CL ,
06 n - 6 byte data MOV SI
,
0000h BE 00 ① o

BF 00 lo
MOV DI 100011
MOV BL 00 → Clear BL to have
carry
,

, B. 932 00
CX
of 6M byte MOV , 0032m
( ( ( B] 00
Mov BL , ooh

BL -

O for adding
Mov Bn
,
BL →
Bn
-
o
for Larry 8A FB
✗1 : ADD BL
,
[ SI ] 02 Ice
yyiseve E ORG 0000h

¥?? ??
73 yy
✗✗ " " e

g)
DATAI 25
'

NC BH DB

✗ z :
fyrg DATAZ DB 1000100lb
DATA } DB 12h
DEC CX 49

ynz , , , , on , o , , ,
data

string of
89 ID DATAY DB czsq , ,

MOV [DID BX
ORG 0018h
is
location
that memory
41000 DATAS
DB
? → It
means

So a t the END ,
FD rolled DATAS
4100 1 03
This is how data is initialized in the data segment .

=) 32m 0018 what is i n this


00n→
0010
0000 lqn No idea

}
is
0001 0011 35m location but n a m e
89N * TAE

0012 39h '

18h 12h
000 ' '
ooo ascii equivalents of 2591
-

00016h 0013 31
No idea n

-02N
-
yY
faafdntnis as
data

000 12h
directed
an orbs
point per
xx

E ORG 0000h
'

MS 42 DB
'
123456 →
string of data

MSG } DW 6667N
data I db 12,3 - three numbers ( not string )
'

db
'

db 11110000 b
MASM Assembler Directives

data 2 dw 12,13
P Assembler directives a re n ot converted into machine dw ↳ usn
dd 300N
code but rather assembler makes
language use

DB 9Dvp(ffnT→ Duplicate ffn


of it in order to convert the
assembly language Y
L

L * this means duplicate 9

Dup directive
is no of
bytes ffn
-

with
to machine language .

used qabyje duplicates


to assembler which data created
* Kind of hints that you give

assembler ALP to 's ② is


helps to convert 001
0
31

)
Assembler takes these
.

]
32 45
directives and stores the
33 23
Data Declaration ( Directive ) m oo data directly . It doesn't

)
35 it
03 write for
( Quad) program
a
.

* DB , DW DD DQ
, 36 oo

Define Define Define word IT ( Ten) 67


]
00

Byte word Dowdle 66 FF

/
Label ol FF

E
9

DATA 't DB Usn ,


35N ,
7-
y①→ specify
In
MASM
n
'
02

03
] FF

ff
taken 61 ] ff
Data , Dw noon ,> n zzzzn as data

magnet
,
,
, , , , ,

DATA } DD 237567A Bn
decimal 0C Ff

|
is
00 Ff
b for FF
* Take
OD
*
Define byte is used for indicating binary
'
'

b "

data * Take
whether a
particular happens
alphabets
to be a byte / word @ double word

☒ ORG 0000h → It means anything that follows


this directive will be stored

starting location 0000N


from
?⃝
Directive
Bx=
[
f- QU Indirect MOV BX , VALI → Mor BX > 0030

"
Adem [ BX ]
Equate directive equates a
symbolic name to a value MOV AL , →
AL=①
value
offset
Inari
AddM[
* Not stored in
memory .
It replaces the value wherever MOV BX , offset DATY →
It means

its name
appears in
program
.

MOV AL ,[ BX ]
of DATY
B✗=o@
COUNT EQU to →
A
CONST F- One 20h
Direct

An
-0A c- MOV Ah
,
COUNT AddM[M0V AL ,
DATY →
AL Direct Addressing
-10 ← MOV AL CONST
AL ,

ADD AH AL
2A c- ,

An
-
-

MASM
Program Models

phynaevs.logicalsegmentat.io#ÉÉ?oÉ]
easels
is labelling
E ORG 0010 n * Eau ,

data segments -

your y
count f- 00
32N is labelled
✓ At " f- QU * DB labels
0030h location
DAT 1 DB 45h ,
67m , 100,1A
'
you
memory
G segments
WRD DW 10h 0910h
,
3500h , "
DD P block called physical
DATI 0902N A of memory of discrete
size
-
a

ALL EQV 32m


✓ "

DAT 3
DW 2 Duplo ) segment .

ORG ALL
physical

* the number of bytes in a


memory segment is

DATY DB 56N
processors @
ORG 64K 16 4 bit
VALZ
to locations for bit gigabytes for 32
- -

CÉÉ¥ssors
Resents
res DB ioiupc ? ) →

DWRD DD 01020304N
a.
*
care .
# Generally 64K
¥hs lomax size)
fond


what
"

DATL 45 DAT 4 56 A variable sized block of memory


-
-
called a
logical
's code @ data
segment occupied by
"
67
program a .

T

RES
#
64
×
data
41
logical
code segment

WRD 10 logical
00
✗ segment

00 ✗ $ Program can be written in blocks .


35

10


09

Logical Segments
DATZ 02
① WRD ooze Oy
09
00 3D 03
00

Logical segments components of


:
003 f- 02 contain the 3 a
program
00
003 F 01

DAT 3 00 → code

00 → data
→ stack

in
*
Mapping of logical segments to actual physical segments memory
sT
.

MOV SI DAT } →
,
(Needs to be done )

→AL=#
"
0010+1 = 0°

MOV AL DATA 1 with actual physical addresses


,
* Load segment registers
.

→BÉgg±gg
0010-14 0014

AddM
to the same
=

Indirect MOV BX , DA -11+4 $ MASM has assembler directives do .

ADD BX , 20h →
B✗=00 ☒ Segments defined in
two
ways ⇐ ( MASM does it in two ways)
Mov AL
@× ] →
µL- simplifiedsegmentdirect.rs#
,
→ we'll use this tmoyhout course

Effective Address
LEA Load
→ full
segment definitions

[
Indirect LEA Bx ,
DAT y →
( It 'll not move data
it
resister Ratner
pddmis @✗ I into
.

Mov AL →
,
will move
displacement Models ( Program Models )
into register)
0030 ) models available MASM assembles ranging
( B- ✗
to
=
* there a re
many
from Tiny to Huge .

model (declare model ) the MODEL statant


designate
use
* To a
a
,

followed by the size of the memory system .

offset ± Displacement
Effective Address =
#
E . MODEL TINY
* TINY model requires that all program and data

the is
fit into one 64K segment .

( the rest of memory


not available fortune program )

CS
resist
( also
ensures
• CODE defines code segment is updated )
data segment ( and assembler automatically

DATA defines tuedata segment

STARTUP shows best unis of the updates
the

end of program
f- ✗ IT indicates the

Yimou "
Ent

64K # Both logical ② physical


30000h
code segment/Data All of that
segments
.

Segnetlstacnsegnct
is fixed into I 64K
3Ffffn
space .

Ex 1 :

model tiny

data

DATA 1 23

]
DB

DATA 2 DW 9999h dht Shot


DW 9999
DATA }
ARRAY DW 01,02/03,04 ,
05
,
06,07 ,
of

• Code

startup
MOV BX , DATA 2 B ✗ = 9999

MOV CX
,
DATA }
MOV DATAI , BL

Mov DL DATA 2 DL -99 n


,

MOV DI
,
0002h DI -
00002 n

Mov AX
,
ARRAY [ DI ] AX -

0002h

• exit
end → to end assembly

F-✗ 2 : MODEL TINY


• DATA

DATA 1 DB 23h

ARRAY DW 01,02/03,0%05,06 07,08 ,

• CODE
STARTUP
ARRAY DX 0001

MOV
-

DX
,

MOV CL DATA 1
cL -

23h
,

BX address of ARRAY
BX , OFFSET ARRAY
-

MOV

AL
CBX ]
MOV AL / -
01

• EXIT

END

From
find the greatest signed no a
write an ALP to .

set lo bytes stored at afar -

The greatest no must


of
.

be stored a t location RES .


To check result of compare -
arithmetic

Jh / JNLE IF ④ of QANDZFO Greater / Not less than equal


-

JGEIJNL SF ④ of -0 mean equal / Not less

/ JNGE / Not great equal


sf④ Of -1
JL Lesser

TILE / JNG Sf ④ Of -
'
④ 2ft Lesser equal / not greater

JE / 52 zf -
l eared / zero

Zf -0
JNEIJNZ not equal / ze ro

compare Instructions

provided signed
is subtraction that changes
Compare Instructions a
*

the flag bits from


only write Alp to find the greatest signed no a
- .

an

set of lo bytes stored a t afar -

The greatest no .
most


Cmp Destination Source location RES
, be stored at .

→ CMP CL [ BX ] two locations


, ✗ memory

AI model tiny
CMP AX , 2000h location ⑧


✓ memory
data
[ DI ] ,Cn immediate data

Cmp 06M 07h 47h


9th 02h 83N Ffn 75m

ARRAY DB , , , 17h ,9on
, , , , ,

→ CMP SI ,
DI RES DB ?


Code


startup
CMP CX ,AX LEA BX ARRAY ( BX is n ow
pointer )
,

CF zf l Mov currently pointing


CX =
BX
-0 -

SF -0 CL
,oAn towards fist data
,

(✗ < BX Cf -

I zf -0 Sf -

I MOV AL
,
[ BX ] → At -91 ie , 9in

DEC CL
(✗ >
BX CF -

o zf -
o
sp -

o
B- ✗
INC
for
unsigned)
PF , Alf data x2 : Cmp Ah [ Bx ] (
Of ,
-

depends on ,

,
,
.ae
THE ✗I ~

MOV AL ,[ BX ] →
Al -02/75
-


greatest
To check result of compare
-

Logical ✗ 1 : INC
BX
DEC CL

JA
/ JNBE Cf oadzifo Above / Not Below @ efhal ×,
g- Nz
-

below /No carry MOV RES AL


JAE
/ JAB / JNCCF -0 Above Equal /Not ,

exit
/ equal

JBIJCIJNAE CF -
l
Below Carry / Not Above
end
T.BE/JNACF-l@Zf-1 Below efnal / Not above

JE /JZ zf - I Equal / zero

T.ME/JNZzf -0
Not Equal / Not Ze ro

provided unsigned
Program Models align 2

dat 2
'

db
'

Model Type Description . code

tiny All the data and code fit in one



startup
segment Tiny programs a re written in
al dat
t.com
.

M ov
,

the must
which means program
yal Es add dat
be originated a t location 100N
Keven
⑧ ) Ss

• exit
Contains two segments one DS of 64K
small end
-

and CS of 64k bytes


bytes one

bit
* flat Model Special type tiny Model for 32
-

of

MemayM①
-

* we can also use model Tiny with 32 bit .

6,135,55 ,ES→
OBYFN
Psp Mode Tiny
Model Type Description 0100h
Ip →
Code
Contains one DS of 64 kbyte ad and
month 010 Ch
Medium Data
FFFFN b/c
Ex 05 I 1
of for large programs Not
(
CS
-

processor
' '

16 bit
→a
I 1
it 'll
the ahah "
hence
compact one CS contains program and is
" Data fffEn every tis
the data Ex System & assume bits )
contains
gone 16⑨ Ffff )

-

of Dg processing gp
.

going f-
( fff
⑧ DS assembler FFFEN b
of done by the
number CS
large allows any
oh only
I "→
so ,
.ve

µµswÉ
can
but the Ds , contain
same large m ay

§
" Ye as -

" " →

"allows
_plvYffiub①
"
" " "" "
^^ "" "
"" "
PS P
oak
m o re

)
tram
I Memory Map
0B6on
:¥÷ 0000h
es

Model
oB6znÑÉ% Data
0020m
• Tiny some
Stack is initialized
onion )
• data
0 B- 62h Ss :sp→ on , on ( sp at
'
'

dat I db a

align 2 →
It
aligns the data to
the even boundy ( even location) * After compiling model tiny ,
an executable file
'

b
'

dat 2 db '
'

at 04 odd
'
EI : a
( skips" , created having .COM extension .

Ab
'
°
dat 2 c -
'
at OEN
b

i at 10M
A Program Segment Prefix : A part of .com file .

code
-

-
startup

A set of instructions which a re
given to the
operatives
n, yay ,
gym www.gayn.wm.waygggn.ua
add dat 2
,
al handled ( From 0000N to 0100N)
.

• exit - Mov
21
INT
End * PSP is created for any executable file ( for
asm
@ exe )

& why CS oB6on ⑧ DS oB62n ?

Model small of bytes


program required only only those
• → m ay no .
.


stack → has to be declared
in small Data started immediately from oB62n .

• data
'

dat 1
'

db a
bit
with 8 bit @ 16

the structure module 32,76846 bit ) ( If working respectively)


of data
-

main
j this is a
-

directives
; using simplified segment • of set indicating operation could not be done
-

are
NEH
All flags affected ⑧
pesigleopeod
q.my
MODEL SMALL this statement is need before
; of
of ✗ 86

gone
'

other simplified instructions


( segmg.FM
use Ac
it can new
mostly atoptowels )
outed
you
E
.

inalitd)
'

get directives
; segment NEG REX
.

NEG YTEPTRLSI ]
kilobyte stack
• STACK ; use default 1 -

a DATA ; Begin data segment

Place data declarations here


j

• CODE
; Begin code segment string Instructions
start-up code
STARTUP ; Generate handle
equipped with
* 80×86 to
special instructions

is
here
Place instructions
-
- - -
-
; string operations .

exit code
Generate
• EXIT ; * string
:
A series of data words (@ bytes ) that reside in

END consecutive locations


memory .

* Operations :
m ove ,
scan
,
compare

Logical Instructions # Mors / MOVSB / Mors w/ MOVSD

L d d '
d
for / 6 bitter stirs Shi Shi
word
# Debt Source shisofwods of bytes of words ) of D.
bit )
AND ,
aol.it ( 32
for 32 up,
shisof Dwods
A logical AND , each bit in the source with the

corresponding bit in the destination * Copies byte @ word @ double word from location
-

a a
.

* CF ② OF both become ze ro
(irrespective of insult in the data segment to a location in the extra segment .

Source DS
Zf
affected ( * SI
:
* Pf ,
Sf an d Pf will make sense -

only for 8 b i t operations


* Destination
-
f- 5 : DI
* Af undefined
* No flags Affected
* Parallelly OR
,
✗ OR

☒ for multiple -
byte @ multiple -

word moves
,
the count to be

in cx register .

# NOT Destination
decrement by 1
* Byte transfer ,
SI @ DI increment @

P
Complements each bit in the destination and stores
- @ -
by
2

p word -
,
4
the result back into the destination
-
.

PD -

- ,

* No Flags Affected
Mnemonic Meaning Format Operation Flags Affected
AL
E NOT

clear DF CLD ( Df ) 0 Df
CLD

NOT BX
STD set DF STD ④ f) ← I DF
NOT BYTEPTRISI]

Selects auto increment D=o

# Df @ D
D= I
NEG Destination auto decrement


Direction flag
* resisters
Does 2 's complement the data in the destination for the DI & SI
on
operation
result back into duris string ops
and stores the the destination .

D with stings
* Cannot 's is used only
find 2 -128 ( 8- bit ) @
complement of
* CLD ⑧ STD → No operands sH→sg① * Lois affects no
Flags
with operands the kind of
(If instructions
no ,

addressing is
implied / implicit addressing ) # STOS
CLD implies that I'm working with Direction bbf -

p stores AL Ax @ EAX into the ex t r a


, @g

segment memory
at
offset address indexed

E± Copy block of data from memory


by
are a
a one
DI register .

memory a re a 50 DATA
jo another *
After store
-

contents if
of
13=01
'

DI
ng ine

AVI •
model tiny decile D= I

indicates whatever is this program , it


386 →
instruction
support 80386

to
is going
set architecture
Ting ) E STOSB f- 5. [ DI ] AL DI -

( Ds D I -11
-
• data same as
F- S in
,
2
AMYL db 09h ,
ben den Ofsh STO SW .

_
AX
, ,
- - -

,
- -

array
2 as 50
deep 6) grasp ! -
F- AX 4

Code
affects

P Stol no FLAGS .

• startup
M ov CX
, 32h

lea Si
, array I F- write an ALP to
fill a set of 100
memory
tea di array
2
Now locations
'

DESI
starting displacement
'
, at with

✗1 : MOV BL , CSI ] CLD value f- 6h


Moves
data .

MOV ⑤I] BL
Mors B
-
INC SI
AI Modelling
,

rep DI •

IN C SI Ina

INC DI d
#rh rest by

DATA

DEC

JNZ
'✗

✗1
Estuary
prefix ( reps
it
he
'll
Motb
DAT 1 DB 100 DUPC ? )
cause * ↳
Code
instruction till
.

Exit executed

contralto) .

startup
end
me zero
reaches DAT 1 DI DAH
MOV DI OFFSET LEA
,
; ,

MOV AL 0F6n for letters ,


we
,
;
have to give
MOV CX 10° →
decimal
# LODS , ☐ as no data

can start wit


CLD
alphabet .

REP STOSB
☒ AX @ EAX with the data
Loads AL
@
exit
stored at the data segment .

end
*
offset address indexed by SI register
*
After loading contents of SI inc
if 13=0 # SCAS

⑧ decile D- =L the AL with byte of data


p
compares in
a
memos .

*
_
AX - word -

E± LODSB AL= DS :[ SI ] SI III


p Eax double word
; ;
-
-
-

↳ Dsw A- ✗ -2
j
= -

,
*
Memory is Es :D I

LODSD Y flags affected


,

EAX =
j Operands not affected ( sashay:)
-

, -
-
*
E SCASB # Repeat until end of string (0--0) @
SCASW
until compared bytes a re not
equal
SCASD

Can be used with prefix


Repeat if
not
equal source Destination
REPNESCAS.by
-

1000 67 67

}
2000

100 / 6 56
5 2001
ALP the displacement
E± :
write an to
find at which
1002 ya zool 4A
no , g, zoo ,
me og
aya , ,,µ ,
present gon an
array gz
1004 AA 2004 AA
data stored
from location DATI the number of
exit
.

<

of the 80
bytes data array
in is
.

And • model tiny Destination


data 67
)
-

1000 67 2000

DATI DB 80 DVPC ? ) 1001 6 56


5 2001
)

1002 67 zooz ya not efual


• code
1003 67 2003 67
startup

1004 AA 2004 AA

MOV DI OFFSET DATI


,

MOV AL , ODN
Mov cx
,
80
Rotate
Operations
CLD

two exit conditions


REPNE SCASB →
Best Count
ODN is pent # ROL ,

(
① If
Exit
all iterations ROR Best, Count

done
END

the next
* If oDn is found ,
DI will point to
* use CL for Count greater than 1 ( if 80386
address .

count greater than I can be specified directly)


-

not ax
,
I

# [ Mps * nor
byteptnf.si ] ,
I

* MOV I 04h
string with
*
compares a
byte in one a
byte in ,

not ax I
*
another word dword
,

string @ a
/ in one string
another string
* nor byteptrf.si ] ,
I
with a
word / dword in .

* not ecx 12
SI with ES :
DI ,
* Ds :

* flags affected
*

P
Direction

Can be used
flag used

with
for

Prefix
auto inc @ dec
ROL
cL←y%<
- → CL
OFFSET STRING ROR
E MOV SI
,
FIRST

DI OFFSET STRING SECOND


Mov ,

CLD
flags affected : Cf
100
MOV CX ,
of -
Ile MSB
changes -

single bit rotate ( only )


CMPSB multi bit rotate
REPE -
no significance in
NEXT DEC DL
É ^^
I ← :
0 I 1 O l l l ☐

( f JNZ AGA I N

MOV RESL ,
BL

AI
O exit
l l
O I I o l 0 0 •

Cf end

for ROL
, -o
Instructions
Shift
E ROL BL ,oy ( assumed
32 bit Mp
) # SAL
/ 5hL
AI :
Baye : 1001 1100

0011 1001 $ SAL /SHL @ two mnemonics for the s am e


Afi

nf# 0111
Operation
"
0010 .

' ' 0 0 1 0°
bit
^bµ÷n;
'

*
shifts each in the specified some number

I 1001
left
100

of bit positions to he .

*
swap Nibbles using this * As bit shifted out of LSB 0 is put in LSB
,

to Cf
* ROR WORD PTRCBX] ,oy ( same effect) MSB shifted .

* SAL / Snl destination , count

# RCL Best / Count it count in Clif count greater than 1


(except in 386

RCR Best / COUNT and above )


Target Register / Memory

E SAL BX , 1

cf←y MOV CL, 02

R④
SAL BP , CL

SAL BYTE PTR [ BX] 1 ,

SAL EAX ,
12

E Write that counts the number of


a
program affected Cf ZF 5f
flags
→ :
, ,

writes
1 's in a
byte in location DATE and

OF If MSB changes bit rotate
-
-

single

it into location REI .

→ pf -

Affected -

but has
meaning only if 8- bit operation

And
:
.
model tins

Af -

undefined ( unaffected )
-

data

DATAL DB

%f¥p
0A In
✗or
# SNR ( Shift Logical Right)
RESI ago
DB ?
BL ,0 MSAs
Shift operand bits rights Put zeroes in


.

• code


startup tongue * 5hr Best, Count

SUB BL BL clear BL * SNR BP , I


, ; ,
no
.

AL
-
-
ish
Let
8 of "
MOV DL
E Mov BL ,AL BL -43
"
-

, So
,

AL AND Ofn BL=o3n


MOV ,
DATA 1 BL ,

MOV 04N 04h


CL
AL
-_

AGAIN : AOL Al
,
I SMR AL CL
04h
,
Bn=
JNC NEXT Mov Bn , AL
Jo this program separated
INC BL ,
into two bytes -

u ⑨ ↳
?⃝
mode )
# SAR # c.
W/ CWD →
(Implicit Addrexis

A Shift Operand Bits Right .


New MSB Old MSB

Always work on ALIAX


to word
A SAR Destination ,
Count * convert Byte →

0000
100 009
* 80 FF 80
EI
-

:
SAR DI
,
I 1111 1111 1000 0000

e×tendedboh
-

w
27 0027
Mov CL ,
02h *
-

design is

SAR word PTRCBP ] , CL

* Convert word to Doubt word → AX / EAX


5673 DX a- ✗ ( if 16 bitmp else EAD
Multiply ⑧ Divide
:
" " * g. by } -
oooo →

MuLy±µuLsouÉ"Md^
"

"" Md
* 9100 - ffff 9100

always
¥ Ix iobitrp
# is
Destination bitmp
EAT
32

Accumulator
* Source times AL → byte multiplication F-
.
mode tiny

* source times AX →
word -

<
data
→ D-
Some times E- AX -

* Multiplicand DW 2040h

register @ location DW 2000h


* source can
be a memory .

Multiplier

Product 1 DW ?
product 2 DW ?
E
B¥AL
MUL BL AX
;

Code

possible .
startup
that the
bit Mov AX , Multiplicand
is 16
result
MVL Multiplier
BX BX DX : AX Mov Products ,A✗
MVL ;
✗ AX
b
b Mov product 2 DX
16 bits ,
lower
Upper •
exit
16 bits
end

* Result for Byte multiplication in AX


Special IMUL
about
( Not
read
multiplication in DX AX to
only from gos86 going
:
word
* Result for Available 80186 )
f- DX : f- AX
* Result for Dwod multiplication IMUL pest , Source ,
Immediate Data ( Any regisnasdes.tl
* Cf and Of zero if MSBIMSWIMSD ze ro source )

80186 it with timer


* Af,pf,Sf ,
zf -

undefined → 8086 inside has programmable ,

serial interface , some memory


peripheral interface
.

Acts microcontroller
EI AL like
-02
:
BL -

03 .

MUL BL

06
AX ⑧ # DIV / IDIV
-

b
bate Ginder bor woeoyiworoy
significant
most A word ÷
Byte @ word → quad word

*
D. word

Qword
÷

÷
word

Dword
④ te ÷ byte ( Not allowed)
* DIV / IDIV Source

P word ÷
-
Byte
Byte location
A word in AX
,
in
Register @ memory
* Ah reminder
quotient
-

AL -

* Dwordiwod
* Dword in DX
:
AX
,
word in Register ( on
) Meng

location .

DX Reminder
* AX quotient
-
-

* Qword-Dwoo
word in f- DX : EAX , D word in Register ( of rang
*
location

p
EAX - Quotient F-DX -
Reminder

All
p flags undefined
B Sign of remainder same as divided -
I n case

of signed ops
# 80×86 is slower in MULIDIV
instructions than other
any
CWD arithmetic instruction
use KBW .

resignations
on
,
# It imposes general / Div
mud

You might also like