Experiment 01 Q1. Given N in Memory Location 2030H. Find The Value of

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

EXPERIMENT 01

Q1. Given N in memory location 2030H. find the value of


Y=1+2+……..N. Store the 8bit Y value in Memory location 2031H.

LOGIC: Load N from memory location 2030H. Move Memory to C, Add


the loop counter (1, 2, 3, ..., N) to the C register. While decreasing C,
add current C value to Accumulator. Break loop when C=1. Store the
value of A to memory location 2031H.

CODE:
ORG 0000H;
LXI H,2030H;
MOV C, M
LOOP ADD C;
DCR C;
JNZ LOOP;
STA 2031H;
HLT;
ORG 2030H;
DB 05H;

RESULT AND CONCLUSIONS:


For N=6, the result is (1+2+3+4+5+6) = 21.
In this experiment, we successfully designed and executed an 8085-
assembly language program to calculate the sum of numbers from 1 to
N and store the result in a specified memory location. The program
utilized the microprocessor's arithmetic and loop control instructions to
perform the computation.
Q2. A set of 10 numbers is stored in memory location starting at 0030H.
write an assembly language program to find the number of odd numbers
in the set and store the number in memory location 0031H.

LOGIC:
1. The program starts at memory location 2000H.
2. It counts the number of odd numbers in a set of 10 numbers stored in
memory locations starting from 0030H.
3. The program initializes counters and registers.
4. It loops through the set, checking each number's oddness using
bitwise operations.
5. If a number is odd, the odd count is increased.
6. After processing all numbers, the odd count is stored in memory
location 0031H.
7. The program halts, completing its task of determining the count of odd
numbers in the set.

CODE:
LXI H, 0030H; #Load HL pair with memory location 0030H
MVI B, 0AH; # Initialize B register with number of elements
MVI C, 00H; #Initialize C to store the count of odd numbers
LOOP: MOV A, M; #Load number from memory into Accumulator
ANI 01H; #Perform bitwise AND with 01H
JNZ ODD; #Jump to ODD if the zero flag is not set
INX H; #Increment HL pair to point to the next number
DCR B; #Decrement the counter B
JNZ LOOP; #Jump to LOOP if B is not zero
JMP DONE; #Jump to DONE to finish the program
ODD: INR C; #Increment the count of odd numbers
INX H; #Increment HL pair to point to the next number
DCR B; #Decrement the counter B
JNZ LOOP; # Jump to LOOP if B is not zero

DONE: MOV M, C; #Store the count of odd numbers in memory


location 0031H
HLT; #Halt the processor

RESULT AND CONCLUSIONS:


If we give input numbers 05H, 10H, 15H, 20H, 45H, 56H, 62H, 85H, 88H
then total odd numbers is 4 that will be stored in 0031H location.
Here in this experiment, we use instructions to write a code to finding
numbers of odd numbers. In this experiment, we successfully designed
and implemented an assembly language program for the 8085
microprocessor to determine the number of odd numbers within a set of
10 numbers stored in memory. The objective of the experiment was to
utilize the 8085 microprocessor's instruction set and programming
capabilities to solve a specific problem
Q3. Addition of 10 numbers, stored in consecutive memory location
starting from 0050H, store the summation result in memory location
0100Hand Carry in 0101H.

LOGIC:
1. Initialize a counter (C) to 10 and a sum (A) to 0.
2. Load the first number from memory (2050H) into the accumulator (A).
3. Add the number in the accumulator (A) to the current sum (L register).
4. Move to the next memory location (increment HL).
5. Repeat steps 2-4 until the counter (C) becomes zero.
6. Store the final sum (L register) in memory (2100H).
7. Store the carry from the addition in memory (2101H) to track any
overflow.
8. Halt the processor.

CODE:
XRA A;
MOV D, A;
MVI C,0AH; # C as a register counter
LXI h,0050H; # Load HL resister pair from memory
location 0050H.
LOOP ADD M; # Add content of M with the contents of A
JNC NEXT; # If no carry them go to INXH
INR D;
NEXT INX H; # Increment H, L pair by 1
DCR C; # Decrement value of register C by 1
JNZ LOOP; #If no zero, then go to LOOP, else continue
STA 0100H; #Store the content in desired location
MOV A, D; # Content of D into Accumulator
STA 0101H; # Store carry into 0101H
HLT; # Stop

RESULT AND CONCLUSION:


Sum = 01H + 02H + 03H + 04H + 05H + 06H + 07H + 08H + 09H + 0AH
= 2DH. It will be stored in 0100H, and as no carry is generated so 00H in
0101H will be stored.
In this experiment, we developed an assembly program for the 8085
microprocessor to calculate the sum of a set of numbers stored in
memory. The program effectively utilized the microprocessor's arithmetic
and control flow instructions to perform the calculations and count carry
occurrences during addition.
EXPERIMENT: 2
Q1. Design a traffic signal simulation using Arduino uno and a PCB
board with LEDs. The goal is to create a sequence of red, amber,
and green lights for each direction (west, north, east and south) in
accordance with traffic light signal rules.
Instructions and Logic:
1. Setup Phase:
a. Define pins for each LED corresponding to directions and colours.
b. For each LED pin:
a. Set the pin as output pin to control LEDs.
2. Main Loop:
a. Begin an infinite loop to simulate the traffic signal sequence.
3. Green Phase (West and South):
a. Turn off all LEDs.
b. Turn on the green LEDs for the west and south directions.
c. Wait for 3 seconds to simulate the green light duration.
4. Red and Green Phases (All Directions):
a. Turn off all LEDs.
b. Turn on the green LEDs for the east and north directions.
c. Turn on the red LEDs for the west and south directions.
d. Wait for 3 seconds to simulate the green light duration.
5. Red and Amber Phases (All Directions Except East and North):
a. Turn off all LEDs to ensure a clean transition.
b. Turn on the amber LEDs for the west and south directions.
c. Wait for 1 second to simulate the amber light duration.
6. Red Phase (All Directions):
a. Turn off all LEDs to ensure a clean transition.
b. Wait for 1 second to simulate the transition time between
phases.
7. Green Phase (North and East):
a. Turn off all LEDs to ensure a clean transition.
b. Turn on the green LEDs for the north and east directions.
c. Turn on the red LEDs for the west and south directions.
d. Wait for 3 seconds to simulate the green light duration.
8. Red and Green Phases (All Directions):
a. Turn off all LEDs to ensure a clean transition.
b. Turn on the green LEDs for the west and south directions.
c. Turn on the red LEDs for the north and east directions.
d. Wait for 3 seconds to simulate the green light duration.
9. Red and Amber Phases (All Directions Except West and South):
a. Turn off all LEDs to ensure a clean transition.
b. Turn on the amber LEDs for the north and east directions.
c. Wait for 1 second to simulate the amber light duration.
10. Repeat:
a. The loop goes back to step 3 to repeat the entire sequence.
11. End Loop

CODE:
int DELAY1=2000;
int DELAY2=1000;

void setup() {
// put your setup code here, to run once:
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
delay(DELAY1);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
delay(DELAY2);
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
delay(DELAY1);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
delay(DELAY2);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
delay(DELAY1);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
delay(DELAY2);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
delay(DELAY1);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
delay(DELAY2);
}

Result:
The result of running your code will be a traffic signal simulation where
the LEDs on the PCB board shows the behaviour of a traffic signal,
cycling through red, amber, and green lights for each direction.

Conclusion:
This logic provides a simple yet effective way to simulate a traffic signal
using LEDs and an Arduino Uno. It's organized into phases to mimic the
standard traffic signal sequence: green, amber, and red. By controlling
different pins for each LED, you can create a visual representation of a
traffic signal for various directions.

You might also like