CSC 202 Low Level Language Manual
CSC 202 Low Level Language Manual
Programming
(CSC202)
Laboratory
Manual
Page 1 of 51
TABLE OF CONTENTS
LAB ONE ....................................................................................................................................... 3
Addition of Two 16-bit Numbers (With and Without Carry) using 8086 Microprocessor ............ 3
LAB TWO Subtraction of Two 16-bit Numbers (With and Without Borrow) using 8086
Microprocessor ............................................................................................................................... 8
LAB THREE................................................................................................................................. 13
Multiplication of Two 8-bit Numbers by Repetitive Addition using 8086 Microprocessor ........ 13
Read 16-bit Data from a Port and Display the Same in Another Port Using 8086 Microprocessor
....................................................................................................................................................... 29
LAB SEVEN................................................................................................................................. 34
Generate a Square Wave of 10 KHz Using Timer 1 in Mode 1 (Using 8051 Microcontroller) ... 34
LAB EIGHT.................................................................................................................................. 40
Write a Program for the Traffic Light Controller Using 8086 Microprocessor ........................... 46
Page 2 of 51
LAB ONE
Addition of Two 16-bit Numbers (With and Without Carry) using 8086 Microprocessor
Objective(s):
• Hardware:
o Computer (Desktop/Laptop) with minimum 4GB RAM.
• Software:
o 8086 trainer kit and 8086 emulator software (e.g., EMU8086, DOSBox with
MASM/TASM).
o Text Editor (e.g., Notepad++).
o Assembler and Debugging tools.
Lab Activities:
In this lab session, you will write an assembly language program for the 8086 microprocessor to
add two 16-bit numbers. You will perform addition with and without considering the carry
generated during the operation.
You will also become familiar with using registers (AX, BX, CX, DX) and memory addressing
techniques. The lab will introduce you to basic instruction sets such as MOV, ADD, ADC, MOV, and
HLT.
Instructor Demonstration:
Algorithm/Pseudocode:
Page 3 of 51
2. Load second 16-bit number into BX or directly ADD to AX.
3. Perform addition (ADD AX, NUM2).
4. Store result in memory (RESULT).
5. Terminate program.
Hands-on Activity:
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
Page 4 of 51
Program (Addition with Carry):
; Program to add two 16-bit numbers considering carry
.MODEL SMALL
.STACK 100H
.DATA
NUM1 DW 0FFFFH
NUM2 DW 0002H
RESULT DW ?
CARRY DW ?
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
CARRY_LABEL:
MOV CARRY, 1
END_PROGRAM:
; Terminate the program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Observation Notes:
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Page 5 of 51
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Page 6 of 51
Required to Do at Home:
Homework Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 7 of 51
LAB TWO
Subtraction of Two 16-bit Numbers (With and
Without Borrow) using 8086 Microprocessor
Objective(s):
• Hardware:
o Computer (Desktop/Laptop) with minimum 4GB RAM.
• Software:
o 8086 Emulator (e.g., EMU8086, DOSBox with MASM/TASM).
o Text Editor (e.g., Notepad++).
o Assembler and Debugging tools.
Lab Activities:
In this lab session, you will write an assembly language program to subtract two 16-bit numbers,
both with and without considering borrow.
Instructor Demonstration:
Algorithm/Pseudocode:
Page 8 of 51
Subtraction with Borrow:
Hands-on Activity:
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
Page 9 of 51
Program (Subtraction with Borrow):
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
BORROW_OCCURRED:
MOV BORROW, 1
END_PROGRAM:
; Terminate the program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Observation Notes:
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Page 10 of 51
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Required to Do at Home:
Page 11 of 51
Homework Notes:
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Page 12 of 51
LAB THREE
Multiplication of Two 8-bit Numbers by Repetitive Addition using 8086 Microprocessor
Objective(s):
• Hardware:
o Computer (Desktop/Laptop) with minimum 4GB RAM.
• Software:
o 8086 Emulator (e.g., EMU8086, DOSBox with MASM/TASM).
o Text Editor (e.g., Notepad++).
o Assembler and Debugging tools.
Lab Activities:
In this lab session, you will write an assembly language program to multiply two 8-bit numbers
using repetitive addition method.
Instructor Demonstration:
Algorithm/Pseudocode:
Page 13 of 51
Hands-on Activity:
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
START_LOOP:
CMP BL, 0 ; Check if multiplier is 0
JE END_LOOP ; If yes, exit loop
ADD CX, AX ; Add multiplicand to result
DEC BL ; Decrement multiplier
JMP START_LOOP ; Repeat
END_LOOP:
MOV RESULT, CX ; Store final result
Observation Notes:
Page 14 of 51
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Page 15 of 51
Required to Do at Home:
2. Research:
i. What instructions does 8086 provide for direct multiplication (MUL)?
Homework Notes:
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Page 16 of 51
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Page 17 of 51
LAB FOUR
Generate Fibonacci Series up to 16 Terms Using 8086 Microprocessor
Objective(s):
• Hardware:
o Computer (Desktop/Laptop) with minimum 4GB RAM.
• Software:
o 8086 Emulator (e.g., EMU8086, DOSBox with MASM/TASM).
o Text Editor (e.g., Notepad++).
o Assembler and Debugging tools.
Lab Activities:
In this lab, you will create an assembly program that generates the first 16 terms of the Fibonacci
sequence.
Instructor Demonstration:
Algorithm/Pseudocode:
Page 18 of 51
Hands-on Activity:
NEXT_TERM:
; Load previous two terms
MOV AL, FIB[SI-1]
ADD AL, FIB[SI-2]
; End program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Page 19 of 51
Observation Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 20 of 51
Required to Do at Home:
Homework Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 21 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 22 of 51
Lab FIVE
Generate Factorial of a Number from 0 to 9 Using 8086 Microprocessor
Objective(s):
• Hardware:
o Computer (Desktop/Laptop) with minimum 4GB RAM.
• Software:
o 8086 Emulator (e.g., EMU8086, DOSBox with MASM/TASM).
o Text Editor (e.g., Notepad++).
o Assembler and Debugging tools.
Lab Activities:
In this lab, you will write an assembly program that generates and stores the factorials of
numbers from 0 to 9.
Instructor Demonstration:
Algorithm/Pseudocode:
Page 23 of 51
5. End program.
Hands-on Activity:
NEXT_NUM:
MOV BX, 1 ; Initialize factorial to 1
; Check if number is 0
CMP CX, 0
JE STORE_FACT
CALC_FACT:
MUL DX ; AX = AX * DX
DEC DX
CMP DX, 1
JG CALC_FACT
STORE_FACT:
MOV FACT[SI], AX ; Store result
ADD SI, 2 ; Move to next word in FACT
INC CX ; Increment number (0 to 9)
CMP CX, 10
JL NEXT_NUM ; Loop till number < 10
; End program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Page 24 of 51
Required to Do in the Lab:
Observation Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 25 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 26 of 51
Required to Do at Home:
Homework Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 27 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 28 of 51
LAB SIX
Read 16-bit Data from a Port and Display the Same in Another Port Using 8086
Microprocessor
Objective(s):
• Hardware:
o Computer (Desktop/Laptop) with minimum 4GB RAM.
o I/O Interface (for actual hardware setup — optional for simulation).
• Software:
o 8086 Emulator (e.g., EMU8086, DOSBox with MASM/TASM).
o Text Editor (e.g., Notepad++).
o Assembler and Debugging tools.
Lab Activities:
In this lab, you will write an assembly program that reads a 16-bit value from an input port and
immediately writes that value to an output port.
Instructor Demonstration:
Algorithm/Pseudocode:
Page 29 of 51
Hands-on Activity:
Program (Read 16-bit Data from Port and Output to Another Port):
; Program to read 16-bit data from one port and output it to another port
.MODEL SMALL
.STACK 100H
.DATA
IN_PORT EQU 00H ; Define input port address
OUT_PORT EQU 02H ; Define output port address
.CODE
MAIN PROC
MOV DX, IN_PORT ; Load input port address into DX
IN AX, DX ; Read 16-bit data from input port into AX
; End program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
Important:
IN and OUT instructions use the DX register for port addressing when working with 16-bit data.
If simulating on an emulator without actual I/O ports, you may simulate port reading/writing
operations.
Observation Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 30 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 31 of 51
Required to Do at Home:
Homework Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 32 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 33 of 51
LAB SEVEN
Generate a Square Wave of 10 KHz Using Timer 1 in Mode 1 (Using 8051 Microcontroller)
Objective(s):
1. Learn how to configure Timer 1 in Mode 1 (16-bit timer mode) of the 8051
Microcontroller.
2. Generate a square wave of 10 kHz frequency using the timer.
3. Understand how to calculate the timer's value to produce a specific frequency.
• Hardware:
o 8051 Microcontroller Development Kit.
o Oscilloscope (to view the generated square wave).
o Connecting cables.
• Software:
o Keil µVision (or any compatible IDE for 8051 programming).
o Assembler/Compiler for 8051.
o Debugger (for simulating the program if hardware is unavailable).
Lab Activities:
In this lab, you will configure Timer 1 of the 8051 microcontroller to generate a square wave
with a frequency of 10 kHz.
Instructor Demonstration:
1. Explain how Timer 1 in Mode 1 (16-bit mode) is used to generate accurate delays.
2. Walk through the process of configuring the timer and generating the required square
wave.
3. Discuss how to calculate the timer count for a specific frequency.
Algorithm/Pseudocode:
Page 34 of 51
Calculation for Timer Setup:
1 1
Time Period = = = 0.0001 seconds = 100 𝜇s
Frequency 10000
• The 8051 timer operates at 12 MHz clock frequency, so the timer increment is:
1
Timer Tick Time = = 83.33 nanoseconds
12 MHz
50 × 10−6
Number of Ticks = ≈ 600
83.33 × 10−9
• The timer works in 16-bit mode (Mode 1), so it counts from 0 to 65535. We need to load
the timer with a value that allows it to count the required number of ticks. To achieve
this:
Hands-on Activity:
Page 35 of 51
Program (Generate 10 kHz Square Wave Using Timer 1 in Mode 1):
; Start Timer 1
SETB TR1 ; Set TR1 bit to start Timer 1
TOGGLE_PIN:
CLR TF1 ; Clear Timer 1 overflow flag (TF1)
CPL P1.0 ; Toggle P1.0 (square wave)
MOV TH1, #0xF9 ; Reload Timer 1 high byte
MOV TL1, #0xE0 ; Reload Timer 1 low byte
RETI ; Return from interrupt (if using interrupt)
; End of program
END
Observation Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 36 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 37 of 51
Required to Do at Home:
1. Modify the program to generate different frequencies (e.g., 5 kHz, 20 kHz) by adjusting
the timer reload values.
2. Research:
o The difference between Mode 0, Mode 1, and Mode 2 of the 8051 timers.
o The impact of different clock frequencies on timer-based delay calculations.
Homework Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 38 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 39 of 51
LAB EIGHT
Transfer Data from ROM Memory to RAM Memory
Objective(s):
1. Understand how to transfer data between ROM and RAM in the 8051 microcontroller.
2. Learn how to access both ROM (read-only memory) and RAM (random access memory)
in the 8051 microcontroller.
3. Develop a program to transfer data stored in ROM to RAM using assembly language.
• Hardware:
o 8051 Microcontroller Development Kit.
o Development board with available ROM and RAM locations.
• Software:
o Keil µVision (or any compatible IDE for 8051 programming).
o Assembler/Compiler for 8051.
o Debugger (for simulating the program if hardware is unavailable).
Lab Activities:
In this lab, you will write a program to transfer data from ROM memory to RAM memory. This
program will demonstrate direct memory addressing and data transfer using the MOV
instruction.
Instructor Demonstration:
1. Show how ROM memory is typically read-only and used for storing program code, while
RAM is used for temporary data storage.
2. Walk through the process of transferring a block of data from ROM to RAM using the
MOV instruction.
3. Discuss how to use memory addresses in assembly language.
Algorithm/Pseudocode:
1. Initialize a pointer to the ROM address from where the data is stored.
2. Initialize a pointer to the RAM address where the data needs to be transferred.
3. Loop through each byte of data in ROM, transferring it to RAM one by one.
4. Once the entire data block is transferred, end the program or display a confirmation
message.
Page 40 of 51
Program Description:
The program will transfer data from a specific ROM address (e.g., 0x30) to a specific RAM
address (e.g., 0x50). The transfer will happen byte by byte until a specified amount of data is
moved.
Hands-on Activity:
START:
; Initialize source ROM address and destination RAM address
MOV DPTR, #ROM_ADDRESS ; Set Data Pointer to source ROM address
MOV R0, #RAM_ADDRESS ; Load the RAM address into register R0
; Program ends
NOP ; No operation, can add other instructions as
needed
END
1. MOV DPTR, #ROM_ADDRESS: The Data Pointer (DPTR) is initialized with the
ROM address from where the data is to be read. In this case, replace ROM_ADDRESS with
the actual address in ROM.
2. MOV R0, #RAM_ADDRESS: The R0 register is initialized with the starting address in
RAM where the data will be stored.
Page 41 of 51
3. MOV A, @DPTR: Loads the data from the current ROM address into the Accumulator
(A).
4. MOV @R0, A: Transfers the data in the Accumulator to the RAM location pointed to
by R0.
5. INC DPTR: Increments the Data Pointer to point to the next ROM address.
6. INC R0: Increments the R0 register to point to the next RAM location.
7. MOV R2, #5: Initializes a counter (R2) for 5 bytes to be transferred. You can adjust this
number as needed.
8. TRANSFER_LOOP: The program loops through the transfer process, moving data byte
by byte, until all 5 bytes are transferred from ROM to RAM.
Observation Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 42 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Required to Do at Home:
Page 43 of 51
2. Research how memory is organized in 8051 microcontroller and how to manage ROM
and RAM efficiently in assembly language.
Homework Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 44 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 45 of 51
LAB NINE
Write a Program for the Traffic Light Controller Using 8086 Microprocessor
Objective(s):
• Hardware:
o 8086 Microprocessor Development Kit.
o Traffic light simulation kit (or LEDs to represent the traffic lights).
o Appropriate interfacing circuitry (LED drivers, switches, etc.).
• Software:
o Keil µVision (or any compatible IDE for 8086 programming).
o Assembler/Compiler for 8086.
o Debugger or Simulator for testing the program.
Lab Activities:
In this lab, you will simulate a traffic light controller using the 8086 microprocessor. The
program will control a set of traffic lights (Red, Yellow, Green) for different intersections.
Instructor Demonstration:
1. Explain the typical operation of a traffic light control system, including the timing for
each light (Green, Yellow, Red).
2. Walk through how to implement this logic using assembly language on the 8086
microprocessor.
3. Discuss how to use I/O ports for controlling the traffic lights (e.g., turning LEDs on and
off).
Algorithm/Pseudocode:
1. Initialize the I/O ports to control the traffic lights (e.g., using LEDs to represent Red,
Yellow, and Green).
2. Set the traffic light cycle with specific time intervals for each light (e.g., Green for 10
seconds, Yellow for 2 seconds, and Red for 10 seconds).
Page 46 of 51
3. Continuously loop through the cycle of Red, Yellow, and Green lights, adjusting the time
spent on each.
4. Optionally, use a delay subroutine to control the timing of each light.
5. Implement the program with the traffic light sequence (Green → Yellow → Red →
Green → Yellow → Red, etc.).
Program Description:
The program will control a set of three traffic lights using LEDs connected to the
microprocessor. The traffic lights will follow a timed sequence of Green, Yellow, and Red, with
specified durations for each color.
Hands-on Activity:
START:
; Green Light Cycle
MOV AL, 01H ; Turn on Green Light (1st bit)
OUT 0X300, AL ; Output to Port 0x300
CALL DELAY ; Wait for 10 seconds (Green Light duration)
Page 47 of 51
Explanation of the Program:
1. MOV AL, 0FFH: Initializes the AL register to 0xFF, which turns off all traffic lights
(assuming each bit controls a traffic light).
2. MOV AL, 01H: Turns on the Green light (bit 0).
3. MOV AL, 02H: Turns on the Yellow light (bit 1).
4. MOV AL, 04H: Turns on the Red light (bit 2).
5. OUT 0X300, AL: Sends the value of the AL register to the I/O port (assumed to be
0x300 in this example), which controls the traffic lights (represented by LEDs).
6. CALL DELAY: Calls the delay subroutine, which is responsible for waiting a specific
time before changing the light.
7. DELAY Subroutine: A simple loop that counts down to create a delay. The NOP
instruction is used to consume time without doing anything, and the DEC CX decrements
the count until the desired delay is reached.
Observation Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 48 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 49 of 51
Required to Do at Home:
1. Modify the program to change the timing of the lights (e.g., Green for 15 seconds,
Yellow for 3 seconds, and Red for 12 seconds).
2. Experiment with different ways to generate delays (e.g., using timers or counters).
3. Research how timers in the 8086 microprocessor could be used to improve the delay
function.
Homework Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 50 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
Page 51 of 51