MSI Lab Manual ss
MSI Lab Manual ss
Experiment Title:
Objective:
To learn the basic functionality of the EMU8086 emulator, understand its user interface, and
write a simple assembly language program to display "Hello, World!" on the screen.
Theory:
The EMU8086 emulator is a microprocessor emulator for the Intel 8086, allowing users to write,
debug, and execute assembly language programs. It provides a graphical debugger to step
through code and observe register, memory, and flag states.
In this lab, students will write their first assembly language program to display a message on the
screen using interrupts. The int 21h DOS interrupt provides various functions, and the ah =
09h service displays a string terminated by '$'.
Apparatus/Software:
Program Code:
; Program to display "Hello, World!" on the screen
.model small
.stack 100h
.data
message db 'Hello, World!$' ; Define the string to display
.code
main proc
; Initialize data segment
mov ax, @data
mov ds, ax
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Procedure:
Observations:
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Objective:
To understand and perform basic data transfer operations using assembly language instructions
on the Intel 8086 microprocessor.
Theory:
Data transfer instructions are used to move data between registers, memory, and I/O devices.
Common instructions include MOV, XCHG, PUSH, and POP.
Program Code:
; End program
mov ah, 4ch ; Terminate program
int 21h
main endp
end main
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Procedure:
• Write a program to move a value from one register to another and verify using the
debugger.
• Record your observations in a table.
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Experiment Title:
Objective:
To understand how to access memory in assembly language using Intel 8086 instructions and
perform operations to store and retrieve values between memory locations and registers using
MOV, LEA, LDS, and LES instructions.
Theory:
Memory access operations in assembly involve moving data between memory and registers. The
MOV instruction is commonly used to transfer data. Other instructions like LEA (Load Effective
Address), LDS (Load Pointer into DS Register), and LES (Load Pointer into ES Register) are
specialized for addressing and pointer handling.
In this experiment:
Program Code:
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
; End program
mov ah, 4ch ; DOS interrupt to terminate program
int 21h
main endp
end main
Procedure:
• Write a program to store a value 0x1234 at a memory location and load it into a
register.
• Record your observations in a table.
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Experiment Title:
Objective:
To understand and implement basic arithmetic operations in assembly language using Intel 8086
instructions like ADD, SUB, INC, and DEC. This program demonstrates how to perform addition and
subtraction on 16-bit numbers.
Theory:
Arithmetic operations are fundamental in assembly language programming. The ADD and SUB
instructions are used for addition and subtraction, respectively. The INC (increment) and DEC
(decrement) instructions increase or decrease the value of a register or memory location by 1
without affecting the carry flag.
This lab focuses on performing the following:
Program Code:
; Perform addition
add ax, bx ; Add AX and BX, result in AX
mov cx, ax ; Store the result in CX
; Perform subtraction
sub cx, bx ; Subtract BX from CX, result in CX
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
; End program
mov ah, 4ch ; DOS interrupt to terminate program
int 21h
main endp
end main
Procedure:
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Experiment Title:
Objective:
To calculate the square of a given number using repetitive addition in assembly language. This
program uses the ADD instruction to perform addition and the LOOP instruction for iteration
control.
Theory:
• Repetitive Addition: The square of a number N can be calculated as N×N by adding the
number N to itself N times.
• Instructions Used:
1. ADD: Adds the source operand to the destination operand.
2. LOOP: Decrements the CX register and jumps to a specified label until CX
becomes zero.
This approach demonstrates how basic instructions like ADD and LOOP can replace more complex
multiplication operations.
Program Code:
repeat_addition:
add ax, bx ; Add BL (num) to AX (accumulated result)
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
; End program
mov ah, 4ch ; DOS interrupt to terminate program
int 21h
main endp
end main
Procedure:
• Write a program to calculate the fourth power of a number using repetitive addition.
• Record your observations in a table.
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Experiment Title:
Objective:
To perform logical bitwise operations (AND, OR, XOR, and NOT) on two numbers using
assembly language.
Theory:
These operations are fundamental in embedded systems for masking, toggling, and testing bit
values.
Program Code:
; Perform OR operation
mov al, num1 ; Reload num1 into AL
or al, num2 ; Perform AL OR num2
mov result_or, al ; Store the result in result_or
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
; End program
mov ah, 4ch ; DOS interrupt to terminate program
int 21h
main endp
end main
Procedure:
• Write a program to perform bitwise operations (AND, OR, XOR, and NOT
operations) on two 16-bit numbers.
• Record your observations in a table.
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Experiment Title:
Objective:
To extract specific bits from a byte using masking techniques by applying bitwise operations
such as AND, SHL (Shift Left), and SHR (Shift Right).
Theory:
Program Code:
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
; End program
mov ah, 4ch ; DOS interrupt to terminate program
int 21h
main endp
end main
Procedure:
1. Open the EMU8086 emulator and create a new assembly file named
masking_operations.asm.
2. Copy the provided code into the editor.
3. Assemble the program using the Compile option.
4. Execute the program using the Run option.
5. Observe the values of result_lower, result_upper, and shifted_upper in the
memory or debugger window.
• Write a program to reverse the bit pattern of the upper half of the AX register while
keeping the lower half unchanged.
• Record your observations in a table.
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Experiment Title:
Objective:
To compare two numbers and display the larger one using conditional jump instructions such as
CMP, JE, JNE, JG, and JL.
Theory:
• Conditional Jumps allow a program to branch to a different location in the code based
on the result of a comparison or flag settings.
• Common instructions:
o CMP: Compares two values by subtracting one from the other but does not store
the result.
o JG: Jump if greater (signed comparison).
o JL: Jump if less (signed comparison).
o JE: Jump if equal.
o JNE: Jump if not equal.
• This experiment uses the CMP instruction and conditional jumps to identify the larger of
two numbers.
Program Code:
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
equal:
mov num_msg, '=' ; If numbers are equal, store '=' in num_msg
jmp display ; Jump to display result
greater:
mov num_msg, '>' ; If AX > BX, store '>' in num_msg
jmp display ; Jump to display result
lesser:
mov num_msg, '<' ; If AX < BX, store '<' in num_msg
display:
; Display result message
lea dx, result ; Load result message address
mov ah, 9 ; DOS interrupt for string display
int 21h
; Terminate program
mov ah, 4ch ; DOS interrupt to terminate program
int 21h
main endp
end main
Procedure:
1. Open the EMU8086 emulator and create a new assembly file named
conditional_jumps.asm.
2. Copy the provided code into the editor.
3. Assemble the program using the Compile option.
4. Execute the program using the Run option.
5. Observe the displayed message and the comparison result on the screen.
• Write a program that jumps to label L1 if either bit 4, 5, or 6 is set in the BL register.
• Record your observations in a table.
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Experiment Title:
Objective:
To create an infinite loop using the JMP instruction and display a message repeatedly on the
screen.
Theory:
Program Code:
loop_start:
; Display message
lea dx, msg ; Load address of message into DX
mov ah, 9 ; DOS interrupt for string display
int 21h ; Display the message
main endp
end main
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Procedure:
1. Open the EMU8086 emulator and create a new assembly file named
infinite_loop.asm.
2. Copy the provided code into the editor.
3. Assemble the program using the Compile option.
4. Execute the program using the Run option.
5. Observe that the message "Hello, this is an infinite loop!" will be displayed repeatedly
on the screen.
6. Terminate the program by closing the EMU8086 window or using a break command.
• Write a program to calculate the sum of two numbers, using JMP instruction.
• Record your observations in a table.
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
Lab 10: Loops and Counters - Counting the Number of 1’s in a Binary Number
Experiment Title:
Counting the Number of 1's in a Binary Number Using a Loop and Counter
Objective:
To count the number of 1’s in a given binary number using a loop and counter. This is achieved
by processing each bit of the number using the LOOP, DEC, and JNZ instructions.
Theory:
• Looping and Counters: Loops and counters are commonly used in assembly language to
perform repetitive tasks. The LOOP instruction helps repeat an operation a specific number
of times, and the DEC instruction decrements a value, while JNZ (Jump if Not Zero)
checks whether the counter has reached zero.
• Algorithm: The process involves:
1. Checking each bit of the binary number.
2. Incrementing the counter if the bit is 1.
3. Moving to the next bit and repeating the process.
• Instructions:
o LOOP: Decreases the counter (CX) and jumps to the specified label if CX is non-
zero.
o DEC: Decrements the specified register or memory location.
o JNZ: Jumps to a label if the specified value is not zero (commonly used to
continue the loop).
Program Code:
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS
LAB MANUAL: MICROPROCESSOR SYSTEMS AND INTERFACING (EEE342)
count_loop:
; Check the least significant bit (LSB)
test ax, 1 ; Perform AND with 1 to check LSB (AX AND 1)
jz skip_increment ; If LSB is 0, jump to skip_increment
skip_increment:
; Shift AX right by 1 to check the next bit
shr ax, 1 ; Shift right by 1
; Display the result (for simplicity, this example assumes output via the
program's termination)
; Terminate program
mov ah, 4ch ; DOS interrupt to terminate program
int 21h
main endp
end main
Procedure:
1. Open the EMU8086 emulator and create a new assembly file named count_ones.asm.
2. Copy the provided code into the editor.
3. Assemble the program using the Compile option.
4. Execute the program using the Run option.
5. Observe the program output (the program will finish execution without direct output
display, but the number of 1's is stored in the count variable, which can be checked via
debugging or extending the program to print the result).
• Write a program to sort an array of numbers in ascending order using loops and
conditional jumps.
• Write a program to calculate the factorial of a given number using a loop.
_____________________________________________________________________________________
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING, CUI ATTOCK CAMPUS