80x86 assembly—addressing modes

Terminology explanation

  • EA: Effective address, Effect Address obtained by combining segment address: offset address

  • Displacement: usually a constant and a label. For example, the first address of a certain data segment is the ARR label, then we can directly write the label ARR to find the first address of the data segment.

  • Base address: BX and BP registers are generally used as base addresses

    What’s interesting is that I initially thought that the segment address was the base address and the segment address was the elder one, and our offset address was the younger one, so we all used it as the basis and thought that the segment address was the base address, but in fact it’s not. Yes, BX and BP can be used as base addresses. The base address means that it can be used as a reference in the offset address. For example, if you MOV an address into BX, we can use the base address to address BX when addressing. Base, without modifying it, then use the index register to change it. (Index will be mentioned below)

  • Index value: Generally, SI and DI are used as index registers to change the address value, just like the subscript of an array.

  • Scale factor: This one is funny. It actually means multiplying a number, usually 1, 2, 4, 8, because computers use these bases, and the scale factor appears because we can multiply the index by the scale factor. The register jumps to find the address. For example, SI * 4 means that every time SI changes, the address can be addressed in multiples of 4.

  • detail:Segment addresses are mentioned later. In fact, our addressing method does not involve segment addresses., so when I was learning it, I was not clear about it, which led to me not understanding base address addressing and the subsequent addressing methods were also wrong.
    Secondly, the segment address does not need to be written in addressing, but it must be specified when needed. (It will be explained in detail later when it needs to be specified)


It doesn’t matter if you didn’t understand the above. I only made up the explanation here after I finished studying.

8086 addressing mode

Literal addressing

  • Literal addressing
    MOV AX, DS:[0110H]
  • Label addressing
    MOV AX,label, for example, if we define a data segment called data, we can directly use data as a label to address the address of this data.

register indirect addressing

MOV AX, [SI]
MOV AX, [DI]
MOV AX, [BX]
MOV AX, [BP]
MOV [SI], AX
can be used in many ways, but AX cannot be used as a register for addressing. When verifying , the error message in debug said: must be index or base reg, so I understood it as AX is not a subscript register or a base address register.
Insert image description here

register relative addressing

Relative addressing means having a label or fixing a constant address as the first address and then using an index register. It is easy to be confused with the base address addressing method. The base address uses a register, but here it uses a constant and a label (actually the label is Constant, it becomes a constant after the compiler is executed)
Here, let: ARR be the label address
MOV AX, ARR[SI],There is no colon after ARR here, not a segment address , don’t get confused, and you will see in debug that it is equal toEA = [ARR + SI]
In fact, you can also write it like this: MOV AX, [ARR + SI], but since the name register relative addressing has come up, let’s use it in a proper way. According to the rules, it is actually the best to use in actual combat.
Of course, not only SI and DI can be used. It can also be used, BP can also be used, but the MOV AX, ARR[SI] here defaults to the DS segment
If you want to use BP, please remember that if you do not specify a segment address, BP's default segment address is the SS stack segment.

Insert image description here
You can see that the unspecified and specified segment addresses are different.
38h[bp][si] is actually equal to [BP + SI + 38h]. If you don’t believe it, you can also see in the picture. The debugged address is [BP + SI + 38h]

base index addressing

Why not say base address?
Okay, I said, MOV AX, [BP], this is base address addressing, which is no different from register indirect addressing.
Why not talk about indexed addressing?
Okay, let me say it again, MOV AX, [SI], this is the indexed addressing you want. What is the difference between this and register indirect addressing.
Therefore, let’s learn base address index addressing.
Assume here: ARR is a label. Assume that the ARR address is equal to 1010H.
MOV AX, ARR[BP][SI]
can also be MOV [BP][DI], AX. It is not just the source operand. Only by using this addressing method can
we see BP, and the segment address is not specified, then the segment address of our instruction is SS.
The base address is BP and the index is SI. The combination is the base-indexed addressing mode.
In fact, after debugging, this is equal to: [BP + SI + 1010H]. Of course, ARR will become the address value.

Proportional indexed addressing mode

This purpose is: assuming that each data in our data segment occupies several words, for example, one element of ours occupies 4 words, our index form can add +4 each time, but this is too troublesome, we directly SI * 4, SI only needs to be increased by 1 each time to complete jump addressing, without the trouble of increasing SI by 4 each time.
First of all, grasp the words, ratio + index, that is, just use the index register and the scale factor.
MOV AX, ARR[SI * 4]
This command is essentially equal to: [ARR + SI * 4]. SI * 4 will generally be calculated for you in debug and the result will be placed in [this].

Base address proportional indexed addressing mode

After learning this, I just tore up the book and chose to write it myself.
I guess the command format must be: MOV AX, ARR[BP][SI*4]
There is no book, so look at the PPT screenshot for the answer. His TABLE and my ARR have the same meaning, just a label, and EBP is 32 bits. Register request, I used a 16-bit register here, EBP is the same as BP, the default segment register is SS, so I guessed it right, I hope I can continue to guess it correctly in the future...
Insert image description here


Summary: The most anti-human thing is that the relative addressing format is ARR[SI]. This is really base addressing, because the base address is to find a benchmark. The relative addressing ARR here is too much like a base address. There, but then I thought about it, ARR as a label is an address. It is not that a register cannot be used as a base. This sentence can only be understood but cannot be expressed in words. I don’t know how to say it. In short, our base address needs a register to represent it, so what follows When I was learning the base address indexed addressing method, I suddenly realized that the original base address requires a register as a reference.
Another thing that made me fall into a big trap is: I always thought that the segment address is the base address addressing method, but the ones we use here are all within the segment. I realized it later, and now I understand, everything is because ARR looks too much like a base address, which makes me think that CS:IP is the base address addressing method.
After learning this, although it is said to be anti-human, in fact, when you think about the command system, he does not even give you a clear breakdown of the methods and so on. It is even more troublesome. Someone can help you what the addressing method of the classification number is. In fact, it is more It's easy for me to learn.
Anyway, I hope I won't mix it up again in the future...

Guess you like

Origin blog.csdn.net/weixin_60521036/article/details/135074936