ASM Irvine 32 Cheat Sheet (P1)
ASM Irvine 32 Cheat Sheet (P1)
ASM Irvine 32 Cheat Sheet (P1)
Cheat Sheet(part-1)
Unsigned Integer
Positive number i.e All Numbers >= 0.
Signed Integer
Negative number i.e All Numbers < 0.
ASCII String
String : Sequence of one or more characters.
Terminology: ASCII string in memory is stored as a succes-
sion of bytes containing ASCII code /numeric code.
Boolean Operations
NOT ( ~ ) : Reverse the bit
AND ( ^ ) : Implement logical AND expression
OR ( + or v ) : Implement logical OR expression
Registers
Registers are high speed direct memory storage locations in-
side the CPU.
INCLUDE Irvine32.inc
INCLUDE : A directive extract all the information from
Irvine32.inc
.MODEL directive
1. Identifies the segmentation model to be used for program
2. Identifies the code convention used for passing the param-
eters to procedures.
flat keyword : tells the assembler to generate the code for
protected mode
stdcall Keyword : enables the calling of MS-WINDOWS
function.
var BYTE ?
String Definitions
Syntax :
String_Name Type "string here.." or
String_Name Type ‘string here..’
i.e
Name BYTE "ABC...XYZ"
Term to know :
Each character of string uses a byte of storage
A,B,.....,Z each uses 8-bit of storage place.
Meaning
Þ Name BYTE 'A','B','C',....,'X','Y','Z',0 is same as:
Name BYTE "ABC...XYZ",0
Þ Name[0]="A" Name[2]="C" and so on.
Multiple lines of string:
DUP operator
m DUP stands for Duplicate
m DUP allocates storage for multiple data elements of same
type
m DUP is usefull declaring array and strings
Examples:
Terminology of Byte 4 DUP("STACK") :
( = ) Symbol :
variable_name= constant or expression
Size of Arrays and Strings:
Explicitly : ArraySize = 4
Implicitly : ArraySize = ($ - ArraySize)
.data
var BYTE 30
mov AL , var is dereferencing technique to access the
data in var.
Let address of var is (0x1000) then :
[ ] for Dereferencing
AL
i.e mov AL , [var] 0x1000
Assembly C/C++
MOV var , 5
MOV eax , 5
Rules to use MOV instruction:
Size of Destination & Source must be of same.
MOV EAX , BL ;ERROR
Both Destination and Source cannot be memory operands
MOV var1 , var2 ;ERROR
mov eax , 5
var = -1
NEG reg NEG eax ; -5
NEG mem NEG var ; 1
Offset Operator
returns the distance of variable in bytes form base location
PTR Operator
used to access specific size of a register/memory
Solution:
mov ax ,word PTR array
Syntax:
instruction destination , size of variable PTR varia-
ble_name
mov AL , 256 ;error : invalid Operands
Example:
val byte 5
ADD EAX , DWORD ptr val
TYPE Operator
Returns the size of variable according to data type in
Byte/s.
LENGHTOF Operator
counts the number of elements in array
returns the size/length of array
arr byte 1 , 2 ,3 ,4 ,5
SIZEOF Operator
Returns the size of variable/array/string as:
SIZEOF = TYPE * LENGTHOF
Example :
intArray BYTE 1,2,3
mov eax , sizeOf intArray ;eax = 3
A.
B.
C.
D.
E.
F.
OFFSETs Access
0000 IntegerArray+0
1
0001 2 IntegerArray+1
0002 3 IntegerArray+2
0003 4 IntegerArray+3
Accessing Elements of Array
1.
mov esi,0 ;Any general purpose reg
mov al,[IntegerArray+esi]
inc esi
Pointers
A variable that contains the address/offset of
other variable.
Used for Dynamic Memory Allocation
TYPEDEF Operator
Use Case:
label1:
....
....
loop label1
while loop
Another technique to use loop structure is while loop.
Syntax:
.while(condition is true )
....
....
.endw
Use Case: Print PAKISTAN 5 TIMES
i.e lengthofArray = 5
i.e counter = 10 etc..
Keep in mind:
if you will not count the size of array just after the array
declaration , the size will be incorrect.
See Example:
array BYTE 1,2,3,4
count BYTE ?
arraySize = ( $ - array )
Assuming the offsets mentioned in example given above
the arraySize = 5
Number of Array Elements : 32-bit and 16-bit
WordArray Word 1,2,3,4
DwordArray Dword 1,2,3,4
1 2 3 4
Elements
Offsets 0000 0002 0004 0006
why to divide by 4?
1 2 3 4
Elements
Offsets (hex) 0000 0004 0008 000C
if offset of WordArray = 0x0000
the offset of arraySize = 0x0010 ::10 hex = 16 deci
then arraySize = 0x0010 - 0x0000 = 16 /4 = 4 elements
NOTE : I have tried to solve and debug the example used in
this sheet with the help of MASM assembler. BUT being a
human I would say : “Mistakes are made and solved by human”.
Regards: Z.A Sandhu
THANKS