在汇编器中寻址 [英] addressing in assembler

查看:110
本文介绍了在汇编器中寻址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些东西我无法消化.我正在学习一些汇编程序,现在我正在讨论寻址这一章.我了解方括号用于取消引用的概念,但是以某种方式,当我看到它的用法时,我无法理解它的意义.更确切地说,这是我开始困惑的地方:

There is something I can't digest. I'm learning some assembler and right now I'm at the chapter with addressing. I understand the concept of brackets for dereferencing, but somehow when I see the usage of it I just can't soak up the point of it. To be a little bit more exact here is where my confusion started:

mov al, [L1]

在这里我以L1为例,是某种宏,该宏以后会在机器代码中替换为真实地址,对吧?

Here I suppose L1 as an example case is some kind of macro which is later substituted for a real address in the machine code, right?

因此,该指令的作用是:取消引用al寄存器(因为几乎无法更改物理地址),并将其值更改为存储在L1处的值.

So what this instruction does is: dereferencing al register (because you could hardly change physical address) and changing the value to the one stored at L1.

如果到目前为止一切正常,就可以了:

If till now everything is ok:

mov [L1], al

可以类比地表示,必须存储一个地址(这样做有一定意义),然后将其更改为内存中的其他位置,对吗?

that would analogicaly mean, there must have been an address stored (so there was some point in doing this) and you change it to some other place in memory, right?

如果您能告诉我没问题的话可以,请这样做,这将使我有可能继续学习.

If you could just tell me it's ok in case you don't see any mistakes please do it, that would make it possible for me to continue learning.

最后一件事,NASM在我的代码下添加了一堆0xAA55(此序列应该可以结束该程序吗?),为什么它出现了那么多次?

One last thing, NASM adds a bunch of 0xAA55 under my code (this sequence is supposed to end the program right?), why is it there so many times?

推荐答案

L1 ,通常/可能是 标签与内存中的一个特定地址相关联.程序员为了方便起见定义了各种标签,这些标签用于象征性地表示内存中的特定位置(L1是一个糟糕的名称;标签通常表示该位置的基本用途:例如PingCounter,ErrorMessage,Login等).

L1 is typically/probably a label, associated with one particular address in memory. The programmer defines various labels for his/her convenience, and such labels are used to symbolically represent a particular location in memory (L1 is a lousy name; labels are typically indicative of the underlying purpose of the location: say, PingCounter, ErrorMessage, Login and the like).

一个1字节静态存储空间的标签是C编译器在全局范围内实现char L1;的方式.

A label for 1 byte of static storage is how a C compiler would implement char L1; at global scope.

在NASM语法中,mov edi, L1将组装为 mov eax, imm32 形式的mov,即标签地址在机器代码中将变为32位立即数. (汇编器不知道最终的数值,但是链接器知道.)请注意,在MASM语法中,这将是一个负担,并且您需要mov edi, OFFSET L1才能获取标签地址作为立即数.

In NASM syntax, mov edi, L1 will assemble to the mov eax, imm32 form of mov, i.e. the label address will become a 32-bit immediate in the machine code. (The assembler doesn't know the final numeric value, but the linker does.) Beware that in MASM syntax, this would be a load and you'd need mov edi, OFFSET L1 to get a label address as an immediate.

但是mov al, [L1]将汇编为另一条指令,并将32位地址嵌入机器代码中,作为要取消引用的地址.该指令从地址L1加载1个字节,并将其放入AL中.

But mov al, [L1] will assemble to a different instruction, with the 32-bit address embedded in the machine code as an address to be dereferenced. This instruction loads 1 byte from the address L1, and places it in AL.

在汇编语言中,此间接寻址模式通过用方括号括起来给定指令的源或目标操作数来表示. (但不能同时使用:x86每条指令最多只支持一个显式内存操作数.)

In the assembly language, this indirect addressing mode is signified by square bracketing the source or destination operand of a given instruction. (But not both: x86 only supports at most one explicit memory operand per instruction.)

mov al, [L1]

使用L1中存储的地址在内存中定位某个位置,并在该位置读取1个字节(= 8位= AL寄存器的大小),并将其加载到AL寄存器中.

uses the address stored in L1, to locate some location in memory and reads 1 byte (= 8 bits = the size of AL register) at this location, and loads it into the AL register.

  mov [L1], al

反向执行此操作.即,具体来说,读取存储在L1中的地址,使用该地址在内存中查找特定位置,并将AL寄存器的内容存储在其中.

Does this in reverse. i.e., specifically, read the address stored in L1, use this address to find a particular place in memory and stores the contents of AL register there.

如果您了解以下有关x86家族中较新处理器的信息不完整且有些过时,则此

Provided that you understand the following information to be incomplete and somewhat outdated with regards to the newer processors in the x86 family, this primer on the 8086 architecture is probably very useful to get one started with Assembly language for the x86 family.
The advantage of starting with this "antiquity of a CPU" (still in use, actually), is that the fundamental concepts are all there, unencumbered of the newer sets of registers, fancy addressing modes, modes of operation and other concepts. The bigger sizes, features and modes of the newer CPUs merely introduce a combinatorial explosion of options, all (most?) of them useful in their way, but essentially irrelevant for an initiation.

这篇关于在汇编器中寻址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆