Running 2 Youtube Channel : The Masti Adda (Fun based ) : The Knowledge Adda (Knowledge based) : Subscribe for Knowledge with Fun....

Write an assembly language program find square of the number from 0 t0 9 using look up table.

Written by @
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: In this type program firstly you have to define look up table then using that table you can find the square of number between 0 t0 9.
Algorithm:
  • Initialize HL pair to look-up table
  • Get the data
  • Check the given data is less than 9 or not.
  • If yes then go to next step or end the program.
  • Add the desired address with the accumulator content.
  • Store the result at memory location.
  • End the Program
Program:
Memory Address
Op-code
Operand
Comments
2000
LXI
H,2500 H
Memory pointer Initialization
2003
LDA
2550 H
Subtract 30 from A
2006
CPI
0A H
Check >9
2008
JC
2010
If yes then error
200B
MVI
A,FF H
Error Indication
200D
STA
2551 H
Store output at location
2010
MOV
C,A

2011
MVI
B,00

2013
DAD
B
Add the desired address
2014
MOV
A,M

2015
STA
2551 H
Store output at location
2018
RST
5
Set Break-point
2019
END

End the program

Look-up Table:
2500-01
2501-04
2502-09
2503-16
2504-25
2505-36
2506-49
2507-64
2508-81
Used Instruction:
LXI: This instruction is used to store the 16-bit data in the register pair designated in the operand.
LDA address: Load data into register A (accumulator) directly from the address given within the instruction.
MVI: This instruction is used to store 8 bit data in specified register.
CPI: Compare 8-bit data with the content of accumulator.
MOV: This instruction is used to copy the content from source register to destination register.
DAD: This instruction adds the contents of the specified register pair to the contents of the HL register pair.
JC: Jump if carry at specified memory address.
STA: This instruction is used to store the content of accumulator at specified memory address.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Result:
Input:
2550-05
Output:
2551-25
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 Input location for Look up Table (M2500)
  • Press ENTER and Provide your Input at location (2500:01) and so on
  • Press SHIFT+4
  • Press ENTER and Provide your Input at location (2550:05)
  • Press G and Provide Initial address (as 2000)
  • Press SHIFT+4,You will get first screen again
  • Press M and Provide address for output (M2551) and press ENTER
  • You will get your desired output.

No comments:

Post a Comment