0% found this document useful (0 votes)
214 views

Lab Report

The document discusses a lab report submitted by Afrina Sultana for their Microprocessor and Micro Controller course. It includes programs written in assembly language to: 1) Print a triangle of stars of varying sizes. 2) Exchange and swap values stored in registers. 3) Implement logic operations like AND, OR, XOR on binary values and display the results. 4) Check a password by comparing user input to a stored value. The programs demonstrate the use of loops, logic operations, input/output functions and conditional jumps in assembly language.

Uploaded by

Afrina Dipti
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
214 views

Lab Report

The document discusses a lab report submitted by Afrina Sultana for their Microprocessor and Micro Controller course. It includes programs written in assembly language to: 1) Print a triangle of stars of varying sizes. 2) Exchange and swap values stored in registers. 3) Implement logic operations like AND, OR, XOR on binary values and display the results. 4) Check a password by comparing user input to a stored value. The programs demonstrate the use of loops, logic operations, input/output functions and conditional jumps in assembly language.

Uploaded by

Afrina Dipti
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Central Women’s University

Lab Report: 02

Course Title: Microprocessor and Micro Controller Sessional

Course Code: CSE-334

Submitted By:

Afrina Sultana

ID: 2018-1-17-016

Department of Computer Science and Engineering

Submitted To:

Ayesha Siddiqua

Lecturer

Department of CSE, CWU

Submission Date: 21-10-2020


Introduction: In this lab we have discussed one program of our previous lab and
also worked with new instructions and OPCODES. The programs that I learnt in
this lab are OR, AND, XOR implementations, how to check password, swap
values etc.

Question: 05

Write a program to print triangle of star using assembly language.

Source Code:

.MODEL SMALL

.STACK 100H

.CODE

MAIN PROC

MOV CX, 4

LEVEL1:

MOV BX, CX

LEVEL2:

MOV AH, 2

MOV DL, '*'

INT 21H

LOOP LEVEL2
1
MOV AH, 2

MOV DL, 10

INT 21H

MOV DL, 13

INT 21H

MOV CX, BX

LOOP LEVEL1

EXIT:

MOV AH, 4CH

INT 21H

MAIN ENDP

END MAIN

Output:

2
****

***

**

Explanation: In this code the first three lines,

.MODEL SMALL

.STACK 100H

.CODE

Work as header files.

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.

We’ll declare our first level like this:

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,

LEVEL2: This is our second level.

MOV AH, 2

MOV DL, '*'

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.

Then we use the instructions to print a new line.

Now we write the lines,

MOV CX, BX

Here the value of BX will be copied into CX.

LOOP LEVEL1: Here the new CX value will be decreased and it will go to
LEVEL1.

To end our program we write,

EXIT:

MOV AH, 4CH

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:

MOV AH, 4CH

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

Work as header files.

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.

In our code first we took two inputs through BL and BH register.

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.

The main work is done by the XCHG OPCODE.

To end our program we write,

EXIT:

MOV AH, 4CH

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

A DB 10, 13,'FOR AND $'

B DB 10, 13,'FOR OR $'

C DB 10, 13,'FOR XOR $'

D DB 10, 13,'FOR ADD $'

E DB 10, 13,'FOR SUB $'

.CODE

MAIN PROC

MOV AX, @DATA

MOV DS, AX

MOV AH, 9

LEA DX, A

INT 21H

11
MOV BL, 111B

AND BL, 101B

ADD BL, 48

MOV AH, 2

MOV DL, BL

INT 21H

LEVELOR:

MOV AH, 9

LEA DX, B

INT 21H

MOV BL, 100B

OR BL, 110B

ADD BL, 48

MOV AH, 2

12
MOV DL, BL

INT 21H

LEVELXOR:

MOV AH, 9

LEA DX, C

INT 21H

MOV BL, 111B

XOR BL, 101B

ADD BL, 48

MOV AH, 2

MOV DL, BL

INT 21H

LEVELADD:

MOV AH, 9

LEA DX, D
13
INT 21H

MOV BL, 011B

ADD BL, 100B

ADD BL, 48

MOV AH, 2

MOV DL, BL

INT 21H

LEVELSUB:

MOV AH, 9

LEA DX, E

INT 21H

MOV BL, 111B

SUB BL, 100B

ADD BL, 48

14
MOV AH, 2

MOV DL, BL

INT 21H

EXIT:

MOV AH, 4CH

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:

MOV AX, @DATA

15
MOV DS, AX

For our first string it will print A. For that we write:

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.

Then we take binary numbers for our inputs as,

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.

ADD BL, 48: Converts the result from binary to decimal.

To show the output we write,

MOV AH, 2

MOV DL, BL

INT 21H

Now for our OR operation we write,

LEVELOR:

16
MOV AH, 9

LEA DX, B

INT 21H

These lines print the string of B.

MOV BL, 100B: Number 100 is copied to BL register.

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.

To print the output result we write,

MOV AH, 2

MOV DL, BL

INT 21H

Similarly we can implement the operations of XOR, ADD and SUB.

To end our program we write the following,

EXIT:

MOV AH, 4CH

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

Write a program to check password using assembly language.

Source Code:

.MODEL SMALL

.STACK 100H

.DATA

A DB 'ENTER YOUR PASSWORD $'

OK DB 'CORRECT PASSWORD $'

NOTOK DB 'WRONG PASSWORD $'

PASS DB 'DIPTI $'

PASS1 DW 5

.CODE

18
MAIN PROC

MOV AX, @DATA

MOV DS, AX

MOV CX, PASS1

MOV BX, OFFSET PASS

MOV AH, 9

LEA DX, A

INT 21H

L1:

MOV AH, 8

INT 21H

CMP AL, [BX]

JNE L2

INC BX

LOOP L1

19
MOV AH, 9

LEA DX, OK

INT 21H

JMP EXIT

L2:

MOV AH, 9

LEA DX, NOTOK

INT 21H

EXIT:

MOV AH, 4CH

INT 21H

MAIN ENDP

END MAIN

Output:

ENTER PASSWORD WRONG PASSWORD

or

20
ENTER PASSWORD CORRECT PASSWORD

Explanation: Inside our data segment we will declare some messages.

INPUT DW 5: My password contains 5 characters. That’s why I have declared 5.

To initialize our data segment we write these two lines:

MOV AX, @DATA

MOV DS, AX

MOV CX, INPUT: The value of my input will be copied to CX.

MOV BX, OFFSET PASS: The values that are placed in the PASS variable is
checked through the OFFSET and copied to BX.

To print our first string for entering the password we write,

MOV AH, 9

LEA DX, A

INT 21H

L1: This is our first level L1.

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.

L2: This is the second level L2.

If any entered character is not equal to the password then following instructions
will be executed.

MOV AH, 9

LEA DX, NOTOK

INT 21H

To end our program we will write,

EXIT:

MOV AH, 4CH

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.

Intel 80x86 Assembly Language OPCODES: An OPCODE is short for


'Operation Code'. An OPCODE is a single instruction that can be executed by the
CPU. Following are the OPCODES used in assembly language.

1. AAA ASCII Adjust for Addition


2. AAD ASCII Adjust for Division
3. AAM ASCII Adjust for Multiplication
4. AAS ASCII Adjust for Subtraction
5. ADC Add With Carry
6. ADD Arithmetic Addition
7. AND Logical And
8. ARPL Adjusted Requested Privilege Level of Selector
9. BOUND Array Index Bound Check
10. BSF Bit Scan Forward
11. BSR Bit Scan Reverse
12. BSWAP Byte Swap
13. BT Bit Test
14. BTC Bit Test with Compliment
15. BTR Bit Test with Reset
16. BTS Bit Test and Set
17. CALL Procedure Call
23
18. CBW Convert Byte to Word
20. CLC Clear Carry
21. CLD Clear Direction Flag
22. CLI Clear Interrupt Flag
23. CLTS Clear Task Switched Flag
24. CMC Complement Carry Flag
25. CMP Compare
26. CMPS Compare String
27. CMPXCHG Compare and Exchange
28. CWD Convert Word to Double word
29. CWDE Convert Word to Extended Double word
30. DAA Decimal Adjust for Addition
31. DAS Decimal Adjust for Subtraction
32. DEC Decrement
33. DIV Divide
34. ENTER Make Stack Frame
35. ESC Escape
36. Floating point instructions no descriptions
37. HLT Halt CPU
38. IDIV Signed Integer Division
39. IMUL Signed Multiply
40. IN Input Byte or Word From Port
41. INC Increment
42. INS Input String from Port
43. INT Interrupt
24
44. INTO Interrupt on Overflow
45. INVD Invalidate Cache
46. INVLPG Invalidate Translation Look Aside Buffer Entry
47. IRET/IRETD Interrupt Return
48. JA/JNBE Jump Above / Jump Not Below or Equal
49. JAE/JNB Jump Above or Equal / Jump on Not Below
50. JB/JNAE Jump Below / Jump Not Above or Equal
51. JBE/JNA Jump Below or Equal / Jump Not Above
52. JC Jump on Carry
53. JCXZ/JECXZ Jump if Register (E)CX is Zero
54. JE/JZ Jump Equal / Jump Zero
55. JG/JNLE Jump Greater / Jump Not Less or Equal
56. JGE/JNL Jump Greater or Equal / Jump Not Less
57. JL/JNGE Jump Less / Jump Not Greater or Equal
58. JLE/JNG - Jump Lessor Equal/Jump Not Greater
59. JMP – Unconditional Jump
60. JNC Jump Not Carry
61. JNE/JNZ Jump Not Equal /Jump Not Zero
62. JNO Jump Not Overflow
63. JNS Jump Not Signed
64. JNP/JPO Jump Not Parity/Jump Parity Odd
65. JO Jump on Overflow
66. JP/JPE Jump on Parity/Jump on Parity Even
67. JS Jump Signed
71. LEA Load Effective Address
25
82. LOOP Decrement CX and Loop if CX Not Zero
83. LOOPE/LOOPZ Loop While Equal /Loop While Zero
84. LOOPNZ/LOOPNE Loop While Not Zero/Loop While Not Equal
88. MOV Move Byte or Word
89. MOVS Move String
90. MOVSX Move with Sign Extend
91. MOVZX Move with Zero Extend
92. MUL Unsigned Multiply
94. NOP No Operation
95. NOT One's Compliment Negation
96. OR Inclusive Logical OR
97. OUT Output Data to Port
99. POP Pop Word off Stack
102. PUSH Push Word onto Stack
105. RCL Rotate Through Carry Left
106. RCR Rotate Through Carry Right
110. RET/RETF - Return From Procedure
111. ROL Rotate Left
112. ROR Rotate Right
114. SAL/SHL – Shift Arithmetic Left/Shift Logical Left
115. SAR – Shift Arithmetic Right
116. SBB Subtract with Borrow
137. SHR Shift Logical Right
141. STC Set Carry
142. STD Set Direction Flag
26
143. STI Set Interrupt Flag
146. SUB Subtract
147. TEST Test for Bit Pattern
150. WAIT/FWAIT Event Wait
152. XCHG Exchange
153. XLAT/XLATB Translate
154. XOR Exclusive OR

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

You might also like