find the factorial of a given number, Compute factorial of number 4 using PUSH and POP stack,Write a program to search an element from 10 integer data. - Codeprg

Breaking

programing News Travel Computer Engineering Science Blogging Earning

Thursday, 13 February 2020

find the factorial of a given number, Compute factorial of number 4 using PUSH and POP stack,Write a program to search an element from 10 integer data.

1. Write an assembly language code to find the factorial of a given number
N!.
ANS-->
MOV  A,#01H
MOV R0,#07H
MOV R1,#00H
LOOP:
MOV B,R0
MUL AB
JNC L1
INC R1


L1:DJNZ R0,LOOP


2. Compute factorial of number 4 using PUSH and POP stack instruction, in
the assembly language programming.


ANS→
MOV  A,#01H
MOV R0,#04H
MOV R1,#00H
MOV SP,#3FH
PUSH 0
LOOP:
POP 0
MOV B,R0
MUL AB
DEC R0
PUSH 0
JNC L1
INC R1
L1:DJNZ R0,LOOP


3. Write a program to search an element from 10 integer data where each
integer is of one byte. Please consider the following cases:


1. Data is not in sorted order.
MOV R1,#00H
MOV R2,#0AH
LOOP:
INC R1
CJNE @R1,#09H,L1
SJMP L2
L1:
DJNZ R2,LOOP
SJMP L3
L2:
MOV R3,#01H
RET
L3:
MOV R3,#02H
END


2. Data is in ascending order. 
MOV R1,#30H
MOV R2,#0AH
LOOP:
INC R1
CJNE @R1,#09H,L1
SJMP L2
L1:
DJNZ R2,LOOP
SJMP L3
L2:
MOV R3,#01H
RET
L3:
MOV R3,#02H
END


4. You are required to solve question 3 with constraint that time generating
subroutine is to be called using:
1. L Call
I→
ORG 0
BACK:
MOV A,#55H
MOV P1,A
LCALL DELAY
MOV A,#0AAH
MOV P1,A
LCALL DELAY
SJMP BACK
ORG 300H
DELAY:
MOV R5,#0FFH
AGAIN:DJNZ R5,AGAIN
RET

END