0% found this document useful (0 votes)
16 views8 pages

Embedded Ex 3

Uploaded by

maniv2769
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)
16 views8 pages

Embedded Ex 3

Uploaded by

maniv2769
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/ 8

ALU OPERATIONS

Ex No:3a GREATEST NUMBER USING COMPARISON


Date: OPERATION

Aim:
To find the greatest of two numbers using comparison operator in 8051 micro-controller

Algorithm:

1: load the first number to the BX


2: load the second number into BX
3: compare the AX with BX using the CMP instruction
4: If AX is greater than or equal to the BX, store AX in memory
5: else, store BX in memory

Program:

ADDRESS OPCODE LABEL MNEMONIC COMMENTS

1000 BB0500 MOV AX,0005H Load first number into AX

1003 BB03 00 MOV BX,0003H Load second number into BX

1006 3BC3 CMP AX, BX Compare AX with BX

1008 7D02 JGE GREATER Jump if AX is greater than or equal to BX

100A 89D8 MOV AX, BX Move BX to AX if BX is greater

100C GREATER Label for greater number

100C A3 10 00 MOV [0010H], AX Store greater number in memory

100F F4 HLT Halt the program


Output:

INPUT OUTPUT

Address Data Address Data

1100 05 (AX = 0005H) 0010 05 (greater)

1101 03 (BX = 0003H)

Result:

Thus the program for greater number using 8051 microcontroller was written , executed
and the output was verified successfully
Ex No :3b SMALLEST NUMBER USING COMPARISON
Date: OPERATION

Aim:
To find the smallest of two numbers using comparison operation in 8051 micro-controller.

Algorithm:

1: Load the first number into AX


2: Load the second number into BX
3: Compare AX with Bx using the CMP instruction.
4: If AX is smaller than or equal to BX, store AX in memory.
5: Else store BX in memory.
6: Halt the program

Program:

ADDRESS OPCODE LABEL MNEMONIC COMMENTS


1000 BB 0500 MOV AX, 0005H Load first
number into
AX
1003 BB0300 MOV BX, 0003H Load second
number into
BX
1006 3BC3 CMP AX,BX Compare AX
with BX
1008 7E02 JLE SMALLER Jump if
AX<=BX
100A 89DB MOV AX,BX Move BX to
AX
If BX is
smaller
100C SMALLER Label for
smaller
Number
100C A31000 MOV[0010H],AX Store the
smaller
number at
memory
100F FA HLT Halt the prog-
ram

Output:

INPUT OUTPUT

Address Data Address Data

1100 05 (AX = 0005H) 0010 03 (smaller)

1101 03 (BX = 0003H)

Result:
Thus the program for smallest number using 8051 microcontroller was written,executed and output
was verified successfully
Ex No: 3c
RIGHT SHIFT USING SHIFT OPERATION
Date:

Aim:
To perform right shift operation on a number using 8051 micro-controller.

Algorithm:
1. Load the number into AX.
2. Perform right shift operation using SHR.
3. Store the result in memory.
4. Halt the program.

Program:

ADDRESS OPCODE LABEL MNEMONIC COMMENTS

1000 BB 1000 MOV AX, 0010H Load number


into AX

1003 D1 E8 SHR AX, 1 Shift AX right by


1

1005 A3 1000 MOV [0010H], Store result at


AX memory location

1008 FA HLT Halt the program


Output:

INPUT OUTPUT

Address Data Address Data

1100 10 (AX = 0010H) 0010 08

Result:
Thus the program for right shift operation using 8051 microcontroller was written, executed
successfully.
Ex No:3d
LEFT SHIFT USING SHIFT OPERATION
Date:

Aim:

To perform left shift operation on a number using 8051 micro-controller

Algorithm:

1: Load the number into AX


2: Perform left shift operation using SHL
3: Store the result in memory
4: Halt the program

Program:

ADDRESS OPCODE LABEL MNEMONIC COMMENTS

1000 BB1000 MOV AX, Load number


into AX
0004H

1003 D1E0 SHL AX, 1 Shift AX left


by 1 bit

1005 A3 1000 MOV [0010H], Store result at


AX memory
location

1008 FA HLT Halt the

Program
Output:

INPUT OUTPUT

ADDRESS DATA ADDRESS DATA

1100 04 (AX = 0004H) 0010 08

Result:
Thus the program for left shift using 8051 microcontroller was executed
successfully.

You might also like