April 06, 2012
Write an assembly language program to add square to two numbers
Aim: Write an assembly language program to evaluate the expression C=A2+B2
Apparatus Used: Microprocessor Kit, Keyboard
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to evaluate the expression C=A2+B2. Let assume that Data 1 is A and 2nd Data is B.
Algorithm:- Get the first data and Second data
- Calculate their square using repetitive addition
- Add the both calculated square
- Store output at another memory location
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
MVI
|
B,02 H
|
Load first data in B
|
2002
|
MOV
|
C,B
|
Store the first data in C
|
2003
|
MVI
|
D,01 H
|
Get Second number
|
2005
|
MOV
|
E,D
|
Store second data in E
|
2006
|
XRA
|
A
|
Clear accumulator
|
2007
|
ADD
|
B
|
Add first number and Second
|
2008
|
DCR
|
C
|
Decrement counter
|
2009
|
JNZ
|
2007
|
A2 calculated
|
200C
|
MOV
|
H,A
|
Store content of A into H
|
200D
|
XRA
|
A
|
Clear accumulator
|
200E
|
ADD
|
D
| |
200F
|
DCR
|
E
| |
2010
|
JNZ
|
200E
|
B2 calculated
|
2013
|
ADD
|
H
|
A2+B2
|
2014
|
STA
|
2200H
|
Store output at 2200 H
|
2017
|
RST
|
5
|
Set breakpoint to execution
|
2018
|
END
|
End the program
|
Used Instruction:
MOV rd,rs: This instruction copies data from the register to destination register.
MVI: This instruction is used to store 8 bit data in specified register.
ADD: This instruction is used to add the content of specified register to the content of accumulator and store output in accumulator.
DCR: This instruction is used decrement the content of specified register by 1.
JNZ: If result is not zero it will jump to the target address.
XRA: Perform the EX-or operation with accumulator.
STA: This instruction is used to store the content of accumulator at specified memory address.
RST 5: This instruction is used to set breakpoint for the execution.
END: This instruction is used to execute the program.
Result:
Output: 2200 H=05 H
Procedure to look output
- After press ENTER, You will get first screen
- Press G and Provide Initial address (as 2000)
- Press SHIFT+4,You will get first screen again
- Press M and Provide address for output (M2200) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment