Académique Documents
Professionnel Documents
Culture Documents
Search the given byte in the list of 50 numbers stored in the consecutive memory
locations and store the address of memory location in the memory locations 2200H and 2201H.
Assume byte is in the C register and starting address of the list is 2000H. If byte is not found
store 00 at 2200H and 2201H.
Statement:
1. LX I H, 2000H
2. MVI B, 52H
:"Initialize counter"
3. BACK: MOV A, M
4. CMP C
5. JZ LAST
6. INX H
7. DCR B
:"Decrement counter"
8. JNZ B
9. LXI H, 0000H
10. SHLD 2200H
11. JMP END
13. END:
HLT
:"Stop"
Suppose that X is the square root of number N. To find the square root, we derive the following
equation
Let X2=N
Add X2 on both sides. Then
2 X2=N+ X2
X2=(N+ X2)/2
X=(N+ X2)/(2*X)
X=((N/X)+X)/2
Xnew= ((N/X)+X)/2
To find the square root of a given number we provide an initial guess X. With this value we
calculate Xnew and compare it with X. If Xnew=X, it gives the result .If Xnew X then we take
the Xnew as X and using the equation we find Xnew. This process is repeated until Xnew=X.
ALGORITHM:
Step1: load HL register pair with a memory pointer.
Step2: get the number into accumulator and E register.
Step3: increment memory pointer.
Step4: get the initial guess to D and B registers.
Step5: call the division program.
Step6: add the initial guess with the accumulator.
Step7: divide the content of accumulator by 2 using division program.
Step8: if the calculated value is equal to guess, store the result in the memory location.
Step9: else take calculated value as guess and go to step5.
PROGRAM:
MEMORY
LOCATION
4100
MACHINE
CODE
21,00,42
LABEL
MNIMONICS
COMMENTS
LXIH, 4200
Initialize HL register
pair with memory
pointer
Transfer the content of
memory location to
accumulator
Transfer the content of
memory location to E
register
Increment memory
pointer
Move the initial guess
to D register
4103
7E
MOV A, M
4104
5E
MOV E, M
4105
23
INX H
4106
56
MOV D, M
4107
46
MOV B,M
4108
410A
0E,00
CD,1E,41
410D
80
ADDB
410E
06,02
MVI B,02
4110
0E,00
MVI C,00
Clear C register
4112
CD,1E,41
CALL DIV
4115
7A
MOV A,D
4116
51
MOV D,C
Move [D] to
accumulator
Move [C] to D register
4117
B9
CMP C
4118
C2,28,41
JNZ LOOP1
411B
23
INX H
411C
71
MOV M,C
411D
76
HLT
411E
90
411F
DA,26,41
JC LOOP2
4122
0C
INR C
4123
C3,1E,41
JMP DIV
4126
79
4127
C9
4128
7B
4129
41
MOV B,C
Increment C register
content
Jump to division
program
Move [C] to
accumulator
Return to main
program
Move[E] to
accumulator
Move [B] to C register
412A
C3,08,41
JMP LOOP3
Jump to loop3
LOOP3
DIV
LOOP2
MVI C,00
CALL DIV
SUB B
MOV A,C
RET
LOOP1
MOV A,E