At the beginning of this semester, I learned the compilation carefully. The program assigned by the teacher was quickly compiled, which undoubtedly gave me great confidence. Every time I see that my programs can be compiled and run, I can't say anything in my heart. I think this is the joy I learned to compile.
However, compilation is successful but cannot be run, and it is quite painful. Because I don't know where the error is. I can check the program on the left and right, but I still can't find it. For example, a recent question: using the subtraction odd number method, we can obtain the approximate square root. My idea is that if you want to perform an operation, you can subtract the odd numbers 1, 3, 5, 7… from S... Always perform the subtraction to zero or not enough to subtract an odd number of natural numbers, and then calculate the odd number minus the natural number, which is the approximate square root of S.
Source code:
Use the odd-number subtraction method to obtain the approximate square root and obtain the integer part of the square root.
Data Segment
S DW 88 h
N dw 01 H
Count db 0
; Set variables and assign values
Data ends
Stack segment Stack
DWP 100 DUP (?)
Stack ends
Code segment 'code'
Assume Cs: code, SS: Stack, DS: Data
Start: mov ax, Data
MoV ds, ax
MoV ax, S
MoV BX, n
L1: sub ax, BX
INC count;
Add Bx, 02 h; ax-xB, Count ++, BX + 2
Cmp s, 0 h
When Jae L1; s is greater than or equal to 0, continue to execute L1 segments
L2: Dec count; count minus 1
MoV Cl, count; the integer portion of the obtained square root is stored in CX
Exit: mov ah, 4ch
Int 21 h
Code ends
End start
If you use masm50 for compilation, there is no error. However, if you use DEBUG for debugging and viewing, the system will crash. After a long struggle, I just don't know where the error is. If you know what the problem is, please give me some advice.