Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .MODEL SMALL
- .STACK 64
- .DATA
- ORG 00
- Y DW 9
- X1 DW 1 ;Xn
- X2 DW ? ;Xn+1
- ORG 10H
- A DW 0 ;(Y/X1)
- B DW 0 ;(X1+A)
- ORG 20H
- Diff DW 0 ;Holds the difference when comparing
- ORG 30H
- RESULT DW ?
- .CODE
- MAIN PROC FAR
- ;Setting the DS
- MOV AX,@DATA
- MOV DS,AX
- ;The Program is goint to do this process
- ; X2 = (X1 + (NUMBER/X1))/2
- ; and will repeat it unti |(X2-X1)|<2
- ;Shifting the variables to enlarge the precision
- MOV CL,8
- SHL WORD PTR Y,CL ;Shift the Y to the left by 8bits
- SHL WORD PTR X1,CL ;Shift X1 as well
- Iteration:
- ;Getting A : Y(Word)/X1(Word)
- MOV AX,Y
- SUB DX,DX ;Clear DX
- DIV X1
- MOV A,AX ;Move the quotient in A
- ;Getting B : X1+A
- SUB AX,AX ;clears the Ax
- ADD AX,A
- ADD AX,X1
- MOV B,AX
- ;Getting X2 = (B)(WORD)/NUM2(WORD)
- SUB DX,DX
- MOV BX,02
- DIV BX ;B/2
- MOV X2,AX ;Stote in X2
- ;Find X2-X1 and strore it in Diff
- SUB AX,X1 ;X2-X1
- JNC NOFIX ;IF Not Negative goto NOFIX
- ;FIX If reuslt is negative
- NOT AX
- INC AX
- NOFIX:
- CLC
- MOV Diff,AX
- CMP Diff,2
- MOV BX,X2
- MOV X1,BX ;Set the Xn+1 = Xn for the next trial if there was
- JNC Iteration ;repeate the whole process
- ;Else
- MOV CL,4
- SHR X1,CL
- SHR X2,CL
- ;Store the Result
- MOV AX,X1
- MOV RESULT,AX
- ;DOS EXIT COMMAND
- MOV AX,4CH
- INT 21H
- MAIN ENDP
- END MAIN
Advertisement
Add Comment
Please, Sign In to add comment