The joy and hardship of compilation

Source: Internet
Author: User

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.

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.