January 14, 2012
Apparatus Used: Microprocessor Kit, Keyboard
Assumption: We have to write a program to subtract two 16 bit numbers. In this case for any 16 bit number, lower byte takes a location and also higher byte take a location, same for the second number and also for output, so we use 6 memory locations for this.
Algorithm:
- Load First number at given location
- Store first number in D-E pair
- Load Second Number
- Store content of E in Accumulator
- Add L and E and store output in L
- Move D in Accumulator
- Subtract H and D and store output in H
- Store content of H and L at given location
- End the Program
Program:
Memory Address
|
Op-code
|
Operand
|
Comments
|
2000
|
LHLD
|
2050 H
|
Get First Number
|
2003
|
XCHG
|
Save Ist Number in D-E pair
| |
2004
|
LHLD
|
2052 H
|
Get 2nd No in H-L pair
|
2007
|
MOV
|
A,E
|
Save data of E in A
|
2008
|
SUB
|
L
|
Subtract E-L
|
2009
|
MOV
|
L,A
|
Store output in L
|
200A
|
MOV
|
A,D
|
Move D into A
|
200B
|
SBB
|
H
|
Subtract H from D
|
200C
|
MOV
|
H,A
|
Store output into H
|
200D
|
SHLD
|
2054
|
Store Final Output
|
2010
|
RST
|
5
|
Set Break-point
|
2011
|
END
|
End the program
|
Used Instruction:
LHLD addr: This instruction copies the contents of memory location given within the instruction into L register and contents of next memory location into the H register.
XCHG: Exchange the Contents of H with D and L with E.
MOV rd, rs: This instruction copies data from the source register into destination register.
SUB r: This instruction subtract the content of specified register from the contents of accumulator and store result in the accumulator.
SBB r: This instruction will subtract the content of specified register from content of accumulator with carry.
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.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Result:
Input:
First Number-2345
2nd Number-1234
Store as
2050-45
2051-23
2052-34
2053-12
Output:
2054-11
2055-11
LHLD addr: This instruction copies the contents of memory location given within the instruction into L register and contents of next memory location into the H register.
XCHG: Exchange the Contents of H with D and L with E.
MOV rd, rs: This instruction copies data from the source register into destination register.
SUB r: This instruction subtract the content of specified register from the contents of accumulator and store result in the accumulator.
SBB r: This instruction will subtract the content of specified register from content of accumulator with carry.
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.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Result:
Input:
First Number-2345
2nd Number-1234
Store as
2050-45
2051-23
2052-34
2053-12
Output:
2054-11
2055-11
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 Input (M2050)
- Press ENTER and Provide your Input at location (2050:45)
- Press ENTER and Provide your Input at location (2051:23)
- Press ENTER and Provide your Input at location (2052:34)
- Press ENTER and Provide your Input at location (2053:12)
- Press SHIFT+4
- Press G and Provide Initial address (as 2000)
- Press SHIFT+4,You will get first screen again
- Press M and Provide address for output (M2054) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment