Win32 assembly language programming (1) Basic Concepts

Source: Internet
Author: User
Tags constant definition

The first basic concept of Win32 Assembler

Win32 programs run in protected mode. In Windows, every Win32 application is put into a separate virtual address space to run. That is to say, each application has a 4 GB address space independent from each other, the operating system converts the 4 GB virtual address and physical memory address when the application is running, and divides the code into data in 16-bit windows, code and other segments have different memory modes. Win32 only has one memory mode, namely, flat mode. All Win32 applications run in a continuous, flat, and huge 4 GB space. This also means that you do not need to deal with segment registers. You can use any segment registers to address any address space, which makes it as convenient to use a 32-bit assembly language as a C language.

Programming in Win32 requires many important rules to be followed. One important thing is that Windows frequently uses ESI, EDI, EBP, and EBX registers internally, and does not check whether the values of these registers are changed, in this way, when you want to use these registers, you must first save their values and restore them after they are used up. The most significant application example is the Windows callback function.

. 386; tell the compiler that our program is written using the 80386 instruction set or. 486. 586 but 386 is the safest.
. Model flat, stdcall; specifies the memory mode, parameter transfer mode, and who will recover the stack when calling the function (caller or function)
. Data; note that Win32 does not have a segment (sectionment) concept, but you can divide the program into different segments with only two types of data and code.
<Your initialized DATA>; data segments are divided into three types: initialized data.
......
. Data ?; Uninitialized data
<Your uninitialized data>
......
. Const; constant definition
<Your constants>
......
. Code; Code Segmentation
<Label>; is the tag that uniquely identifies your code range. The two tags must be the same, and All executable code of the application must be between the two labels.
<Your code>
.....
End <label>

Segments do not indicate different segments of registers for different segments, as in DOS, because Windows only has a 4 GB segment, in a Windows program, segments are represented by assigning different segments with different attributes when the program is loaded. For example, when your program is loaded, for ring3 programs ,. the code segment cannot be written, while. data segments are writable. If you try to write your own code as in DOS, you will get a blue screen error.

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.