(Translation) Win32ASM tutorial -3

zhaozj2021-02-16  54

4.0 memory

This part will explain how memory is managed in Windows.

3. 1DOS and Win3.xx

In a 16-bit program like DOS and Win3.xx, memory is divided into many segments. These segments have a size of 64kb. In order to store memory, a segment pointer and an offset pointer are required. Segment pointer indicates which segment to be used, and the OFFSET pointer indicates the location of the section itself. Look at the picture below:

RAM

Segment 1

(64KB)

Segment 2

(64KB)

Segment 3

(64KB)

Section 4

(64KB)

More

Note the interpretation of the 16-bit programs, there are more about 32-bit (but don't skip this part, understand 32-bit memory management, this part is very important) The table is all the memory, divided into 64KB of multiple sections. There are up to 65536 segments. Take out now:

Segment 1 (64KB)

OFFSET 1

OFFSET 2

Offset 3

Offset 4

OFFSET 5

More

In order to point to the position in the segment, OFFSET needs to be used. An offset is a location within the segment. There are up to 65536 OFFSETs per segment. The address of the address is:

Segment: offset

E.g:

0030: 4012 (all of which are 16)

It means: segment 30, offset4012. What is it in this address. You first go to the segment 30, then go to the offset4012 of the paragraph. In the previous chapter, you have learned the segment and pointer registers. For example, segment registers are:

Cs

Code segment

DS

Data segment

SS

Stack segment

ES

Expand segment

FS (ONLY 286 )

Full functional segment

GS (ONLY 386 )

Full functional segment

As the name suggestion: The code segment (CS) includes any of the current code executions. The data segment is used to indicate which section takes out data. Stack finger stack (there are more behind). ES, FS, GS are full-featured registers and can be used for any segment (although not in Windows).

Most of the pointer registers are equipped with OFFSET, but full-featured registers (AX, BX, CX, DX, etc.) can also be used. IP indicates which OFFSET is executed when the current instruction is executed. The SP saves the current stack of Offset1, in SS (in the stack).

4.2 32-bit Windows

You may have noticed everything about the segment is bored. in

16

During the bit programming, the segment is essential. Fortunately, this problem is already

32

Position

Windows

(

95

And above) is solved. You still have a paragraph, but you don't have to manage them because they are no longer

64KB

But

4GB

. If you try to change one of the segment registers,

Windows

Even crashes. This is called flat (

Flat

) Memory mode. only

Offset

And is

32

Bit, thus

0

Until

4,294,967,295

. Every address in memory is used

Offset

Representation. This is really

32

Be worth

16

The biggest advantage of bit. So, you can now forget the segment register and concentrate on other registers.

转载请注明原文地址:https://www.9cbs.com/read-26633.html

New Post(0)