Assembly Language Instructions
By Didar Hussain
GENERAL SYNTAX
Include Irevine32.inc
.data
.code
Main proc
Call DumpRegs
Exit
Main ENDP
END main
By Didar Hussain 2
Data portion
Code portion
INSTRUCTIONS
 ZX
 SX
 INC
 DEC
 XCHG
 NEG
 LAHF
 SAHF
 PTR
 LENGTHOF
 SIZEOF
 TYPE
 LOOP
By Didar Hussain 3
ZX
 ZX instruction is used to extend zeros without the
values which we given
 For e.g when we give 11h in the al register, in
this condition without 11 all the values in the eax
register will be zeros
 In simple words there will be 6 leading zeros see
the following
00000011
By Didar Hussain 4
SYNTAX
.data
var byte 29h
.code
main proc
movzx eax,var
By Didar Hussain 5
PROGRAM
By Didar Hussain 6
SX
 Same to same ZX but there will be leading
ones
 For e.g we entered 84 using al register and we
want to replace garbage values of ah and
extended portion with 1, for this type of task
we use SX instruction
 Note that when the MSB in any number is one
then SX create leading 1,s otherwise it create
leading 0,s.
By Didar Hussain 7
SYNTAX
.data
var byte 89h
.code
main proc
movsx eax,var
By Didar Hussain 8
PROGRAM
By Didar Hussain 9
INCREMENT
 For increment instruction simply use inc
 Through this instruction a number is
incremented
 For e.g when we give 25 through using of inc
instruction it become 26
 In simple words it added 1 to a number
By Didar Hussain 10
SYNTAX
.data
var byte 85h
.code
main proc
mov al,var
inc al
By Didar Hussain 11
PROGRAM
By Didar Hussain 12
DECREMENT
 For decrement instruction simply use dec
 It is completely opposite of increment instruction
 Through this instruction a number is decremented
 So in simple words we can say it subtract 1 from a
number
 For e.g 45 become 44, 12 become 11 through using
dec instruction
By Didar Hussain 13
.data
var byte 85h
.code
mov al,var
dec al
By Didar Hussain 14
SYNTAX
PROGRAM
By Didar Hussain 15
XCHG
 XCHG stands for xchange
 It is used to exchange two register with each other
 For e.g al and ah are two register which store different
values i-e al store 14 and ah store 13
 We want that these register xchange values with each
other i-e al store 13 and ah store 14
 So this type of operations we can done with the help
of XCHG instruction
16By Didar Hussain
SYNTAX
.code
main proc
mov al,14h
mov ah,13h
xchg al,ah
By Didar Hussain 17
PROGRAM
By Didar Hussain 18
NEG
 Neg stands for negative
 As express from name it is used to convert a positive
number into negative
 We also can say it convert unsigned into signed
 Note that the signed and unsigned operations depends
on only most significant bit(msb).
 When msb=1 it represent -ve/signed, and when msb=0
it represent +ve/unsigned
By Didar Hussain 19
SYNTAX
.data
var dword 70000000h
.code
main proc
mov eax,var
neg eax
By Didar Hussain 20
PROGRAM
By Didar Hussain 21
LAHF
 LAHF stands for load status flag into ah register
 The LAHF instruction is used for to move the
status of flags into ah register
 And then we move the ah register into memory
 So the main purpose of LAHF is to move the flag
status into memory
By Didar Hussain 22
SYNTAX
.data
var byte ?
.code
main proc
mov al,11111111b
add al,00000001b
lahf
mov bl,11110000b
add bl,00001111b
By Didar Hussain 23
PROGRAM
By Didar Hussain 24
SAHF
 SAHF stands for shift status flags into ah register
 It is used to move the status of flags again from
memory to ah register
 It is basically perform a work completely opposite of
LAHF
 LAHF move the flags status to memory and SAHF
shift the flags status again from memory to register
By Didar Hussain 25
SYNTAX
.data
var byte ?
.code
main proc
mov al,11111111b
add al,00000001b
lahf
mov bl,11110000b
add bl,00001111b
sahf
By Didar Hussain 26
PROGRAM
By Didar Hussain 27
PTR
 Ptr stands for pointer
 Ptr is used to move small values to a big register or
large values to a small register.
 Normally it is don't possible to done this type of
operations but through the help of ptr instruction
we can easily perform
 We write as byte ptr,word ptr,dword ptr.
By Didar Hussain 28
PTR
 Byte ptr in that condition when there is a large values
for e.g word or dword we want to store in al register
 Word ptr in that condition when there is a large values
i-e dbyte or small values i-e byte we want to store in
ax register .
 Similarly when small values i-e byte or word we
want to store in eax register then we use dword ptr
By Didar Hussain 29
SYNTAX
.data
var byte 24h
.code
mov eax,dword ptr var
By Didar Hussain 30
PROGRAM
By Didar Hussain 31
• The lengthof instruction is used to find the number
of elements
• The elements which we entered during coding in
any register using any number system
• When we want to find how many elements we
entered, for this purpose we use the lengthof
instruction
By Didar Hussain 32
LENGTHOF
.data
var1 word 45h,98h,78h
.code
main proc
mov al,lengthof var1
By Didar Hussain 33
SYNTAX
PROGRAM
By Didar Hussain 34
SIZEOF
 The sizeof instruction is used to find the complete size of
a register
 In simple words the sizeof instruction used to find that
”how many size is of the register”
 Note that sizeof mean the register size should be
multiplied with the number of elements
 Sizeof we can simply find by the following formula
Sizeof=register size multiplied by number of elements
 Register size mean al/byte register is one byte, ax/word is
two bytes and eax/dword is 4 bytes
By Didar Hussain 35
SYNTAX
.data
var word 20h,54h,62h,78h
.code
main proc
mov al,sizeof var
By Didar Hussain 36
PROGRAM
Output
By Didar Hussain 37
TYPE
 Type instruction is used to show the status of the
register
 For e.g al register or byte contain one byte, it show
1,ax register or word contain two bytes so it show
2,similarly eax register or dword contain 4 bytes so it
show 4
 In simple words the type instruction show or find out
the number of bytes in the given register
By Didar Hussain 38
SYNTAX
.data
var byte 68h
.code
main proc
mov al,type var
By Didar Hussain 39
PROGRAM
By Didar Hussain 40
LOOP
 Loop is basically a counter
 Counter mean repetition of a statement for a
specific condition
 A statement continue until a condition occur
 So with the help of loop we can get a
condition which we want
 It is to be noted that for LOOP a counter
register is used
By Didar Hussain 41
SYNTAX
.code
main proc
mov ecx,6
mov eax,2
L:
inc eax //6 times 2 will be incremented, so 2 well becomes 8
loop L
By Didar Hussain 42
PROGRAM
By Didar Hussain 43
Youngest Microsoft
Certified Professional
 Arfa Karim Randhawa
 1995-2012
 She became the world youngest Microsoft Certified Professional at the age of nine
 In 2011, she suffered a cardiac arrest and she died in 2012, at the age of 16
“If you think shy, you act shy.
If you think confident you act confident”.
Arfa Karim
44
A True Inspiration
By Didar Hussain
THANKS
By Didar Hussain 45

Assembly language instructions

  • 1.
  • 2.
    GENERAL SYNTAX Include Irevine32.inc .data .code Mainproc Call DumpRegs Exit Main ENDP END main By Didar Hussain 2 Data portion Code portion
  • 3.
    INSTRUCTIONS  ZX  SX INC  DEC  XCHG  NEG  LAHF  SAHF  PTR  LENGTHOF  SIZEOF  TYPE  LOOP By Didar Hussain 3
  • 4.
    ZX  ZX instructionis used to extend zeros without the values which we given  For e.g when we give 11h in the al register, in this condition without 11 all the values in the eax register will be zeros  In simple words there will be 6 leading zeros see the following 00000011 By Didar Hussain 4
  • 5.
    SYNTAX .data var byte 29h .code mainproc movzx eax,var By Didar Hussain 5
  • 6.
  • 7.
    SX  Same tosame ZX but there will be leading ones  For e.g we entered 84 using al register and we want to replace garbage values of ah and extended portion with 1, for this type of task we use SX instruction  Note that when the MSB in any number is one then SX create leading 1,s otherwise it create leading 0,s. By Didar Hussain 7
  • 8.
    SYNTAX .data var byte 89h .code mainproc movsx eax,var By Didar Hussain 8
  • 9.
  • 10.
    INCREMENT  For incrementinstruction simply use inc  Through this instruction a number is incremented  For e.g when we give 25 through using of inc instruction it become 26  In simple words it added 1 to a number By Didar Hussain 10
  • 11.
    SYNTAX .data var byte 85h .code mainproc mov al,var inc al By Didar Hussain 11
  • 12.
  • 13.
    DECREMENT  For decrementinstruction simply use dec  It is completely opposite of increment instruction  Through this instruction a number is decremented  So in simple words we can say it subtract 1 from a number  For e.g 45 become 44, 12 become 11 through using dec instruction By Didar Hussain 13
  • 14.
    .data var byte 85h .code moval,var dec al By Didar Hussain 14 SYNTAX
  • 15.
  • 16.
    XCHG  XCHG standsfor xchange  It is used to exchange two register with each other  For e.g al and ah are two register which store different values i-e al store 14 and ah store 13  We want that these register xchange values with each other i-e al store 13 and ah store 14  So this type of operations we can done with the help of XCHG instruction 16By Didar Hussain
  • 17.
    SYNTAX .code main proc mov al,14h movah,13h xchg al,ah By Didar Hussain 17
  • 18.
  • 19.
    NEG  Neg standsfor negative  As express from name it is used to convert a positive number into negative  We also can say it convert unsigned into signed  Note that the signed and unsigned operations depends on only most significant bit(msb).  When msb=1 it represent -ve/signed, and when msb=0 it represent +ve/unsigned By Didar Hussain 19
  • 20.
    SYNTAX .data var dword 70000000h .code mainproc mov eax,var neg eax By Didar Hussain 20
  • 21.
  • 22.
    LAHF  LAHF standsfor load status flag into ah register  The LAHF instruction is used for to move the status of flags into ah register  And then we move the ah register into memory  So the main purpose of LAHF is to move the flag status into memory By Didar Hussain 22
  • 23.
    SYNTAX .data var byte ? .code mainproc mov al,11111111b add al,00000001b lahf mov bl,11110000b add bl,00001111b By Didar Hussain 23
  • 24.
  • 25.
    SAHF  SAHF standsfor shift status flags into ah register  It is used to move the status of flags again from memory to ah register  It is basically perform a work completely opposite of LAHF  LAHF move the flags status to memory and SAHF shift the flags status again from memory to register By Didar Hussain 25
  • 26.
    SYNTAX .data var byte ? .code mainproc mov al,11111111b add al,00000001b lahf mov bl,11110000b add bl,00001111b sahf By Didar Hussain 26
  • 27.
  • 28.
    PTR  Ptr standsfor pointer  Ptr is used to move small values to a big register or large values to a small register.  Normally it is don't possible to done this type of operations but through the help of ptr instruction we can easily perform  We write as byte ptr,word ptr,dword ptr. By Didar Hussain 28
  • 29.
    PTR  Byte ptrin that condition when there is a large values for e.g word or dword we want to store in al register  Word ptr in that condition when there is a large values i-e dbyte or small values i-e byte we want to store in ax register .  Similarly when small values i-e byte or word we want to store in eax register then we use dword ptr By Didar Hussain 29
  • 30.
    SYNTAX .data var byte 24h .code moveax,dword ptr var By Didar Hussain 30
  • 31.
  • 32.
    • The lengthofinstruction is used to find the number of elements • The elements which we entered during coding in any register using any number system • When we want to find how many elements we entered, for this purpose we use the lengthof instruction By Didar Hussain 32 LENGTHOF
  • 33.
    .data var1 word 45h,98h,78h .code mainproc mov al,lengthof var1 By Didar Hussain 33 SYNTAX
  • 34.
  • 35.
    SIZEOF  The sizeofinstruction is used to find the complete size of a register  In simple words the sizeof instruction used to find that ”how many size is of the register”  Note that sizeof mean the register size should be multiplied with the number of elements  Sizeof we can simply find by the following formula Sizeof=register size multiplied by number of elements  Register size mean al/byte register is one byte, ax/word is two bytes and eax/dword is 4 bytes By Didar Hussain 35
  • 36.
    SYNTAX .data var word 20h,54h,62h,78h .code mainproc mov al,sizeof var By Didar Hussain 36
  • 37.
  • 38.
    TYPE  Type instructionis used to show the status of the register  For e.g al register or byte contain one byte, it show 1,ax register or word contain two bytes so it show 2,similarly eax register or dword contain 4 bytes so it show 4  In simple words the type instruction show or find out the number of bytes in the given register By Didar Hussain 38
  • 39.
    SYNTAX .data var byte 68h .code mainproc mov al,type var By Didar Hussain 39
  • 40.
  • 41.
    LOOP  Loop isbasically a counter  Counter mean repetition of a statement for a specific condition  A statement continue until a condition occur  So with the help of loop we can get a condition which we want  It is to be noted that for LOOP a counter register is used By Didar Hussain 41
  • 42.
    SYNTAX .code main proc mov ecx,6 moveax,2 L: inc eax //6 times 2 will be incremented, so 2 well becomes 8 loop L By Didar Hussain 42
  • 43.
  • 44.
    Youngest Microsoft Certified Professional Arfa Karim Randhawa  1995-2012  She became the world youngest Microsoft Certified Professional at the age of nine  In 2011, she suffered a cardiac arrest and she died in 2012, at the age of 16 “If you think shy, you act shy. If you think confident you act confident”. Arfa Karim 44 A True Inspiration By Didar Hussain
  • 45.