Small Turtle 0 Basic assembly Language study notes the first assembler in chapter fourth

Source: Internet
Author: User

1. Using tools       code writing: notepad++, code compiler: MASM 2, a source program from write to execute process       First step, using a text editor, Compile the source program in assembly language, this step produces a text file that stores the source program.       The second step is to compile and connect the source program. Use MASM.exe to compile the source program files, generate the target files, and then use LINK.exe to connect to the target file to generate executable files that can be run directly in the operating system. The executable file consists of two parts, the program (the machine code translated from the assembly instruction of the source program) and the data (the data defined in the source program), the relevant description information (how large the program is, how much memory space to occupy). This step produces an executable file that can be run directly in the operating system. exe.       Third, execute the executable file. The operating system loads the machine code and data in the executable file into memory according to the description information in the executable file, and initializes the relevant initialization, such as Cs:ip pointing to the first assembly instruction to be executed. The program is then executed by the CPU.  3, a simple assembly language source program      assume CS:CODESG     CODESG segment                  mov ax,0123h                  mov bx,0456h                 add ax,bx        &NBS P        Add ax,ax                  mov ax,4c00h                 int 21h        codesg ends       end           The code above is a simple addition operation, here are some concepts to explain.       First, pseudo-directive. Assembly instructions and pseudo-directives are included in the Assembler language source program. The assembly instruction is translated into the corresponding machine code, while the pseudo-instruction does not have the corresponding machine code, and ultimately cannot be understood by the CPU, but it is understood by the compiler. A pseudo-directive is a compiler-compiled instruction that compiles according to pseudo-directives. In the above program, the pseudo-directive has Assume,segment...ends,end。 (1) segment...ends segment and ends are pseudo-instructions appearing in pairs. Meaning a segment is defined between the two, segment represents the beginning of a segment, and ends represents the end of a segment: segment name segment  .  .Segment name ends a assembler can consist of multiple segments that are used to store code, data, or be used as a stack space. (2) End end is a token that the assembler ends, and the compiler stops compiling the source program when it encounters a pseudo-directive when it compiles the program.          So when the program is finished, you must add the pseudo-directive end.       (3) Assume assume means "hypothesis", assuming that a section register and a segment of the program are associated, that is, to tell the CPU which segment to point to, from where to start executing the meaning of assembly instructions. In the code above, CODESG SEGMENT...CODESG ends defines a segment named CODESG, where the code is stored, so this segment is a code snippet. The program begins with assume CS:CODESG to associate the code snippet CODESG with the segment register CS in the CPU. 4. The program in the source program is programmed in assembly language including pseudo-instructions and assembly instructions. Assembly instructions are programs that are ultimately executed by the computer, and pseudo-directives are executed only by the compiler. Therefore, the "program" in the source program refers to the assembly instructions or data composition. The program is converted to a CPU-aware machine code after compiling the connection, as shown in the following procedure:

5, the Label assembly program, in addition to assembly instructions and pseudo-instructions, there are some markings. It's like "CODESG" in the example code above. A label refers to an address. For example CODESG before segment, as the name of the segment, the name of this segment is eventually compiled, the connection process is processed as a segment of the segment address. 6, the program returns in the above example code: mov ax,4c00h int 21H The function that the two instruction implements is the program returns.     Using these two instructions at the end of the program will enable the program to return. Here we want to understand what the program returns. In DOS single-task operating system, only one program can be run at a time, when the program 1 is running, program 2 to run, you want to control the CPU to program 2, program 2 to be run. Program 2 starts running and program 1 pauses. When the program 2 is finished, the control of the CPU should be returned to program 1, after which, program 1 continues to run. Therefore, after a program is finished, the control of the CPU is returned to the program that makes the program run, which is the process of returning the program. 7. Distinguish between concepts related to "end" here we have learned a few "end" related concepts, which are differentiated as shown in the following table:

8, compile the source program first we have a compilation compiler, here we use is MASM, need to download, you can go to my Baidu network disk download, Link: http://pan.baidu.com/s/1dFMUgH7 (password: XDPM) put the source program files and compilers together To facilitate our direct compilation:

Enter the CMD Small black window, enter into the MASM compiler directory, run MASM.exe: An object file appears in the folder:

Next we use LINK.exe to connect to this object file:

Once connected, an executable file appears in the folder: To see how the program is running, we can use debug to step through it: we can see that, with the T command stepping into debug, the assembly instructions we write in the program are run. One thing to note here is that when the statement executes to the last "int 21", we use the P command to end. After debugging, press "Q" to exit Debug and return to command. 9, summary assembler from writing to execution process as shown:

Small Turtle 0 Basic assembly Language study notes the first assembler in chapter fourth

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.