Compilation of macros to achieve "Hello World" _x86

Source: Internet
Author: User

Share your resources ...

Link: Https://pan.baidu.com/s/1z6zdi-szqWLFgzBhnPYXoQ Password: 638v

The necessary knowledge reserves

Debug.exe is just a debugging tool, not a compilation tool, and cannot generate an executable program from a A.ASM assembly connection.
The Debug.exe has built-in assembler functionality, but is extremely weak, and can only support the assembly of instructions and does not support the assembly of most commonly used pseudo directives. For example, it does not support the use of variable names and statement labels. It can only be compiled with a command-by-order after entering debug.

To assemble a a.asm-like assembly-language source program into an executable file, you have to use a separate assembly and connection program. There are two kinds of commonly used assembly connection tools, one is MASM, the other is tasm. (The above links have, which tasm download cost me two pieces of the ocean ...) )

MASM requires at least two files: Masm.exe and Link.exe versions can be over 5.0.
Tasm needs Tasm.exe and Tlink.exe, as well as some ancillary files. The version can be 3.0 or 5.0.

There are some suggestions on the Internet to use TASM, said that its biggest advantage is that it is equipped with the debugger Turbo debugger features more powerful than debug, many, many times, window interface, mouse operation ....

Strong not strong, now first into the assembly I dare not to fancy, and so have been used again to make a conclusion.

about MASM integrated development environment

Of course I also downloaded an integrated ide,masm for Windows 2012, looking pretty good, but some of the features need to register to use, but as a beginner, free function of the plenary should also be almost the introduction of it.

Emmm, and, among other things, I'm more optimistic about the two tool tools-> options for debugging

How good, I also can't say, intuition ...

Hello World Writing

A new language, still starting with our Hello Word, the significance of Hello World is much more than the surface.

The full segment of Hello World program
DATAS  SEGMENT
     STRING  DB  ' Hello world! ', 13,10, ' $ '
DATAS  ENDS

Codes  SEGMENT
     assume    cs:codes,ds:datas
START:
     mov  ax,datas
     mov  ds,ax
     LEA  dx,string
     mov  ah,9
     int  21H

     MOV  ah,4ch
     int  21H
codes  ENDS
    End   START

Notice that the string name was originally STR, then dead or dead, and suddenly found that Str was a key word for the assembly ....

1.SEGMENT: Represents a segment, segment defines a pseudo instruction.

There are data segments, code snippets, stack segments, and additional segments in the Assembly
Format is: segment name SEGMENT [Location type] [combination type] [class name]
Section name ENDS
Function: To segment the program to realize the segmented management of memory
The program consists of two parts, the Datas data segment and the Codes code snippet.

2.STRING DB 13,10, ' Hello world! ', 13, 10, ' $ '

13 and 10 represent the ASCII code for carriage returns and newline characters, and the result is a carriage return line feed
' $ ' is the end sign, otherwise no ' $ ' will appear garbled.
This sentence is equivalent to C (char*) string= "\nhello world!\n";

3.INT 21H is the interrupt number of DOS interrupt function call; MOV ah,4ch function is to get you out of the program

which
MOV ah,4ch
INT 21H
is the template used at the end of the program, using AH to select features, where the 4CH function is to quit the program meaning. This interrupt tells the program to return to DOS when it finishes execution.

Read more about DOS function < here.

4.MOV ah,9 9 is the command number that prints the string (09H corresponds to the display string)

Note: The first assembler example in the classroom and in many textbooks: "123+456=sum" is not an output statement, you must use debug debugging to display the results of the program.

5. Put the data into the DS
MOV AX, DATAS
MOV DS, AX

The starting address of the data segment is loaded into the DS, the datas is immediately counted, so it is not possible to put it directly into the DS segment register, which requires the help of a universal register.

6.

LEA dx, string; string offset start dx
Lea:loadeffective Address

Execution procedure

Or the old ways of the previous section.

MASM How to enter the debugging mode.

If the input TD 2.exe, under the MASM is not possible,

Only Debug 2.exe

But if in TASM environment, TD is OK ...

Note that the operation is slightly different ...

This article temporarily first here, bedroom to access the door, I want to gallop back ...

April 26, 2018 23:49:15

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.