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

Labs a PreLabs and Labs

Uploaded by

Isah Muhammad
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)
10 views

Labs a PreLabs and Labs

Uploaded by

Isah Muhammad
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/ 13

PRE LAB - 1

Addition and Subtraction of Two 8-bit Numbers

1. Addition and Subtraction of Two 8-bit Numbers


Activity 1: Study addressing modes

Activity 2: Study 8085 arithmetic operation

Q1 Write a 8085 Microprocessor program to add two numbers


1. Load the HL register pair with 0000H
2. Load first number (e.g., 25H) into Accumulator
3. Load second number (e.g., 18H) into register B
4. Add B to A, result stored in A
5. Store result in L register (low byte)
6. Halt the program

Q2 Write a 8085 Microprocessor program to add two numbers


1. Load first number (e.g., 25H) into Accumulator
2. Load second number (e.g., 18H) into register B
3. Subtract B from A, result stored in A
4. Halt the program

1
LAB - 1
Addition and Subtraction of Two 8-bit Numbers

Simulation – 1 Addition of Two 8-bit Numbers

A. Enter and execute the following simulation codes

LXI H, 0000H ; Initialize HL register pair to store result


MVI A, 25H ; Load first number (e.g., 25H) into Accumulator
MVI B, 18H ; Load second number (e.g., 18H) into register B
ADD B ; Add B to A, result stored in A
MOV L, A ; Store result in L register (low byte)
HLT ; Halt the program

B. Record the Contents of the Registers

C. Take the Screenshot

Simulation – 2 Subtraction of Two 8-bit Numbers

MVI A, 25H ; Load first number (e.g., 25H) into Accumulator


MVI B, 18H ; Load second number (e.g., 18H) into register B
SUB B ; Subtract B from A, result stored in A
HLT ; Halt the program

2
Pre LAB - 2
Activity 1: Study Data Transfer and Arithmetic Instructions

Q1 Write a 8085 Microprocessor program to add two numbers


Load the HL register pair with 0000H
Load first number (e.g., 25H) into Accumulator
Load second number (e.g., 18H) into register B
Add B to A, result stored in A
Store result in L register (low byte)
Halt the program

Q2 Write a 8085 Microprocessor program to add two numbers


Load first number (e.g., 25H) into Accumulator
Load second number (e.g., 18H) into register B
Subtract B from A, result stored in A
Halt the program

3
LAB - 2
Simulation – 1 Loading of of Two 8-bit Numbers Data Transfer and Arithmetic
Instructions

A. Enter and execute the following simulation codes

LXI H, 0000H ; Initialize HL register pair to store result


LXI D, 3000H ; Destination address (DST)
LXI H, 2000H ; Source address (SRC)
MVI C, 0AH ; Load counter (N = 10 bytes)

LOOP:
MOV A, M ; Load data from source into Accumulator
STAX D ; Store data at destination
INX H ; Increment source address
INX D ; Increment destination address
DCR C ; Decrement counter
JNZ LOOP ; Repeat until C = 0

HLT ; Halt program

Explanation:
1. Initialize Pointers:
o H stores source address (2000H).
o D stores destination address (3000H).
o C is the counter (N = 10 bytes).
2. Loop Execution:
o Read data from source (MOV A, M).
o Write data to destination (STAX D).
o Increment source and destination addresses (INX H, INX D).
o Decrease counter (DCR C).
o If counter ≠ 0, repeat (JNZ LOOP).
3. Halt Execution (HLT) when all data is transferred.

4
Pre LAB - 3
Activity: Study Logical Operations: AND, OR, XOR of two numbers

Q1 Write a 8085 Microprocessor program to perform logic operation on two numbers


1. Load the HL register pair with 0000H
7. Load first number (e.g., 25H) into Accumulator
8. Load second number (e.g., 18H) into register B
9. Add B to A, result stored in A
10. Store result in L register (low byte)
11. Halt the program

Q2 Write a 8085 Microprocessor program to add two numbers


5. Load first number (e.g., 25H) into Accumulator
6. Load second number (e.g., 18H) into register B
7. Subtract B from A, result stored in A
8. Halt the program

5
LAB - 3
Logical Operations:

Simulation – I AND Operations of Two Numbers

MVI A, 55H ; Load first number (A = 55H)


MVI B, 0F0H ; Load second number (B = F0H)
ANA B ; Perform A = A AND B
MOV C, A ; Store result in C (AND result)

Simulation – II OR Operations of Two Numbers

MVI A, 55H ; Reload first number


ORA B ; Perform A = A OR B
MOV D, A ; Store result in D (OR result)

Simulation III XOR Operations of Two Numbers


MVI A, 55H ; Reload first number
XRA B ; Perform A = A XOR B
MOV E, A ; Store result in E (XOR result)
HLT ; Halt program

6
PreLab 4
Activity: Study Branching and Looping Instructions

Study codes below


; Program: Count from 5 to 1 and store in memory (C050H onwards)

LXI H, C050H ; HL points to memory location C050H


MVI C, 05H ; Load counter value 5 into register C

LOOP: MOV M, C ; Store the current value of C to memory


INX H ; Move to next memory location
DCR C ; Decrement the counter
JNZ LOOP ; If C ≠ 0, jump back to LOOP
HLT ; Halt the program

Labs 4

Steps to Run in GNUSim8085:


1. Open GNUSim8085.
2. Go to File > New and paste the code above.
3. Click Assemble (or press F5) to compile.
4. Click Execute > Go (or Ctrl+F9) to run the program.
5. After execution, check memory from C050H onwards to see:

7
Prelab 5

Activity: Code Conversion: Binary to BCD, ASCII to BCD, Hexadecimal to


decimal

1. Short Definitions
What is the difference between binary, BCD, and ASCII?
How is a BCD number different from a binary number?
What does the DAA instruction do in 8085?

2. Predict the Output


a. If register A = 0010 1001 (i.e., 29 in binary), and you execute DAA, what is the new value
in A?
b. If ASCII value 35H is given (character '5'), how do you convert it to numeric value 5?
c. Convert hexadecimal 2F to decimal using pen and paper. What are quotient and remainder
values?

8
Lab 5
Experiment 1: Binary to BCD Conversion
Objective: Convert an 8-bit binary number to its equivalent BCD.

Input: Binary number in A


Output: BCD result in memory 3000H, 3001H, and 3002H (hundreds, tens, units)
Example: Binary 0x79 (121 in decimal) → BCD = 1 2 1

Algorithm:
Divide the binary number by 100 to get hundreds.
Divide the remainder by 10 to get tens.
Store hundreds, tens, and units in memory.

Sample Code:

MVI A, 79H ; Load binary number (121)


MOV B, A ; Save in B

MVI C, 00H ; Hundreds


MVI D, 00H ; Tens

LOOP1: CPI 64H ; Compare with 100


JC STEP2
SUI 64H ; Subtract 100
INR C
JMP LOOP1

STEP2:
LOOP2: CPI 0AH ; Compare with 10
JC STORE
SUI 0AH
INR D
JMP LOOP2

STORE:
STA 3002H ; Units
MOV A, D
STA 3001H ; Tens
MOV A, C
STA 3000H ; Hundreds
HLT

9
Experiment 2: ASCII to BCD Conversion
Objective: Convert an ASCII digit (e.g., '3' = 33H) to its BCD numeric value.

Input: ASCII character in memory 3100H


Output: BCD in A (e.g., for '5' → 05H)

Logic:
ASCII of '0' is 30H, '1' is 31H … '9' is 39H
Subtract 30H from ASCII to get the number

Sample Code:

LDA 3100H ; Load ASCII character (e.g., 35H = '5')


SUI 30H ; Subtract 30H
STA 3101H ; Store BCD number
HLT

Experiment 3: Hexadecimal to Decimal Conversion


Objective: Convert a hexadecimal number to its decimal equivalent using repeated
subtraction/division method.
Input: Hex value in A (e.g., 2F = 47 in decimal)
Output: Decimal digits in memory

Concept:
Divide hex number by 10 repeatedly and Store quotient and remainder as decimal digits

Sample Pseudocode:
MVI A, 2FH ; Load hex number (47)
MOV B, A
MVI C, 00H ; Tens
MVI D, 00H ; Units

LOOP:
CPI 0AH
JC STORE
SUI 0AH
INR C
JMP LOOP

STORE:
MOV D, A ; Units = remainder
MOV A, C
STA 3200H ; Tens
MOV A, D
STA 3201H ; Units
HLT

10
Pre Lab 6

Activity: Code Conversion: Binary to BCD, ASCII to BCD, Hexadecimal to


decimal

Q1 Define the following terms:

• Interrupt
• Maskable vs Non-Maskable Interrupts
• Vector and Non-Vector Interrupts
• Interrupt Service Routine (ISR)

2. Answer the following questions:

• List the five hardware interrupts in 8085 in order of priority.


• What is the purpose of the EI and DI instructions?
• What is the vector address for:

RST 7.5

TRAP

INTR

11
Lab 6

Experiment 1: Simulate TRAP Interrupt Execution


Objective: Demonstrate execution from the TRAP vector address.
Steps:
1. Load the main program starting at 8000H.
2. Simulate an interrupt by jumping to the TRAP vector location 0024H.
3. Execute a small ISR at 0024H that stores a value in memory.
4. Return to main program using RET.

Sample Code:
; Main program
ORG 8000H
MVI A, 11H
CALL 0024H ; Simulating TRAP interrupt manually
HLT

; TRAP ISR at 0024H


ORG 0024H
MVI A, 55H
STA 9000H ; Store value at 9000H
RET

Experiment 2: Enable Interrupts and Use RST Instruction


Objective: Use the EI, RST n instructions to simulate software interrupt behavior.
Steps:
1. Enable interrupts using EI.
2. Trigger a software interrupt using RST 5 (vector address 0028H).
3. Handle it using an ISR that stores a value.

Sample Code:
ORG 8000H
EI ; Enable interrupts
RST 5 ; Simulate interrupt (jumps to 0028H)
HLT

; ISR at vector 0028H


ORG 0028H
MVI A, AAH
STA 9001H
RET

12
Notes for GNU 8085 Use:
• Use manual CALL to ISR locations to simulate hardware interrupts.
• You can emulate vector execution by putting the code at those addresses (0024H,
0028H, etc.).
• Since external triggers aren’t simulated, you just call the ISR manually.

13

You might also like