April 06, 2012
Write an assembly language program to calculate factorial of number between 0 and 8.
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to calculate factorial of number between 0 and 8.
Algorithm:
- Initialize Stack Pointer
- Get the number to find factorial
- Check the number if less than 2 ,store result
- If number is greater than 2, Initialize counter and result
- Call subroutine program
- Result=Result*No
- No=No-1
- If No=0 then Return the program else repeat the process
- Store result
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LXI
|
SP,27FF H
|
Initialize Stack Pointer
|
2003
|
LDA
|
2200 H
|
Get the Number in Accumulator
|
2006
|
CPI
|
02 H
|
Check the number Is greater than 2
|
2008
|
JC
|
201A
|
Store Previous number in A
|
200B
|
MVI
|
D,00 H
|
Load number as result
|
200D
|
MOV
|
E,A
|
Current number is now previous no.
|
200E
|
DCR
|
A
|
Decrement the A
|
200F
|
MOV
|
C,A
|
Load Counter
|
2010
|
CALL
|
2021
|
Call subroutine
|
2013
|
XCHG
|
Exchange the content of H-L
| |
2014
|
SHLD
|
2201
|
Store the content of H and L
|
2017
|
JMP
|
201D
|
Jump unconditionally
|
201A
|
LXI
|
H,0001 H
|
Store data in H and L
|
201D
|
SHLD
|
2201 H
|
Store the content of H and L
|
2020
|
END
|
End the program
| |
Subroutine
| |||
2021
|
LXI
|
H,0000 H
|
Store 00 in H and L
|
2024
|
MOV
|
B,C
|
Store C into B
|
2025
|
DAD
|
D
|
Add D-E and H-L
|
2026
|
DCR
|
B
|
Decrement the B
|
2027
|
JNZ
|
2025
|
Jump if not zero
|
202A
|
XCHG
|
Exchange the content of H and L
| |
202B
|
DCR
|
C
|
Decrement counter
|
202C
|
CNZ
|
2021
|
Call if not zero
|
202D
|
RET
|
Return to the caller
|
Used Instruction:
LDA adr: Load data into register A (accumulator) directly from the address given within the instruction.
XCHG: Exchange the Contents of H with D and L with E.
DAD rp: This instruction adds the contents of the specified register pair to the contents of the HL register pair.
SHLD: The contents of register L are stored in the memory location specified by the 16-bit address in the operand and the contents of register H are stored in the next memory location.
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
CPI: Compare immediate data with accumulator
JC: Jump if carry is set at target address.
MVI: This instruction is used to store 8 bit data in specified register.
MOV: This instruction is used to copy the content from source register to destination register.
JMP: Jump unconditionally at target address.
RET: Return to the main program.
DCR: This instruction is used decrement the content of specified register by 1.
JNZ: Jump if counter is not zero at target address.
END: This instruction is used to execute the program.
LDA adr: Load data into register A (accumulator) directly from the address given within the instruction.
XCHG: Exchange the Contents of H with D and L with E.
DAD rp: This instruction adds the contents of the specified register pair to the contents of the HL register pair.
SHLD: The contents of register L are stored in the memory location specified by the 16-bit address in the operand and the contents of register H are stored in the next memory location.
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
CPI: Compare immediate data with accumulator
JC: Jump if carry is set at target address.
MVI: This instruction is used to store 8 bit data in specified register.
MOV: This instruction is used to copy the content from source register to destination register.
JMP: Jump unconditionally at target address.
RET: Return to the main program.
DCR: This instruction is used decrement the content of specified register by 1.
JNZ: Jump if counter is not zero at target address.
END: This instruction is used to execute the program.
Subscribe to:
Post Comments (Atom)
My programmer is trying to persuade me to move to .net
ReplyDeletefrom PHP. I have always disliked the idea because of the expenses.
But he's tryiong none the less. I've been using Movable-type on various websites for about a year and am anxious about
switching to another platform. I have heard good things about blogengine.net.
Is there a way I can import all my wordpress content into it?
Any help would be greatly appreciated!
my web site: csr racing cheats
destinia hack
ReplyDeleteAlso visit my web page Swamp Attack Hack - Sitzgdfreysudtgsjdf.Com -