求一个整数N的平方根的汇编源文件

;本程序求N的平方根
STACK SEGMENT STACK
DW 20 DUP(?)
STACK ENDS

DATA SEGMENT
N DB 20H
M DB 01H
I DB 01H
DATA ENDS

CODES SEGMENT
ASSUME CS:CODES,DS:DATA,ES:NOTHING,SS:STACK
MAIN: MOV AX,DATA
MOV DS,AX

AGAIN:MOV AL,M
CMP AL,N
JAE DONE
MOV AL,I
MOV BL,2
MUL BL
ADD M,AL
INC I
JMP AGAIN

DONE: MOV AL,M
CMP AL,N
JE EXIT
SUB I,1
EXIT: MOV DL,I
ADD DL,30H
MOV AH,02H
INT 21H
MOV AX,4C00H
INT 21H
CODES ENDS
END MAIN

;算法原理
(X+1)2 = X2 + 2 * X + 1
令Mi = I2,
则Mi+1 = Mi + 2*I +1
用此式迭代计算

你可能感兴趣的:(文件)