EX121112019
EX121112019
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
Is carry
flag set
Carry=0 Carry=1
Stop
MULTIPLICATION/DIVISION
START
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:
PROGRAM: MULTIPLICATION
PROGRAM: DIVISION
AIM:
Write and execute an ALP to 8086 processor to sort the given 16-bit numbers in Ascending
and Descending order.
APPARATUS REQUIRED:
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 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:
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
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:
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:
ALGORITHM
PROGRAM:
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:
; 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)
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 DPL, #LOW(LEDcodes) ; | put the low byte of the start address of the
; | 7-segment code table into DPL
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)
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)
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
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
OUTPUT:
RESULT:
Thus ALP –to interface matrix keyboard was executed successfully.
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.
Aim:
To write ALP to generate square wave using Timer/Counter for different Frequencies.
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.
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.
DELAY
ADDRESS OP-CODE MNEMONICS
9104 00 nop
9105 00 nop
9106 00 nop
9107 00 nop
9108 14 dec a
910D 22 ret
CALCULATION:
=5/256
=0.0196v
RESULT:
Thus the program of ALP-To generate square wave using Timer/Counter for different
Frequencie was executed successfully.
APPARATUS REQUIRED:
PROGRAM:
ORG (16-bit)H
4100
Stack pointer is
4121 C082 PUSH 82H
incremented by 1.
RESULT:
Thus the program to interface the stepper motor with 8051 was executed.