Name: Mariam Nadeem
Roll No: 29
Submitted to: Sir Hammad
Section: BSCS 7A
Lab Work
Practical # 1
Write a program to adding two variables in assembly language.
TITLE: Add Two Variables
INCLUDE [Link]
INCLUDE [Link]
.data
COMMENT Pra_1
SUM is a variable name and DWORD (32 bit) is a Data type and
initial value is zero.
Pra_1
SUM DWORD 0
.code
Practical_1 PROC
mov EAX, 5
add EAX, 6 mov
SUM, EAX
; for display information of registers mWrite
“The Registers Information is: “ call crlf
call DumpRegs
; for display Answer of SUM
mWrite “The Sum of two Numbers is: “ call
WriteINT
call crlf
exit
Practical_1 ENDP
END Practical_1
Practical # 2
Write a program to use Integer Literals with Radix.
TITLE: Integer Literals [{+ | -}] digits [radix]
INCLUDE [Link]
INCLUDE [Link]
.code
Practical_2 PROC
mov EAX, 101101h
add EAX, -1001h
mWrite “HEXADECIMAL Addition: “ call
DumpRegs
mov EAX, 1011001101b add
EAX, 10010101b
mWrite “BINARY Addition: “ call
DumpRegs
mov EAX, 1011001101o add
EAX, 10010101o
mWrite “OCTAL Addition: “ call
DumpRegs
mov EAX, 20173d
add EAX, -1932d
mWrite “DECIMAL Addition: “ call
DumpRegs
exit
Practical_2 ENDP
END Practical_2
Practical # 3
Write a program to perform all arithmetic operations/expressions
TITLE: Constant Integer Expressions
INCLUDE [Link]
INCLUDE [Link]
.code
Practical_3 PROC
mov EAX, 10 * 2 – (12 MOD 7 + 4) / 5
mWrite “The values in registers: “ call
DumpRegs
mWrite “The Answer in Decimal is: “ call
Writedec
call crlf
exit
Practical_3 ENDP
END Practical_3
Practical # 4
Write a program to display some character literals
TITLE: Character Literals
INCLUDE [Link]
INCLUDE [Link]
.data
S1 BYTE “A” ,0 S2
BYTE „L‟ ,0 S3
BYTE „I‟ ,0
.code
Practical_4 PROC
mov EDX, OFFSET S1
call WriteString
mov EDX, OFFSET S2
call WriteString
mov EDX, OFFSET S3
call WriteString
call crlf
exit
Practical_4 ENDP
END Practical_4
Practical # 5
Write a program to display string literals
TITLE: String Literals
INCLUDE [Link]
.data
S1 BYTE “ALI” ,0
S2 BYTE „ADP-CS‟ ,0
.code
Practical_5 PROC
mov EDX, OFFSET S1
call WriteString
call crlf
mov EDX, OFFSET S2
call WriteString
call crlf
exit
Practical_5 ENDP
END Practical_5
Practical # 6
Write a program that input numbers and stored in different variables and perform
this expression: (A + B) – (C + D)
TITLE: Expression (A+B) – (C+D)
INCLUDE [Link]
INCLUDE [Link]
.data
A1 dword ?
B1 dword ?
C1 dword ?
D1 dword ?
.code
Practical_6 PROC
mWrite “ >>>>> (A + B) – (C + D) <<<<< “
call crlf
call crlf
mWrite “Enter the Value of A: “ call
readint
mov A1 , EAX
mWrite “Enter the Value of B: “ call
readint
mov B1 , EAX
mWrite “Enter the Value of C: “ call
readint
mov C1 , EAX
mWrite “Enter the Value of D: “ call
readint
mov D1 , EAX
call crlf
mWrite “The Answer of (A+B) – (C+D) is: “ call
Answer ; User defined procedure
call crlf
exit
Practical_6 ENDP
Answer PROC
mov EAX , A1
mov EBX , B1
mov ECX , C1
mov EDX , D1
add EAX , EBX
add ECX , EDX
sub EAX , ECX
call WriteINT call
crlf
ret
Answer ENDP
END Practical_6
Practical # 7
Write a program that defines symbolic constant names for several string literals.
Use each symbolic constant name in a variable definition.
TITLE: Symbolic Text Constant
INCLUDE [Link]
str1 EQU <”ALI ”,0> str2
EQU ”RAZA ”,0
.data
first BYTE str1
second BYTE str2
.code
Practical_7 PROC
mov EDX, OFFSET first call
WriteString
mov EDX, OFFSET second call
WriteString
exit
Practical_7 ENDP
END Practical_7
Practical # 8
Write a program that perform symbolic integer constant.
TITLE: Symbolic Integer Constant
INCLUDE [Link]
A1 EQU 58
B1 = 61
.code
Practical_8 PROC
mov EAX , A1 add
EAX , B1 call
Writedec call crlf
exit
Practical_8 ENDP
END Practical_8
Practical # 9
Write a program that input the length and width of rectangle and calculate the
Area of rectangle.
TITLE: Area of Rectangle
INCLUDE [Link]
INCLUDE [Link]
.code
Practical_9 PROC
mWrite “The Length of Rectangle is: “ call
readint
mov EBX , EAX
mWrite “The Width of Rectangle is: “ call
readint
call crlf
mWrite “The Area of Rectangle is: “ call
areaofrectangle
call crlf
exit
Practical_9 ENDP
areaofrectangle PROC
imul EAX , EBX call
Writedec
ret
areaofrectangle ENDP
END Practical_9
Practical # 10
Write a program to perform a direct offset operand (starting address) in assembly
language.
TITLE: Direct OFFSET operand (Starting Address) INCLUDE
[Link]
.data
myarray dword 10, 20, 30, 40, 50
.code
Practical_10 PROC
mov EAX , myarray call
Writedec
call crlf
mov EAX , myarray + 4 call
Writedec
call crlf
mov EAX , myarray + 12 call
Writedec
call crlf
exit Practical_10
ENDP
END Practical_10
Practical # 11
Write a program to perform a direct offset operand (pick value) in assembly language.
TITLE: Direct OFFSET operand (pick value) INCLUDE
[Link]
.data
myarray dword 10, 20, 30, 40, 50
.code
Practical_11 PROC
mov ESI , OFFSET myarray mov
EAX , [ESI]
add ESI , 8
mov EAX , [ESI]
call Writedec call
crlf
exit
Practical_11 ENDP
END Practical_11
Practical # 12
Write a program to calculate the sum of every third value from the list of 10 values
of array in assembly language.
INCLUDE [Link]
INCLUDE [Link]
.data
myarray dword 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
.code
Practical_12 PROC
mov ESI , OFFSET myarray add
ESI , 8
mov ECX , [ESI]
mov ESI , OFFSET myarray add
ESI , 20
mov EDX , [ESI]
mov ESI , OFFSET myarray add
ESI , 32
mov ESI , [ESI]
add ECX , EDX add
ECX , ESI mov EAX ,
ECX
mWrite „The Sum of every third values is: „ call
Writedec
call crlf
exit Practical_12
ENDP
END Practical_12
Practical # 13
Write a program to exchange values of registers in assembly language
INCLUDE [Link]
INCLUDE [Link]
.code
Practical_13 PROC
mov EAX , 100
mov EBX , 200
mWrite “Before exchanging values of EAx and EBX: “ call
DumpRegs
xchg EAX , EBX
COMMENT change_
Now the values of EAX is 200
And the value of EBX is 100. Change_
mWrite “After Exchanging values of EAx and EBX: “ call
DumpRegs
exit Practical_13
ENDP
END Practical_13
Practical # 14
Write a program to exchange values of two variables in assembly language
INCLUDE [Link]
INCLUDE [Link]
.data
X dword 5
Y dword 7
.code
Practical_14 PROC
mWrite “Before exchanging the value of X is: “ mov EAX
,X
call Writedec call
crlf
mWrite “After Exchanging the value of X is: “ xchg EAX ,
Y
call Writedec
call crlf
exit
Practical_14 ENDP
END Practical_14
Practical # 15
Write a program to perform increment operator in assembly language
INCLUDE [Link]
INCLUDE [Link]
.code
Practical_15 PROC
mWrite “Now the value of AL (Register) is 255 (FF).” mov AL , 255
call DumpRegs
inc AL
mWrite “After inc the value of AL (Register) is Zero (00).”
Call DumpRegs
exit Practical_15
ENDP
END Practical_15
Practical # 16
Write a program to perform decrement operator in assembly language
TITLE: Decrement Operator
INCLUDE [Link]
INCLUDE [Link]
.code
Practical_16 PROC
mWrite “Now the value of AL (Register) is zero (00).” mov AL , 0
call DumpRegs
dec AL
mWrite “After dec the value of AL (Register) is 255 (FF).”
Call DumpRegs
exit Practical_16
ENDP
END Practical_16
Practical # 17
Write a program to perform OFFSET operator in assembly language
TITLE: OFFSET Operator
INCLUDE [Link]
.data
m DWORD ?
n WORD ? z
BYTE ?
t DWORD ?
.code
Practical_17 PROC
mov ESI , OFFSET m
call DumpRegs
mov ESI , OFFSET n
call DumpRegs
mov ESI , OFFSET z
call DumpRegs
mov ESI , OFFSET t
call DumpRegs
exit Practical_17
ENDP
END Practical_17
Practical # 18
Write a program to use Negation operator in assembly language
TITLE: Negation Operator
INCLUDE [Link]
INCLUDE [Link]
.code
Practical_18 PROC
mWrite “Before Negation the value of AL is:” mov Al ,
254
call DumpRegs
mWrite “After Negation the value of AL is:” neg AL
call DumpRegs
exit
Practical_18 ENDP
END Practical_18
Practical # 19
Write a program to perform Lengthof operator in assembly language
TITLE: Lengthof Operator
INCLUDE [Link]
INCLUDE [Link]
.data
Array_1 dword 10, 20, 30, 40, 50, 60, 70, 80
Msg byte “Hello”,0
.code
Practical_19 PROC
mWrite “The Length of String(msg) is: ” mov
EAX , LENGTHOF msg
call Writedec call
crlf
mWrite “The Length of Array(array_1) is: ”
mov EAX , LENGTHOF array_1 call
Writedec
call crlf
exit
Practical_19 ENDP
END Practical_19
Practical # 20
Write a program to perform Type operator in assembly language
TITLE: Type Operator
INCLUDE [Link]
INCLUDE [Link]
.data
m dword ?
n word ?
z byte ? t
tbyte ?
.code
Practical_20 PROC
mWrite “The Type of m(dword data type) is: ” mov EAX ,
type m
call Writedec
mWrite “ bytes”
call crlf
call crlf
mWrite “The Type of n(word data type) is: ” mov
EAX , type n
call Writedec
mWrite “ bytes”
call crlf
call crlf
mWrite “The Type of z(byte data type) is: ” mov
EAX , type z
call Writedec
mWrite “ bytes”
call crlf
call crlf
mWrite “The Type of t(tbyte data type) is: ” mov
EAX , type t
call Writedec
mWrite “ bytes”
call crlf
call crlf
exit
Practical_20 ENDP
END Practical_20
“Chapter 3 : Practical’s Solutions”
Question#05: Listing File for AddTwoSum
.data
A DWORD 10
B DWORD 20
Result DWORD ?
.code
Main PROC
Mov eax, A ; Load A Add
eax, B ; Add B
Mov result, eax ; Store result Ret
Main ENDP END
main
Question#06: AddVariables Program with 64-bit Variables
.data
A QWORD 1234567890ABCDEFh
B QWORD 1122334455667788h
Result QWORD ?
.code
Main PROC
Mov rax, A ; Load A into RAX (64-bit register) Add rax, B ; Add B to
RAX
Mov result, rax ; Store result Ret
Main ENDP END
main