Lab Report (Mid)
Lab Report (Mid)
Lab Report
Submitted By:
Afrina Sultana
ID: 2018-1-17-016
Submitted To:
Ayesha Siddiqua
Lecturer
1
Question: 01
Write a program that takes one input and shows the output using assembly
language programming.
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1
INT 21H
MOV BL, AL
MOV AH, 2
MOV DL, BL
INT 21H
EXIT:
INT 21H
2
MAIN ENDP
END MAIN
Output:
33
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC is the main function for this program where PROC stands for
procedure. HereMOV AH, 1 works as an input function which moves instructions
from register to registers. AH is an 8 bit register. AH is the destination and 1 is the
source here. INT is an interrupt function. When INT 21H function arrives in a
program, microprocessor stops and executes its immediate previous function.
MOV BL, AL is a function where AL is source and BL is destination. The input which
AL is containing will move to the destination BL. MOV AH, 2 is an output function.
To display the output we use MOV DL, BL. Here, DL is the display register. The
3
input we have in BL will be shifted to DL so that we can see the output. Again INT
21H function will execute immediate previous function. The MAIN ENDP is used to
end the program and END MAIN is used to end the main procedure.
Question: 02
Write a program that takes one input and shows the output in a new line using
assembly language programming.
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1
INT 21H
MOV BL, AL
MOV AH, 2
MOV DL, 10
4
INT 21H
MOV AH, 2
MOV DL, BL
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
.MODEL SMALL
.STACK 100H
.CODE
5
Works as header files.
MAIN PROC is the main function for this program where PROC stands for
procedure. Here MOV AH, 1 works as an input function which moves instructions
from register to registers. AH is an 8 bit register. AH is the destination and 1 is the
source here. INT is an interrupt function. INT 21H function arrives in a program
microprocessor stops and executes its immediate previous function. MOV BL, AL
is a function where AL is source and BL is destination. The input which AL is
containing will move to the destination BL. To show the output in a new line we
use,
MOV AH, 2
MOV DL, 10
INT 21H
Where MOV AH, 2 is an output function used to show the output in a new line. DL
is a display function used to display the new line and 10 is the ASCII value of a
new line.
To display the output we use MOV DL, BL. Here, DL is the display register. The
input we have in BL will be shifted to DL so that we can see the output. Again INT
21H function will execute immediate previous function. The MAIN ENDP is used to
end the program and END MAIN is used to end the main procedure.
6
Question: 03
Write a program that takes one input and shows the output in a new line without
a space using assembly language programming.
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1
INT 21H
MOV BL, AL
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
7
INT 21H
MOV AH, 2
MOV DL, BL
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
.MODEL SMALL
.STACK 100H
.CODE
8
Works as header files.
MAIN PROC is the main function for this program where PROC stands for
procedure. Here MOV AH, 1 works as an input function which moves instructions
from register to registers. AH is an 8 bit register. AH is the destination and 1 is the
source here. INT is an interrupt function. INT 21H function arrives in a program,
microprocessor stops and executes its immediate previous function. MOV BL, AL
is a function where AL is source and BL is destination. The input which AL is
containing will move to the destination BL. To show the output in a new line we
use,
MOV AH, 2
MOV DL, 10
INT 21H
Where MOV AH, 2 is an output function used to show the output in a new line. DL
is a display function used to display the new line and 10 is the ASCII value of a
new line.
The line MOV DL, 13 describes that 13 is the ASCII value for carry is return. So, DL
will display the output without a space in the front.
To display the output we use MOV DL, BL. Here, DL is the display register. The
input we have in BL will be shifted to DL so that we can see the output. Again INT
21H function will execute immediate previous function. The MAIN ENDP is used to
end the program and END MAIN is used to end the main procedure.
9
Question: 04
Write a program that takes multiple inputs and shows the outputs in a new line
without a space using assembly language programming.
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1
INT 21H
MOV BL, AL
INT 21H
MOV BH, AL
INT 21H
10
MOV CL, AL
INT 21H
MOV CH, AL
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH, 2
MOV DL, BL
INT 21H
MOV DL, BH
INT 21H
MOV DL, CL
INT 21H
MOV DL, CH
11
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
4569
4569
.MODEL SMALL
.STACK 100H
.CODE
12
MAIN PROC is the main function for this program where PROC stands for
procedure. Here MOV AH, 1 works as an input function which moves instructions
from register to registers. INT is an interrupt function. When INT 21H function
arrives in a program, microprocessor stops and executes its immediate previous
function. Here, the previous function is MOV AH, 1 that is why, the input function
will be executed. To take input MOV BL, AL is used where AL will take an input
and place that input in BL. Then INT 21H function is used to execute the
immediate function which is the input function. To take another input, again we
use MOV BH, AL where AL takes another input and place it in BH. INT 21H
executes the input function. To take more inputs same steps should be followed.
MOV AH, 2
MOV DL, 10
INT 21H
Where MOV AH, 2 is an output function used to show the output in a new line. DL
is a display function used to display the new line and 10 is the ASCII value of a
new line.
The line MOV DL, 13 describes that 13 is the ASCII value for carry is return. So, DL
will display the output without a space in the front.
To display the output we use our output function MOV AH, 2. The inputs we have
stored in all destination registers will be shifted to DL for displaying. We use MOV
13
DL, BL where DL is the display register. The input we have in BL will be shifted to
DL so that we can see the output. Again INT 21H function will execute immediate
previous function which is the output function MOV AH, 2. The input we have in
BH will be shifted to DL. All the inputs will be shown using the same steps as
previous.
The MAIN ENDP is used to end the program and END MAIN is used to end the
main procedure.
Question: 05
Source Code:
.MODEL SMALL
.STACK 100H
.DATA
.CODE
MAIN PROC
14
MOV AX, @DATA
MOV DS, AX
MOV AH, 9
INT 21H
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH, 9
INT 21H
EXIT:
INT 21H
15
MAIN ENDP
END MAIN
Output:
AFRINA DIPTI
AFROZA ARNA
In these lines, MSG1 and MSG2 is used for displaying strings. Here DB is used to
allocate the string message. We use ‘$’ sign to stop the string message.
LEA DX, MSG1 in this instruction LEA stands for load effective address. We use DX
to load our MSG1 in DX.
16
INT 21H this function as usual interrupts to execute its immediate previous
function.
Again previous three lines are used for same operation. And then the MAIN ENDP
is used to end the program and END MAIN is used to end the main procedure.
Question: 06
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1
INT 21H
MOV BL, AL
INT 21H
MOV CL, AL
17
ADD BL, CL
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH, 2
MOV DL, BL
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
18
32
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC is the main function for this program where PROC stands for
procedure. Here MOV AH, 1 works as an input function which moves instructions
from register to registers. INT is an interrupt function. When INT 21H function
arrives in a program, microprocessor stops and executes its immediate previous
function. Here, the previous function is MOV AH, 1 that is why, the input function
will be executed.
MOV BL, AL in this line we take input in source register AL and move that input
into our destination register BL. And in MOV CL, AL this line we take our second
input in source register AL and move that input into our destination register CL.
ADD BL, CL in this line, the actual addition happens of two inputs.
19
MOV DL, BL here BL where the addition has been placed moves to the display
register DL.
MOV AH, 2
MOV DL, BL
These three lines are used because when we run our program it prints the
characters. Those characters correspond to the value of our expected result plus
48. So if we subtract 48 from our result BL then we will get our final addition.
Question: 07
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
20
MOV AH, 1
INT 21H
MOV BL, AL
INT 21H
MOV CL, AL
SUB BL, CL
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH, 2
MOV DL, BL
INT 21H
EXIT:
21
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Output:
53
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC is the main function for this program where PROC stands for
procedure. Here MOV AH, 1 works as an input function which moves instructions
from register to registers. INT is an interrupt function. When INT 21H function
arrives in a program, microprocessor stops and executes its immediate previous
22
function. Here, the previous function is MOV AH, 1 that is why, the input function
will be executed.
MOV BL, AL in this line we take input in source register AL and move that input
into our destination register BL. And in MOV CL, AL this line we take our second
input in source register AL and move that input into our destination register CL.
SUB BL, CL in this line, the actual subtraction happens between two inputs.
MOV DL, BL here BL where the subtraction has been placed moves to the display
register DL.
MOV AH, 2
MOV DL, BL
These three lines are used because when we run our program it prints any value
from our ASCII table. Those values correspond to the value of our expected result
minus 48. So if we subtract 48 from our result BL then we will get our final
subtracted result.
Question: 08
23
Write a program to declare variable using assembly language programming.
Source Code:
.MODEL SMALL
.MODEL SMALL
.STACK 100H
.DATA
VAR DB 5
.CODE
MAIN PROC
MOV DS, AX
MOV AH, 2
INT 21H
EXIT:
24
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Output:
Description: First we have to declare the variable inside our code segment.
VAR DB 5: Here VAR is our variable name. DB allocates memory for data segment.
Our declared variable is 5.
Then the main function starts. Inside our code segment we have to initialize our
data segment like,
MOV DS, DX
Then we’ll have to print our variable through our output function.
Question: 09
25
Source Code:
.MODEL SMALL
.STACK 100H
.DATA
VAR1 DB ?
VAR2 DB ?
.CODE
MAIN PROC
MOV DS, AX
MOV AH, 1
INT 21H
MOV VAR1, AL
INT 21H
MOV VAR2, AL
MOV AH, 2
26
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH, 2
INT 21H
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
52
27
52
.MODEL SMALL
.STACK 100H
.CODE
VAR1 DB ?
VAR2 DB ?
name DB value
MAIN PROC is the main function for this program where PROC stands for
procedure. Here MOV AH, 1 works as an input function which moves instructions
from register to registers. INT is an interrupt function. When INT 21H function
28
arrives in a program, microprocessor stops and executes its immediate previous
function. Here, the previous function is MOV AH, 1 that is why, the input function
will be executed.
MOV VAR1, AL in this line we take our first input variable in AL and copy it in
VAR1. Then we take our second variable in AL and move it in VAR2.
MOV AH, 2 this is our output function. Now our output function is used to show
our two variables as output.
Question: 10
Source Code:
.MODEL SMALL
.STACK 100H
.DATA
VAR DB ?
.CODE
MAIN PROC
29
MOV AX, @DATA
MOV DS, AX
MOV AH, 1
INT 21H
MOV VAR, AL
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH, 2
INT 21H
MOV AH, 2
SUB VAR, 17
30
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
13
We will have to declare a variable VAR DB? for our input case. For our
hexadecimal number we will have to take input first. We know that in our
hexadecimal numbers there are characters from A to F and they all have ‘1’ in
their tenfold. So we will have to print a ‘1’ in our code.
MOV AH, 2
31
INT 21H
To print our expected character, we will have to subtract 17 from our variable
because of ASCII table and the line is,
SUB VAR, 17
Question: 11
Source Code:
.MODEL SMALL
.STACK 100H
.DATA
MSG2 DB 'GREATER$'
MSG3 DB 'SMALLER$'
32
.CODE
MAIN PROC
MOV DS, AX
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
MOV BL, AL
SUB BL, 48
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
33
CMP BL, 5
JL L1
MOV AH, 9
INT 21H
JMP EXIT
L1:
MOV AH, 9
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
34
3
Smaller
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC is the main function for this program where PROC stands for
procedure.
First we will declare some message inside our data segment like
MSG2 DB 'GREATER$'
MSG3 DB 'SMALLER$'
MOV DS, AX
35
To our first value it will print MSG1. For that we write:
MOV AH, 9
INT 21H
We use SUB BL, 48 this line because emulator doesn’t understand decimal
number. For that we have to subtract 48 from our input.
We can use any value two compare our input with. Here I have take 5 as a
comparing value. CMP is our keyword to compare values.
JMP EXIT: After satisfying all the conditions it will jump to EXIT to end our
program.
36
LEA DX, MSG3: If the condition CMP BL, 5 is true then it will print message 3 which
prints smaller.
Question: 12
Source Code:
.MODEL SMALL
.STACK 100H
.DATA
.CODE
MAIN PROC
37
MOV AX, @DATA
MOV DS, AX
MOV AH, 9
INT 21H
MOV AH, 1
INT 21H
MOV BL, AL
SUB BL, 48
CMP BL, 4
JGE L2
L1:
MOV AH, 9
INT 21H
JMP EXIT
38
CMP BL, 7
JNG L3
JMP L1
L3:
MOV AH, 9
INT 21H
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
5 In Range
39
To enter an input first message will be printed.
SUB BL, 48: For the emulator to understand our input value in decimal we will
subtract 48 from BL.
CMP BL, 4: In my code, I have taken 4 to 7 as my range and first I will compare the
input with 4.
JGE L2: After comparing if input is greater than or equal 4 then it will jump to level
L2.
LEA DX, MSG3: If our input is not in our range it will print MSG3.
JNG L3: If our input value is not greater than or equal then it will jump to L3.
JMP L1: If the condition is true then it will jump to level L1.
LEA DX, MSG2: After satisfying the above conditions it will print message 2.
40
Then it will end our program by,
EXIT:
INT 21H
MAIN ENDP
END MAIN
Question: 13
Write a program to repeat and terminate any value using assembly language.
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
L:
MOV AH, 1
41
INT 21H
MOV BL, AL
MOV AH, 2
MOV DL, BL
INT 21H
INT 21H
INT 21H
CMP BL, 63
JE EXIT
JMP L
EXIT:
INT 21H
MAIN ENDP
42
END MAIN
Output:
55
77
11
Description: First we have to level our code with L. Then take our input value
and move it into BL from AL. And then print our input.
CMP BL, 63: In this line we will compare our input with a specific value. Here I
have taken 63 which is the ASCII value of ‘?’. So, if we take ‘?’ as our input it will
repeat our input and terminate the program.
Question: 14
Source Code:
43
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH,1
INT 21H
MOV BL,AL
INT 21H
MOV BH, AL
INT 21H
MOV CL, AL
CMP BL, BH
JGE L2
L1:
CMP BH, CL
JGE LL1
44
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH, 2
MOV DL, CL
INT 21H
JMP EXIT
LL1:
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH,2
45
MOV DL,BH
INT 21H
JMP EXIT
L2:
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
CMP BL,CL
JGE LL2
MOV AH,2
MOV DL,CL
INT 21H
JMP EXIT
LL2:
46
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
MOV AH,2
MOV DL,BL
INT 21H
JMP EXIT
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
47
573
Description: To print the greatest number we will take three inputs and print
the greatest value among them. We will have to move three inputs into different
registers.
CMP BL, BH: Here we are comparing the second value with the first one.
CMP BH, CL: Now our second value BH is being compared with CL.
MOV DL, BH: If BH is the greatest value then it will jump to LL1 level and will move
the value from BH to DL to display.
CMP BL, CL: If the previous conditions don’t satisfy then it will compare BL with
CL.
48
JGE LL2: If BL is greater than or equal to CL then it will jump to LL2.
And then it will end our program by printing the greatest value among three
inputs.
Question: 15
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1
INT 21H
MOV BL, AL
49
SUB AL, 48
LOOP:
MOV CX,0
MOV CL,AL
MOV AH,2
MOV DL,'#'
TOP:
INT 21H
LOOP TOP
EXIT:
INT 21H
MAIN ENDP
END MAIN
Output:
############################################
50
Description: First the program will take any value as an input and then subtract
it from 48 using SUB AL, 48.
MOV CX, 0: Here we have used a 16 bits register CX. We have initialized CX as 0.
MOV CL, AL: The value that we have in AL now will be moved to CL.
MOV DL,'#': Here I want to print ‘#’ in a loop. That’s why ‘#’ will be moved to DL.
Question: 16
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH, 1
51
INT 21H
MOV BL, AL
SUB AL, 48
MOV CX, 0
MOV CL, AL
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
TOP:
MOV AH, 2
MOV DL, BL
INT 21H
DEC BL
LOOP TOP
52
EXIT:
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
Output:
54321
Description: First we will take an input and then move it from AL to BL.
MOV CL, AL: Then the value would be shifted from AL to CL.
DEC BL: Now DEC is used for doing the actual operation here which is decreasing.
After the values reach to ‘1’ the program will terminate and exit.
53
Question: 17
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV AH,1
INT 21H
MOV BL,AL
MOV CL,'1'
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
54
INT 21H
TOP:
MOV AH,2
MOV DL,CL
INT 21H
INC CL
CMP BL,CL
JE EXIT
JMP TOP
EXIT:
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
Output:
55
12345
Description: First as usual we will have to take an input value for which the
program will show the ascending order. The input will be shifted to BL from AL
using,
MOV BL, AL
MOV CL,'1': Whatever value we take as our input for showing our ascending order
to, it will always have a ‘1’ in it. That is why we have to initialize CL with ‘1’.
MOV DL, CL: Now we will display the ‘1’ from CL.
CMP BL, CL: Now the increased CL value will be compared with BL every time it
increases.
JE EXIT: Finally when our increased value matches with our input value then our
program will jump to exit.
JMP TOP: It will jump to TOP if our increased value is not equal to our input
value.
When our increased value matches with our input value, our program will be
terminated.
56
Question: 18
Write a program to display star print multiline using nested loop in assembly
language.
Source Code:
.MODEL SMALL
.STACK 100H
.DATA
.CODE
MAIN PROC
MOV CX,4
MOV BX,2
TOP:
MOV AH,2
MOV DL,'*'
INT 21H
DEC BX
57
CMP BX,0
JE EXIT
JMP TOP
EXIT:
MOV AH,2
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
MOV BX,2
LOOP TOP
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
Output:
58
**
**
**
Description: Since we are printing a * that’s why the * needs to be placed in DL.
Here we have two loops CX and BX.
The lines,
MOV BX, 2: No. of stars means that for line no. 1 two stars will be printed, for line
2 again two stars will be printed and like this for line 4 again two stars will be
printed.
Then BX will be compared with 0. If BX=0 then the program will be executed. If
not then it will jump to the level TOP.
After printing two stars, we will need new lines to print our next two stars in line
2, 3 and 4. That’s why after EXIT we will use the new line instructions. And also
another LOOP BX, 2 will be declared. With 2 BX will jump to the TOP and print two
stars and the BX will be decreased to 0. Then after comparing it will jump go to
EXIT.
After that it will go to the second line. And with LOOP=2 it will again go to the
TOP. Like this the remaining stars will be printed.
59
Question: 19
Write a program to print ASCII table using nested for loop with assembly
language.
Source Code:
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV CX,0
L1:
MOV BX,CX
MOV CX,8
L2:
MOV AH,2
MOV DL,BL
60
INT 21H
INC BL
CMP BL,255
JE EXIT
LOOP L2
MOV AH, 2
MOV DL, 10
INT 21H
MOV DL, 13
INT 21H
INC BL
MOV CX,BX
LOOP L1
EXIT:
MOV AH,4CH
INT 21H
61
MAIN ENDP
END MAIN
Output:
@ABCDEFG
HIJKLMNOP
QRSTUVWX
...........
...........
...........
Description: MOV CX, 8 means in every line 8 character will be printed. We will
place our ASCII table’s symbols in BL. Then we will have to increase BL until it
reaches to 255 because there are 255 symbols in the ASCII table. We have to
compare BL with 255. When BL will be 255 the code will jump to EXIT.
Discussion: In our first lab, we learned about the emulator. We have learned
how an emulator works, which operation does which work, how to create and
save files, about different functions etc. We have also learned how to take inputs
62
and show them as outputs, how to show them in a new line, how can we take
multiple inputs. As this was our first lab, I faced problems while running my
program. I also faced some difficulties in handling the emulator software.
63