Lab Report
Lab Report
Lab Report: 02
Submitted By:
Afrina Sultana
ID: 2018-1-17-016
Submitted To:
Ayesha Siddiqua
Lecturer
Question: 05
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV CX, 4
LEVEL1:
MOV BX, CX
LEVEL2:
MOV AH, 2
INT 21H
LOOP LEVEL2
1
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV CX, BX
LOOP LEVEL1
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
2
****
***
**
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC is the main function for this program where PROC stands for
procedure.
MOV CX, 4: Here we have used CX for a loop which decides that the triangle will
have 4 lines.
LEVEL1:
MOV BX, CX
Here we have copied the value 4 into BX. This level basically controls the outer
loop of the triangle.
3
Then we write the instructions,
MOV AH, 2
INT 21H
This level controls the inner loop of the triangle. To print the asterisk we have to
use the display register.
LOOP LEVEL2: This instruction means that the instruction will execute till
LEVEL2. The loop will get back to LEVEL2 after executing a loop and also it
decreases the value of the loop by one every time.
MOV CX, BX
LOOP LEVEL1: Here the new CX value will be decreased and it will go to
LEVEL1.
EXIT:
INT 21H
4
MAIN ENDP
END MAIN
Discussion: In my previous lab class there I had some confusion with the loops
and the levels. But in this lab my confusions got cleared.
Question: 06
Write a program that exchange and swap values using assembly language.
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1
INT 21H
MOV BL, AL
INT 21H
5
MOV BH, AL
INT 21H
MOV CL, AL
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH, 2
MOV DL, CL
INT 21H
MOV DL, BH
INT 21H
MOV DL, BL
INT 21H
6
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH, 1
INT 21H
MOV BL, AL
INT 21H
MOV BH, AL
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
7
XCHG BL, BH
MOV AH, 2
MOV DL, BL
INT 21H
MOV DL, BH
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
CSE
ESC
AD
DA
8
Explanation: In this code the first three lines,
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC is the main function for this program where PROC stands for
procedure.
First we take three inputs through AL register and copy them to BL, BH and CL
respectively. Now we have to print our inputs in backwards. For that we have
displayed our inputs in backward direction. Such as our last input was in CL, that’s
why we’ll display CL register then BH and then BL register.
Now this backward direction printing can be done by second method which is the
exchange method.
For the exchange operation we have to use XCHG OPCODE. We write this
instruction as follow,
XCHG BL, BH
MOV AH, 2
MOV DL, BL
INT 21H
9
MOV DL, BH
INT 21H
Here, after the XCHG OPCODE we have to write the two register in which we are
going to do the swapping or exchange operation. Then through our output function
we will display our registers according to the sequence of our inputs.
EXIT:
INT 21H
MAIN ENDP
END MAIN
Discussion: The first portion of the program was the basic of taking multiple
inputs and displaying them. But the second portion of the program introduced us
with a new OPCODE which is XCHG. Through this OPCODE I can easily
exchange or swap the values of registers.
Question: 07
Write a program that implements the AND, OR, XOR, ADD and SUB operations
using assembly language.
10
Source Code:
.MODEL SMALL
.STACK 100H
.DATA
.CODE
MAIN PROC
MOV DS, AX
MOV AH, 9
LEA DX, A
INT 21H
11
MOV BL, 111B
ADD BL, 48
MOV AH, 2
MOV DL, BL
INT 21H
LEVELOR:
MOV AH, 9
LEA DX, B
INT 21H
OR BL, 110B
ADD BL, 48
MOV AH, 2
12
MOV DL, BL
INT 21H
LEVELXOR:
MOV AH, 9
LEA DX, C
INT 21H
ADD BL, 48
MOV AH, 2
MOV DL, BL
INT 21H
LEVELADD:
MOV AH, 9
LEA DX, D
13
INT 21H
ADD BL, 48
MOV AH, 2
MOV DL, BL
INT 21H
LEVELSUB:
MOV AH, 9
LEA DX, E
INT 21H
ADD BL, 48
14
MOV AH, 2
MOV DL, BL
INT 21H
EXIT:
MAIN ENDP
END MAIN
Output:
FOR AND 5
FOR OR 6
FOR XOR 2
FOR ADD 7
FOR SUB 3
Explanation: Inside our data segment we declare our messages. To initialize our
data segment we write these two lines:
15
MOV DS, AX
MOV AH, 9
LEA DX, A
INT 21H
Here, MOV ah, 9 is our output function to print strings. LEA stands for load
effective address which loads the string of A to DX.
MOV BL, 111B: Number 111 is copied to BL. 111B stands for binary number.
AND BL, 101B: OPCODE AND is used to implement the operation of AND
between 101 and 111.
MOV AH, 2
MOV DL, BL
INT 21H
LEVELOR:
16
MOV AH, 9
LEA DX, B
INT 21H
OR BL, 110B: OR operation takes place between 110B and BL through the OR
OPCODE.
ADD BL, 48: Converts the result of OR operation from binary to decimal.
MOV AH, 2
MOV DL, BL
INT 21H
EXIT:
MAIN ENDP
17
END MAIN
Discussion: In this program I have used OPCODES AND, OR, XOR, ADD and
SUB. These OPCODEs are built in. We can use various numbers and implement
the operations. We can display the results in binary number also.
Question: 08
Source Code:
.MODEL SMALL
.STACK 100H
.DATA
PASS1 DW 5
.CODE
18
MAIN PROC
MOV DS, AX
MOV AH, 9
LEA DX, A
INT 21H
L1:
MOV AH, 8
INT 21H
JNE L2
INC BX
LOOP L1
19
MOV AH, 9
LEA DX, OK
INT 21H
JMP EXIT
L2:
MOV AH, 9
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
or
20
ENTER PASSWORD CORRECT PASSWORD
MOV DS, AX
MOV BX, OFFSET PASS: The values that are placed in the PASS variable is
checked through the OFFSET and copied to BX.
MOV AH, 9
LEA DX, A
INT 21H
MOV AH, 8: This is a function which is taking input from the user keeps in a
hidden form.
CMP AL, [BX]: The offset value of the BX is compared with the AL register.
JNE L2: If one value doesn’t match it will jump to the level L2.
21
INC BX: If the values are equal then BX will increase after comparing every input
with [BX].
LOOP L1: Then it will go to the level L1 after every successful comparison.
If the password is correct then the message of the variable OK will be printed.
MOV AH, 9
LEA DX, OK
INT 21H
JMP EXIT: After the correct entered password it will straight jump to exit.
If any entered character is not equal to the password then following instructions
will be executed.
MOV AH, 9
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
22
Discussion: In this program I have learned how to take input in a hidden form,
about the offset instruction. This program assures security also.
Conclusion: Through this lab I have learned a lot of new things. I’ve been
introduced with various new OPCODEs and instructions. The problems I faced in
the previous lab have been solved in this lab.
27