0% found this document useful (0 votes)
51 views51 pages

CSC 202 Low Level Language Manual

The document is a laboratory manual for a course on Low Level Language Programming (CSC202), detailing various lab exercises using the 8086 microprocessor. It includes objectives, hardware and software requirements, lab activities, and sample assembly language programs for operations such as addition, subtraction, and multiplication of numbers. Each lab section emphasizes hands-on experience with low-level programming concepts and provides tasks for both in-lab and at-home practice.

Uploaded by

ibrahima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views51 pages

CSC 202 Low Level Language Manual

The document is a laboratory manual for a course on Low Level Language Programming (CSC202), detailing various lab exercises using the 8086 microprocessor. It includes objectives, hardware and software requirements, lab activities, and sample assembly language programs for operations such as addition, subtraction, and multiplication of numbers. Each lab section emphasizes hands-on experience with low-level programming concepts and provides tasks for both in-lab and at-home practice.

Uploaded by

ibrahima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Low Level Language

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

LAB FOUR ................................................................................................................................... 18

Generate Fibonacci Series up to 16 Terms Using 8086 Microprocessor...................................... 18

Lab FIVE ...................................................................................................................................... 23

Generate Factorial of a Number from 0 to 9 Using 8086 Microprocessor ................................... 23

LAB SIX ....................................................................................................................................... 29

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

Transfer Data from ROM Memory to RAM Memory .................................................................. 40

LAB NINE .................................................................................................................................... 46

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):

1. Understand basic 8086 assembly programming syntax.


2. Learn how to add two 16-bit numbers in assembly language.
3. Understand how to handle carry generation in arithmetic operations.
4. Develop hands-on experience with low-level programming concepts.

Hardware and Software Requirements:

• 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:

1. Overview of 8086 registers and their usage in arithmetic operations.


2. Demonstrate basic 16-bit addition.
3. Explain the role of ADC (Add with Carry) instruction.
4. Show how to monitor register contents during and after execution.
5. Assemble and run a sample program.

Algorithm/Pseudocode:

Addition without Carry:

1. Load first 16-bit number into AX.

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.

Addition with Carry:

1. Load first 16-bit number into AX.


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. Check for carry using the Carry Flag (CF).
6. If carry occurred, set CARRY variable.
7. Terminate program.

Hands-on Activity:

Follow the steps to write and execute the program:

Program (Addition without Carry):


; Program to add two 16-bit numbers without considering carry
.MODEL SMALL
.STACK 100H
.DATA
NUM1 DW 1234H
NUM2 DW 5678H
RESULT DW ?

.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV AX, NUM1


ADD AX, NUM2
MOV RESULT, AX

; Terminate the program


MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

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

MOV AX, NUM1


ADD AX, NUM2
MOV RESULT, AX

; Check carry flag


JC CARRY_LABEL
JMP END_PROGRAM

CARRY_LABEL:
MOV CARRY, 1

END_PROGRAM:
; Terminate the program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

Required to Do in the Lab:

1. Write and assemble the provided programs.


2. Run and test the programs using an emulator.
3. Observe the values stored in RESULT and CARRY.
4. Document your results and observations below:

Observation Notes:

…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………

Page 5 of 51
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………

Page 6 of 51
Required to Do at Home:

1. Modify the program to:


o Add three 16-bit numbers sequentially.
o Display the result on the screen using interrupt INT 21H.
2. Research:
o What happens if the addition causes an overflow in 8086?
o How does the Carry Flag and Overflow Flag differ?

Homework Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

Page 7 of 51
LAB TWO
Subtraction of Two 16-bit Numbers (With and
Without Borrow) using 8086 Microprocessor
Objective(s):

1. Understand the subtraction operation in 8086 assembly language.


2. Learn how to subtract two 16-bit numbers.
3. Handle borrow condition during subtraction.
4. Develop skills in writing low-level programs.

Hardware and Software Requirements:

• 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:

1. Overview of subtraction instructions in 8086 (SUB, SBB).


2. Explain how the Borrow Flag works.
3. Demonstrate a basic 16-bit subtraction.
4. Observe and discuss register changes during program execution.

Algorithm/Pseudocode:

Subtraction without Borrow:

1. Initialize the data segment.


2. Load the first 16-bit number into AX register.
3. Subtract the second 16-bit number from AX using SUB.
4. Store the result in memory.
5. Terminate the program.

Page 8 of 51
Subtraction with Borrow:

1. Initialize the data segment.


2. Load the first 16-bit number into AX register.
3. Subtract the second 16-bit number using SUB.
4. If borrow occurs (Carry Flag set), adjust accordingly.
5. Optionally use SBB (Subtract with Borrow) instruction for chaining multiple subtractions.
6. Store the final result and borrow status.
7. Terminate the program.

Hands-on Activity:

Follow the steps to write and execute the program.

Program (Subtraction without Borrow):

; Program to subtract two 16-bit numbers without considering borrow


.MODEL SMALL
.STACK 100H
.DATA
NUM1 DW 5678H
NUM2 DW 1234H
RESULT DW ?

.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV AX, NUM1


SUB AX, NUM2
MOV RESULT, AX

; Terminate the program


MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

Page 9 of 51
Program (Subtraction with Borrow):

; Program to subtract two 16-bit numbers considering borrow


.MODEL SMALL
.STACK 100H
.DATA
NUM1 DW 1234H
NUM2 DW 5678H
RESULT DW ?
BORROW DW 0

.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV AX, NUM1


SUB AX, NUM2
MOV RESULT, AX

; Check if borrow occurred (carry flag is set)


JC BORROW_OCCURRED
JMP END_PROGRAM

BORROW_OCCURRED:
MOV BORROW, 1

END_PROGRAM:
; Terminate the program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

Required to Do in the Lab:

1. Write and assemble the provided programs.


2. Run and test the programs using an emulator.
3. Check the RESULT and BORROW variables after execution.
4. Document your results and observations below:

Observation Notes:

…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………

Page 10 of 51
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………

Required to Do at Home:

1. Modify the program to:


o Subtract three numbers sequentially (e.g., (A - B - C)).
o Properly handle borrow at each subtraction step.
2. Research:
o How is the borrow handled differently in signed versus unsigned subtraction in
8086?

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):

1. Understand how to perform multiplication through repetitive addition.


2. Implement a simple multiplication algorithm manually in assembly language.
3. Improve proficiency in loop structures and register usage in 8086 assembly language.

Hardware and Software Requirements:

• 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:

1. Explain how multiplication can be achieved by adding a number repeatedly.


2. Demonstrate use of loops (LOOP instruction) in 8086 assembly.
3. Show how registers are updated in each addition iteration.

Algorithm/Pseudocode:

1. Initialize the data segment.


2. Load the first 8-bit number (multiplicand) into a register (e.g., AL).
3. Load the second 8-bit number (multiplier) into another register (e.g., BL).
4. Clear a register (e.g., CL) to store the result (set it to 0 initially).
5. Create a loop:
o Add the multiplicand to the result register.
o Decrease multiplier (BL) by 1.
o Repeat until the multiplier becomes zero.
6. Store the final result.
7. Terminate the program.

Page 13 of 51
Hands-on Activity:

Follow the steps to write and execute the program.

Program (Multiplication by Repetitive Addition):

; Program to multiply two 8-bit numbers by repetitive addition


.MODEL SMALL
.STACK 100H
.DATA
NUM1 DB 05H ; Multiplicand
NUM2 DB 04H ; Multiplier
RESULT DW 0

.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV AL, NUM1 ; Load multiplicand


MOV BL, NUM2 ; Load multiplier
MOV CX, 0 ; Clear result

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

; Terminate the program


MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

Required to Do in the Lab:

1. Assemble and run the above program.


2. Monitor register values after each loop iteration.
3. Document your results and observations:

Observation Notes:

Page 14 of 51
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………

Page 15 of 51
Required to Do at Home:

1. Modify the program to handle:

i. Multiplying larger numbers and storing 16-bit results correctly.


ii. Multiplying numbers entered by the user (interactive input).

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):

1. Understand how to generate Fibonacci series in assembly language.


2. Implement loops and basic arithmetic operations using the 8086 instruction set.
3. Practice the use of registers and memory for sequence generation.

Hardware and Software Requirements:

• 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:

1. Explain the Fibonacci sequence:


Each term is the sum of the two preceding terms (e.g., 0, 1, 1, 2, 3, 5, 8, 13, ...).
2. Demonstrate how to use registers to hold previous two terms.
3. Show how to output or store each term sequentially.

Algorithm/Pseudocode:

1. Initialize the data segment.


2. Set the first two Fibonacci numbers (e.g., 0 and 1).
3. Display/store the first two numbers.
4. Set a counter to 14 (remaining numbers to be generated after the first two).
5. Loop:
o Add the two previous numbers.
o Store/display the result.
o Update the two previous numbers for the next iteration.
o Decrease the counter by 1.
o Repeat until the counter becomes zero.
6. Terminate the program.

Page 18 of 51
Hands-on Activity:

Follow these steps to write and execute the program.

Program (Generate Fibonacci Series - 16 terms):

; Program to generate Fibonacci series up to 16 terms


.MODEL SMALL
.STACK 100H
.DATA
FIB DB 16 DUP(?) ; Reserve space for 16 numbers
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV AL, 00H ; First term


MOV FIB[0], AL

MOV AL, 01H ; Second term


MOV FIB[1], AL

MOV CL, 14 ; Remaining terms to generate


MOV SI, 2 ; Index for next term

NEXT_TERM:
; Load previous two terms
MOV AL, FIB[SI-1]
ADD AL, FIB[SI-2]

; Store the new term


MOV FIB[SI], AL

INC SI ; Move to next index


DEC CL ; Decrease counter
JNZ NEXT_TERM ; Repeat if counter is not zero

; End program
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN

Required to Do in the Lab:

1. Assemble and run the program.


2. Observe memory locations (FIB array) to verify that Fibonacci sequence is correctly
stored.
3. Document your results and observations:

Page 19 of 51
Observation Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

Page 20 of 51
Required to Do at Home:

1. Modify the program to:


o Generate Fibonacci series for a user-specified number of terms (up to a limit).
o Display each term on the console.
2. Research:
o How large can Fibonacci numbers get before overflow occurs in 8-bit and 16-bit
registers?

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):

1. Understand how to compute factorials in assembly language.


2. Implement multiplication operations and loops using 8086 instruction set.
3. Manage register contents efficiently for repetitive operations.

Hardware and Software Requirements:

• 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:

1. Explain the concept of factorial:


o n! = n × (n-1) × (n-2) × ... × 1
o 0! is defined as 1.
2. Show how to use multiplication in a loop.
3. Discuss handling results that grow larger than a byte (for 9!, maximum value fits in 2
bytes).

Algorithm/Pseudocode:

1. Initialize the data segment.


2. Set a loop from 0 to 9.
3. For each number:
o If the number is 0, set factorial to 1.
o Otherwise:
▪ Initialize factorial result as 1.
▪ Multiply factorial result by each number down to 1.
4. Store/display each computed factorial.

Page 23 of 51
5. End program.

Hands-on Activity:

Follow these steps to write and execute the program.

Program (Generate Factorials from 0 to 9):

; Program to generate factorial of numbers from 0 to 9


.MODEL SMALL
.STACK 100H
.DATA
FACT DW 10 DUP(?) ; Reserve space for 10 factorial results
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV CX, 0 ; Start with number 0


MOV SI, 0 ; Index for FACT array

NEXT_NUM:
MOV BX, 1 ; Initialize factorial to 1

; Check if number is 0
CMP CX, 0
JE STORE_FACT

MOV DX, CX ; Temp copy of current number

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

Note: MUL here is implicitly multiplying AX by DX. Initially, AX = 1.


We use 16-bit (word-sized) storage because factorials grow quickly.

Page 24 of 51
Required to Do in the Lab:

1. Assemble and run the program.


2. Observe memory locations (FACT array) to verify that factorials are correctly stored.
3. Document your results and observations:

Observation Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

Page 25 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

Page 26 of 51
Required to Do at Home:

1. Modify the program to:


o Allow a user to input a number between 0 and 9 and display its factorial.
2. Research:
o What modifications would be needed to compute larger factorials (e.g., up to
20!)?

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):

1. Understand how to perform port input/output (I/O) operations in assembly language.


2. Learn how to use IN and OUT instructions in 8086.
3. Develop the skill of handling 16-bit data transfer between I/O devices.

Hardware and Software Requirements:

• 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:

1. Explain the purpose of IN and OUT instructions.


2. Describe port addressing (fixed addresses for I/O ports).
3. Show how data is moved between CPU and I/O ports using registers like AX.

Algorithm/Pseudocode:

1. Initialize the data segment.


2. Set the input port address (e.g., port 00H).
3. Set the output port address (e.g., port 02H).
4. Read 16-bit data from the input port into AX register.
5. Write 16-bit data from AX register to the output port.
6. Terminate the program.

Page 29 of 51
Hands-on Activity:

Follow these steps to write and execute the program.

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

MOV DX, OUT_PORT ; Load output port address into DX


OUT DX, AX ; Write 16-bit data from AX to output port

; 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.

Required to Do in the Lab:

1. Assemble and run the program.


2. Simulate input/output port behavior if hardware is not available.
3. Document your results and observations:

Observation Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

Page 30 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

Page 31 of 51
Required to Do at Home:

1. Modify the program to:


o Continuously read and display data in an infinite loop.
o Add a feature to stop the operation when a specific key is pressed.
2. Research:
o How direct memory-mapped I/O differs from port-mapped I/O.

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 and Software Requirements:

• 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:

1. Initialize Timer 1 in Mode 1 (16-bit timer mode).


2. Set the Timer 1 value to generate a delay that corresponds to a 10 kHz square wave.
3. Start Timer 1 and toggle the output pin (e.g., P1.0) to create the square wave.
4. Use an interrupt or polling to continuously toggle the square wave.
5. Stop Timer 1 once the square wave generation is complete.

Page 34 of 51
Calculation for Timer Setup:

• Timer 1 is a 16-bit timer. To generate a square wave with a frequency of 10 kHz, we


need to calculate the time period of one cycle:

1 1
Time Period = = = 0.0001 seconds = 100 𝜇s
Frequency 10000

o The Timer 1 needs to toggle every 50 microseconds to produce a square wave


with a 50% duty cycle.

• The 8051 timer operates at 12 MHz clock frequency, so the timer increment is:

1
Timer Tick Time = = 83.33 nanoseconds
12 MHz

• To generate a delay of 50 microseconds, we calculate the number of ticks required:

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:

Timer Reload Value = 65536 − 600 = 64936

Hands-on Activity:

Follow these steps to write and execute the program.

Page 35 of 51
Program (Generate 10 kHz Square Wave Using Timer 1 in Mode 1):

; Program to generate a 10 kHz square wave using Timer 1 in Mode 1


ORG 0H
START:
; Initialize Timer 1 in Mode 1 (16-bit mode)
MOV TMOD, #0x10 ; Configure Timer 1 in Mode 1
MOV TH1, #0xF9 ; Load high byte of Timer 1 (64936 = 0xF9E0)
MOV TL1, #0xE0 ; Load low byte of Timer 1 (64936 = 0xF9E0)

; Start Timer 1
SETB TR1 ; Set TR1 bit to start Timer 1

; Toggle P1.0 (Square wave output)


MAIN_LOOP:
JB TF1, TOGGLE_PIN ; Wait for Timer 1 overflow (TF1)
SJMP MAIN_LOOP ; Continue looping

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

Required to Do in the Lab:

1. Assemble and run the program on the 8051 microcontroller.


2. Use an oscilloscope to measure the output waveform on P1.0 pin and confirm it is a
square wave with a 10 kHz frequency.
3. Document your results and observations:

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 and Software Requirements:

• 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:

Follow these steps to write and execute the program.

Program (Transfer Data from ROM to RAM):

; Program to transfer data from ROM memory to RAM memory


ORG 0H

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

; Load data from ROM to RAM one byte at a time


MOV A, @DPTR ; Load data from ROM into Accumulator
MOV @R0, A ; Store data into RAM

; Increment the ROM and RAM pointers


INC DPTR ; Increment Data Pointer (ROM address)
INC R0 ; Increment RAM address (R0)

; Repeat for a set number of bytes (for demonstration, we'll transfer 5


bytes)
MOV R2, #5 ; Set counter to 5 (number of bytes to
transfer)
TRANSFER_LOOP:
MOV A, @DPTR ; Load data from ROM into Accumulator
MOV @R0, A ; Store data into RAM
INC DPTR ; Increment ROM address
INC R0 ; Increment RAM address
DEC R2 ; Decrement counter
JNZ TRANSFER_LOOP ; Repeat until all data is transferred

; Program ends
NOP ; No operation, can add other instructions as
needed
END

Explanation of the Program:

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.

Required to Do in the Lab:

1. Write and assemble the program on the 8051 microcontroller.


2. Use debugging tools to verify that data is correctly transferred from ROM to RAM.
3. Monitor the RAM location to confirm that the data has been written correctly.

Observation Notes:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

Page 42 of 51
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………………………………………………………………………………

Required to Do at Home:

1. Modify the program to handle larger data blocks.

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):

1. Understand the basic principles of a traffic light control system.


2. Learn how to interface and control traffic lights using an 8086 microprocessor.
3. Develop a program that simulates a traffic light controller with different light cycles
(Green, Yellow, Red) using assembly language.

Hardware and Software Requirements:

• 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:

Follow these steps to write and execute the program.

Program (Traffic Light Controller):

; Traffic Light Controller using 8086 Microprocessor

ORG 100H ; Starting address of the program

MOV AL, 0FFH ; Initialize AL register to 0xFF (all LEDs off)


OUT 0X300, AL ; Turn off all traffic lights

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)

; Yellow Light Cycle


MOV AL, 02H ; Turn on Yellow Light (2nd bit)
OUT 0X300, AL ; Output to Port 0x300
CALL DELAY ; Wait for 2 seconds (Yellow Light duration)

; Red Light Cycle


MOV AL, 04H ; Turn on Red Light (3rd bit)
OUT 0X300, AL ; Output to Port 0x300
CALL DELAY ; Wait for 10 seconds (Red Light duration)

JMP START ; Repeat the cycle

; Delay Subroutine for timing


DELAY:
MOV CX, 0FFFFH ; Load CX with the maximum value (for delay)
DELAY_LOOP:
NOP ; No operation - does nothing (used for delay)
DEC CX ; Decrement the CX register
JNZ DELAY_LOOP ; Repeat until CX reaches 0
RET ; Return from subroutine

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.

Required to Do in the Lab:

1. Write and assemble the program on the 8086 microprocessor.


2. Interface LEDs to represent the Green, Yellow, and Red traffic lights and test the
program.
3. Use debugging tools or simulators to verify that the lights change according to the
specified timing.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy