0% found this document useful (0 votes)
37 views36 pages

EX121112019

The document describes 5 experiments involving algorithms and programs for arithmetic operations, sorting arrays, converting between BCD and ASCII, reversing strings, and searching for a number in a list. The first experiment adds, subtracts, multiplies, and divides 16-bit numbers using various addressing modes. The second sorts an array of 16-bit numbers in ascending and descending order. The third converts a given BCD number to its ASCII equivalent. The fourth reverses a given string. The fifth searches for a given number among numbers stored in memory. Each experiment includes the aim, apparatus, algorithm, program, flowchart, inputs and outputs.

Uploaded by

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

EX121112019

The document describes 5 experiments involving algorithms and programs for arithmetic operations, sorting arrays, converting between BCD and ASCII, reversing strings, and searching for a number in a list. The first experiment adds, subtracts, multiplies, and divides 16-bit numbers using various addressing modes. The second sorts an array of 16-bit numbers in ascending and descending order. The third converts a given BCD number to its ASCII equivalent. The fourth reverses a given string. The fifth searches for a given number among numbers stored in memory. Each experiment includes the aim, apparatus, algorithm, program, flowchart, inputs and outputs.

Uploaded by

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

EX NO 1: ALP- To perform 16-bit arithmetic operations (using Various Addressing Modes)

AIM:
To write and execute 8086 ALP programs to add, subtract, multiply and divide two 16-bit
numbers using various addressing modes

APPARATUS REQUIRED:
8086 IDE / 8086 Microprocessor Kit.

ALGORITHM: ADDITION/SUBTRACTION
1. Load the first data in AX register.
2. Load the second data in BX register.
3. Clear CL register.
4. Add/subtract the two data and get the sum in AX register.
5. Store the sum in memory.
6. Check for carry, if carry flag is set then go to next step, otherwise go to step-8.
7. Increment CL register.
8. Store the carry in memory.
9. Stop.
FLOW CHART:
ADDITION/SUBTRACTION

Start

Get the first number

Get the second number

ADD the two numbers

Is carry
flag set

Carry=0 Carry=1

Store result and carry


in memory

Stop

MULTIPLICATION/DIVISION

START

Initialize the source index register

AX  OPR1 , BX OPR2

Multiply/Divide the two numbers

Store the result at AX and DX in memory

STOP
PROGRAM: ADDITION
MOV SI, 0150H
MOV AX, [SI]
MOV BX, [SI+2]
MOV CL, 00H
ADD AX, BX
MOV [SI+4], AX
JNC NO CARRY
INC CL
NO CARRY: MOV [SI+6], CL
HLT

PROGRAM: SUBTRACTION
MOV SI, 0150H
MOV AX, [SI]
MOV BX, [SI+2]
MOV CL, 00H
SUB AX, BX
MOV [SI+4], AX
JNC NOBORR
INC CL
NOBORR: MOV [SI+6], CL
HLT
Output for Addition:

DATA 1 DATA 2 OUTPUT


Addition with Carry FB23H 12F4H 010E17H
Addition without Carry 49ACH B694H 00DEA0H

BEFORE Execution AFTER EXECUTION

Output for Subtraction


DATA 1 DATA 2 OUTPUT
Subtraction without Borrow FB23H 12F4H E82FH
Subtraction with Borrow 49ACH B694H 01-9318H

BEFORE Execution AFTER EXECUTION


ALGORITHM: MULTIPLICATION/DIVISION

1. Load the first data in AX register.


2. Load the second data in BX register.
3. Multiply/divide the content of AX and BX.
4. For Multiplication the product will be in AX and DX. Store the result in memory.
5. For Division the quotient is stored in AX and the remainder in DX, store it in memory.
6. Stop.

PROGRAM: MULTIPLICATION

MOV SI, 0170H


MOV AX, [SI]
MOV BX, [SI+2]
MUL BX
MOV [SI+4], AX
MOV AX,DX
MOV [SI+6], AX
HLT

PROGRAM: DIVISION

MOV SI, 0170H


MOV AX, [SI]
MOV BX, [SI+2]
MOV CX, BX
CMP AX, CX
JC NEXT
DIV BX
NEXT: MOV [SI+4], AX
MOV [SI+6], DX
HLT
Output for Multiplication:
DATA 1 DATA 2 OUTPUT
Multiplication with Overflow FB23H 12F4H 1297 D35CH
Multiplication without Overflow 00F5H 109FH 000F E82BH
BEFORE Execution AFTER EXECUTION

Output for Division:


DATA 1 DATA 2 OUTPUT
Quotient Remainder
Division 0020H 0005H 0006H 0002H
Divide 1205H 4520H 0000H 1205H

BEFORE Execution AFTER EXECUTION


RESULT: Thus, the program for performing 16-bit arithmetic operations using various addressing
modes was written and executed successfully.
EX NO 2: ALP- FOR SORTING AN ARRAY

AIM:
Write and execute an ALP to 8086 processor to sort the given 16-bit numbers in Ascending
and Descending order.

APPARATUS REQUIRED:

8086 IDE / 8086 Microprocessor Kit.

ALGORITHM:
1. Initialize the number of elements counter.
2. Initialize the comparisons counter.
3. Initialize the input data memory address in source index register.
4. Load the numbers into respective registers AX and BX.
5. Compare the elements.
Ascending: If AX < BX then go to step 7 else go to next step.
Descending: If AX > BX then go to step 7 else go to next step.
6. Swap the numbers in the memory
7. Decrement the comparison counter
8. Is count = 0? if yes then go to next step else go to step 4.
9. Decrement the element counter.
10. Is count not 0? go Step 3 else go to next step.
11. Stop & terminate the program.

PROGRAM: SORTING

ORG 0100H
START: MOV CH,05H
OUTER: MOV CL, CH
MOV SI, 0170H
INNER: MOV AX, [SI]
MOV BX, [SI+2]
CMP AX, BX
JB SKIP ; JNB – DESCENDING ORDER
MOV [SI+2], AX
MOV [SI], BX
SKIP: INC SI
INC SI
DEC CL
JNZ INNER
DEC CH
JNZ OUTER
HLT
FLOW CHART:
Output:
ASCENDING ORDER DESCENDING ORDER
Before Execution:

After First cycle

After Second cycle

After Third cycle

After Execution
RESULT: Thus the program to sort numbers in ascending order and descending order was written
and executed successfully.
EX NO 3: ALP - For Code conversion: BCD – ASCII

AIM:
Write and execute an ALP to 8086 processor to convert a given BCD number to its ASCII
equivalent.

APPARATUS REQUIRED:

8086 IDE / 8086 Microprocessor Kit.

ALGORITHM:
1. Load the BCD number stored at input memory location in register AL.
2. Copy contents of register AL in register AH.
3. Perform AND operation on register AL with 0F.
4. Assign 04 to CL Register.
5. Shift the contents of AH by executing SHR instruction using CL.
6. Perform OR operation on register AX with 3030.
7. Store the content of AX in Output memory location.

PROGRAM:

ORG 0100H
MOV AL, [0150H]
MOV AH, AL
AND AL, 0FH
MOV CL, 04H
SHR AH, CL
OR AX, 3030H
MOV [0160H], AX
HLT
FLOWCHART:

START

Move BCD number to AL

COPY AL contents into AH contents

AND AL content with OF

Shift right the AH contents 4 times

OR AX content with 3030

Store the result in AX in output


memory

STOP
OBSERVATION:

BEFORE EXECUTION:

AFTER EXECUTION:

RESULT:
Thus, the program for converting BCD number into ASCII is written and executed
successfully.
EX NO 4: ALP - TO REVERSE THE GIVEN STRING

AIM: To write and execute an ALP to 8086 processor to reverse a given string

APPARATUS REQUIRED:

8086 IDE / 8086 Microprocessor Kit.

ALGORITHM:

1. Create a string
2. Traverse through the string
3. Push the characters in the stack
4. Count the number of characters
5. Load the staring address of the string
6. POP the top character of the stack until count is not equal to zero
7. Put the character and reduce the count and increase the address
8. Continue until the count is greater than zero
9. Load the effective address of the string in dx using LEA command
10. Print the sting by calling the interrupt with 9H in AH
11. The string must be terminated by ‘$’ sign
PROGRAM:
Reverse Numbers as String:
ORG 0100H
MOV CX,0005h
MOV SI,0150H
MOV DI,0159H
NEXT: MOV AL, [SI]
XCHG AL, [DI]
MOV [SI], AL
INC SI
DEC DI
DEC CX
JNZ NEXT
HLT
Reverse a string
.STACK 100H
.DATA
STRING DB 'PSG DCE', '$'
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
CALL REVERSE
LEA DX,STRING ; load address of the string
MOV AH, 09H ; output the string loaded in dx
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
REVERSE PROC
MOV SI, OFFSET STRING ; load the offset of the string
MOV CX, 0H ; count of characters of the string
LOOP1: MOV AX, [SI]
CMP AL, '$' ; compare if this is the last character
JE LABEL1
PUSH [SI] ; else push it in the stack
INC SI ; increment the pointer and count
INC CX
JMP LOOP1
LABEL1: MOV SI, OFFSET STRING ; again load the starting address of the string
LOOP2: CMP CX, 0 ;if count not equal to zero
JE EXIT
POP DX ; pop the top of stack
XOR DH, DH
MOV [SI], DX ; put the character of the reversed string
INC SI
DEC CX
JMP LOOP2
EXIT: MOV [SI],'$ ' ; add $ to the end of string
RET
Output:

RESULT: Thus the ALP for reversing the string is is written and executed successfully.
EX NO 5: ALP – TO SEARCH A NUMBER AMONG THE GIVEN NUMBERS

AIM: To write and execute an ALP to 8051 microcontroller to search a number among the given
numbers

APPARATUS REQUIRED:

8051 IDE / 8051 Microcontroller Kit.

ALGORITHM

STEP 1: Start the program.


STEP 2: Initialize the counter and data pointer.
STEP 3: Load internal memory location with 0.
STEP 4: Current element of data pointer is obtained.
STEP 5: If40H is not equal to the current element jump to step 10.
STEP 6: Increment the data pointer and decrement the counter.
STEP 7: If count not equal to 0 jumps to step 4.
STEP 8: Move the data from the memory location 40 to accumulator.
STEP 9: Move the data in accumulator to data pointer.
STEP 10: If there is carry jump to Step 6.
STEP 11: Move the data in accumulator to 40 H and jump to step 6.
STEP 12: Stop the program.

PROGRAM:

ADDRESS OP-CODE LABEL MNEMONICS COMMENTS

MOV DPTR,(16-bit) Move the 16-bit address to


the data pointer.

Move the data to the


MOV 40H,(8-bit)
memory location 40H

MOV R5,(8-bit) It initializes the counter.

LOOP 2: It loads the data pointer


MOVX A,@ DPTR
with 16 constant indicated.

It compares the magnitude


of two operands and
CJNE A,40 H (LOOP 1)
branches if their values are
not equal.
Increments the indicated
LOOP 3: INC DPTR
variable by 1.

Decrements the location


DJNZ R5,(LOOP 2)
indicated by 1.

Move the data to the


MOV A,40 H
memory location 40H

It loads the data pointer


MOVX @ DPTR,A
with 16 constant indicated.

Program control branches


HLT SJMP HLT unconditionally to the
address indicated

LOOP 1: JC LOOP 3: Jump on carry to loop 3.

Move the data to the


MOV 40 H,A
memory location 40H

Program control branches


SJMP LOOP3 unconditionally to the
address indicated
OUTPUT:

Largest number in an array of numbers

Memory address Data

4200 09

4201 55

4203 24

4204 42

4205 23

4206 33

4207 94

4208 43

4209 50

OUTPUT

420A 94
RESULT:
Thus ALP for searching a number among the given numbers was written and executed.
EX NO:6 ALP-INTERFACING SUBROUTINE

AIM:
To interface subroutine using assembly language program

PROGRAM:

start:

MOV R0, #0 ; clear R0 - the first key is key0

; scan row0
SETB P0.3 ; set row3
CLR P0.0 ; clear row0
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in
R0)
; scan row1
SETB P0.0 ; set row0
CLR P0.1 ; clear row1
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in
R0)
; scan row2
SETB P0.1 ; set row1
CLR P0.2 ; clear row2
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in
R0)
; scan row3
SETB P0.2 ; set row2
CLR P0.3 ; clear row3
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in
R0)

JMP start ; | go back to scan row 0


; | (this is why row3 is set at the start of the program
; | - when the program jumps back to start, row3 has just
been scanned)

finish:
JMP $ ; program execution arrives here when key is found - do
nothing

; column-scan subroutine
colScan:
JNB P0.4, gotKey ; if col0 is cleared - key found
INC R0 ; otherwise move to next key
JNB P0.5, gotKey ; if col1 is cleared - key found
INC R0 ; otherwise move to next key
JNB P0.6, gotKey ; if col2 is cleared - key found
INC R0 ; otherwise move to next key
RET ; return from subroutine - key not found
gotKey:
SETB F0 ; key found - set F0
RET ; and return from subroutine
Output:

RESULT:
Thus ALP- to implement subroutine concept was completed successfully.
EX NO: 7 ALP- INTERFACING MATRIX KEYBOARD

AIM:
To interface matrix keyboard using assembly language program.

ALGORITHM:
1. Start the program
2. Set a row and column list
3. Each and every press scan all rows and column
4. Make the row and column of the pressed key and others as one
5. Show the result in R0
6. Stop the program

PROGRAM:

MOV TMOD, #50H ; put timer 1 in event counting mode


SETB TR1 ; start timer 1

MOV DPL, #LOW(LEDcodes) ; | put the low byte of the start address of the
; | 7-segment code table into DPL

MOV DPH, #HIGH(LEDcodes) ; put the high byte into DPH

CLR P3.4 ;|
CLR P3.3 ; | enable Display 0
again:
CALL setDirection ; set the motor's direction
MOV A, TL1 ; move timer 1 low byte to A
CJNE A, #10, skip ; if the number of revolutions is not 10 skip next
instruction
CALL clearTimer ; if the number of revolutions is 10, reset timer 1
skip:
MOVC A, @A+DPTR ; | get 7-segment code from code table - the index
into the table is
; | decided by the value in A
; | (example: the data pointer points to the start of
the
; | table - if there are two revolutions, then A will
contain two,
; | therefore the second code in the table will be
copied to A)

MOV C, F0 ; move motor direction value to the carry


MOV ACC.7, C ; and from there to ACC.7 (this will ensure
Display 0's decimal point
; will indicate the motor's direction)
MOV P1, A ; | move (7-seg code for) number of revolutions
and motor direction
; | indicator to Display 0
JMP again ; do it all again

setDirection:
PUSH ACC ; save value of A on stack
PUSH 20H ; save value of location 20H (first bit-addressable
; location in RAM) on stack
CLR A ; clear A
MOV 20H, #0 ; clear location 20H
MOV C, P2.0 ; put SW0 value in carry
MOV ACC.0, C ; then move to ACC.0
MOV C, F0 ; move current motor direction in carry
MOV 0, C ; and move to LSB of location 20H (which has
bit address 0)

CJNE A, 20H, changeDir ; | compare SW0 (LSB of A) with F0 (LSB of


20H)
; | - if they are not the same, the motor's direction
needs to be reversed

JMP finish ; if they are the same, motor's direction does not
need to be changed
changeDir:
CLR P3.0 ;|
CLR P3.1 ; | stop motor

CALL clearTimer ; reset timer 1 (revolution count restarts when


motor direction changes)
MOV C, P2.0 ; move SW0 value to carry
MOV F0, C ; and then to F0 - this is the new motor direction
MOV P3.0, C ; move SW0 value (in carry) to motor control bit
1
CPL C ; invert the carry
MOV P3.1, C ; | and move it to motor control bit 0 (it will
therefore have the opposite
; | value to control bit 1 and the motor will start
; | again in the new direction)
finish:
POP 20H ; get original value for location 20H from the
stack
POP ACC ; get original value for A from the stack
RET ; return from subroutine

clearTimer:
CLR A ; reset revolution count in A to zero
CLR TR1 ; stop timer 1
MOV TL1, #0 ; reset timer 1 low byte to zero
SETB TR1 ; start timer 1
RET ; return from subroutine

LEDcodes: ; | this label points to the start address of the 7-segment code table which is
; | stored in program memory using the DB command below

DB 11000000B, 11111001B, 10100100B, 10110000B, 10011001B, 10010010B, 10000010B,


11111000B, 10000000B, 10010000B

OUTPUT:

RESULT:
Thus ALP –to interface matrix keyboard was executed successfully.

EX NO: 8 ALP- INTERFACING 7- SEGMENT LED


AIM:
To interface 7- Segment LED using assembly language program.

PROGRAM:
start:
SETB P3.3 ;|
SETB P3.4 ; | enable display 3
MOV P1, #11111001B ; put pattern for 1 on display
CALL delay
CLR P3.3 ; enable display 2
MOV P1, #10100100B ; put pattern for 2 on display
CALL delay
CLR P3.4 ;|
SETB P3.3 ; | enable display 1
MOV P1, #10110000B ; put pattern for 3 on display
CALL delay
CLR P3.3 ; enable display 0
MOV P1, #10011001B ; put pattern for 4 on display
CALL delay
JMP start ; jump back to start

; a crude delay
delay:
MOV R0, #200
DJNZ R0, $
RET

Output:
RESULT:
Thus ALP - to interface 7-Segment LED was executed successfully.

EX NO: 9 ALP-To generate square wave using Timer/Counter for different


Frequencies.

Aim:

To write ALP to generate square wave using Timer/Counter for different Frequencies.

Working procedure for DAC:

1. Connect the 9 pin D typeconnector from the DAC module to the Mp/Mc kit.

2.Connect the 26-pin connector from the DAC module to Mp/Mc kit.

3.Connect the keyboard to the Mp/Mc kit.

4.Switch on the power supply.

5.Assemble your program.

6.Execute it and measure the output voltage/waveform at the front panel of the DAC module.

7.Vary the digital count,execute the program and measure the output analog voltage.

8.Take number of reading and if required draw the graph,DAC input counts Vs output voltage to
check the linearity.

9.Switch off the power supply and remove all the connections.

SQUARE WAVE GENERATION:


User can change the delay period in order to get the desired frequency of the wave form.User
can view the output at DAC O/P,through the CRO.

ADDRESS OP-CODE MNEMONICS COMMENTS

9000 74 80 mov a,#80 ;control word

9002 90 40 03 mov dptr,#4003 ;control register address

9005 F0 movx @dptr,a ;all ports as o\p

9006 74 80 mov a,#80 ;give the dig i\p as data-

9008 90 40 01 mov dptr,#4001 ;port b address

900B F0 movx @dptr,a ;digital data to port b

900C 12 91 00 lcall 9100 ;call delay routine

900F 74 FF mov a,#ff ;digital data

9011 F0 movx @dptr,a ;digital data to port B

9012 12 91 00 lcall 9110 ;call delay routine

9015 02 90 06 ljump 9006 ;jump to start

DELAY
ADDRESS OP-CODE MNEMONICS

9100 79 40 mov r1,#40

9102 74 FF mov a,#FF

9104 00 nop

9105 00 nop

9106 00 nop

9107 00 nop

9108 14 dec a

9109 70 F9 jnz 9104

910B D9 F5 djnz rl,9102

910D 22 ret

CALCULATION:

1 count (decimal) =VCC/256

=5/256

=0.0196v
RESULT:

Thus the program of ALP-To generate square wave using Timer/Counter for different
Frequencie was executed successfully.

EX NO: 10 INTERFACING STEPPER MOTOR WITH 8051


MICROCONTROLLER
AIM:

To write an Assembly Language Program to interface stepper motor with 8051


microcontroller.

APPARATUS REQUIRED:

8051 Trainer Kit, Power Cable.

PROGRAM:

ADDRESS OP-CODE LABEL MNEMONICS COMMENTS

ORG (16-bit)H
4100

4100 7C33 START: MOV R4,#33H Move the data 33 to R4

MOV DPTR,# Move the data pointer with


4102 904144 L2:
FORWARD value for forward.

4105 12411C LCALL L1 Call L1.

Decrement and jump on no


4108 DCF8 DJNZ R4,L2
Zero to L2.

410A 12413B LCALL DELAY Call the delay.

410D 7C33 L3: MOV R4,#33H Move the data 33 to R4

MOV DPTR,# Move the data pointer with


410F 904148
REVERSE the value for reverse.

4112 12411C LCALL L1

Decrement and jump on no


4115 DCF8 DJNZ R4,L3
Zero to L3.

4117 12413B LCALL DELAY Call the delay.

411A 80E4 SJMP START Jump to start.

411C 7804 L1 MOV R0,#04H Move the data 04 to R0

Move the value in data


411E EO LOOP: MOVX A,@DPTR
pointer to A.
Stack pointer is
411F C083 PUSH 83H
incremented by 1.

Stack pointer is
4121 C082 PUSH 82H
incremented by 1.

Move the value of data


4123 90FFC0 MOV DPTR,#OFF20H
pointer

4126 7A04 MOV R2,#04H Move R2 with 04

Move the data to the


4128 7905 L7: MOV R1,#05H
memory location 05H

Move the data to the


412A 7BFF L6: MOV R3,#0FFH
memory location 0FFH

Decrement and jump on no


412C DBFE L4: DJNZ R3,L4
Zero to L4.

Decrement and jump on to


412E D9FA DJNZ R1,L6
L6

4130 DAF6 DJNZ R2,L7 Decrement and jump to L7

Move the data in A to data


4132 F0 MOVX @DPTR,A
pointer.

Stack pointer is read and is


4133 D082 POP 82H
decremented by 1.

Stack pointer is read and is


4135 D083 POP 83H
decremented by 1.

4137 A3 INC DPTR Increment the data pointer.

Decrement and jump on no


4138 D8E4 DJNZ R0,LOOP
Zero to LOOP.

413A 22 RET Return.

Move the data to the


413B 7D01 DELAY: MOV R5,#01H
memory location 01H
Move the data to the
413D 7A05 L9: MOV R2,#05H
memory location 05H

Decrement and jump on no


413F DAFE L8: DJNZ R2,L8
zero to 8

Decrement and jump on no


4141 DDFA DJNZ R5,L9
Zero to LOOP.

4143 22 RET Return

4144 0905060A FORWARD: 09H,05H,06H,0AH

414B 0A060509 REVERSE: 0AH,06H,05H,09H

RESULT:
Thus the program to interface the stepper motor with 8051 was executed.

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