Compile learning notes for beginners (3) -- the first program

Source: Internet
Author: User

Getting started with crazy summer vacation Study Notes (3) -- the first program


Refer to Chapter 4 of Assembly Language


1. Process of writing a source program to execution

Step 1: Compile the Assembly source program

Step 2: Compile and connect the source program

Step 3: Execute


2. source program


Code:

assume cs:firstfirst segmentstart:mov ax,2add ax,axadd ax,axmov ax,4C00Hint 21Hfirst endsend start

Code explanation:

Assume, segment, ends, and end are all pseudo commands.


End indicates that the program has ended.

Segment and ends (note the distinction between end and sever) appear in pairs, indicating a segment. The first in front of the segment indicates the segment name and number, which can be obtained at will. A program must have at least one segment.

Assume is used to associate registers with segments.

Start: You can get the name at will, but it must be the same as the end. Indicates the entry of the program. CS: IP point.



3. Compile the connection


(64-bit Windows 7, which may be faulty. Use dosbox for simulation)


Use MASM to compile and link

Save the above Code to 1. ASM.


Compile: Input MASM 1.asmin cmd to generate 1.obj.

Link: Enter link 1.obj; in cmd to generate 1.exe


4. program running


Input 1 in cmd, and there will be no output in the running process.


The running process of the program: first, there must be a running P1 program. The P2 program to be run must be loaded into the memory from the executable file, and the CPU control is handed over to P2 for p2 to run. P1. After P2 is completed, the CPU control is handed over to P1, and then P1 continues to run. Run 1.exe p1in dosto load 1.exe as memory. Command sets the Cs of the CPU: ip z points to the First Command of the Program (that is, the entry of the Program), so that it runs. After the program is running, the command is returned, and the CPU continues to run the command.


In the previous Code: mov ax, 4c00h

Int 21 h

Function is returned by the program.

Int has nothing to do with int in English C, indicating interruption.


5. Tracking of Program Execution Process


In cmd, enter debug 1.exe to run 1.exe.

Enter R to view the register information, and you can see the length of the commands in the Cx stored source program.

DS differs from Cs BY 0010 H. cause:

Before running the program, the dossystem first finds a XX: Running H address, and creates a program segment prefix (PSP) Data zone in the first 256 of the memory segments, DOS uses PSP to communicate with the loaded program. Load the program from XX: 0010h.


Enter t for one-step execution. When int is 21 h, input P ends.






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.