创建指向特定位置的指针
我需要一个指向始终相同的位置的指针。那么,我如何创建一个指向.. 内存地址 0x20 的指针并以某种方式存储它以便以后能够访问它。 笔记: 我不想存储结果,而是存储指向内存地址的实际指针(因为我想指向数组的开头)。
提前致谢。
——
我想我现在已经解决了。我使用 BIOS 中断 0x15 来获取内存映射。每个中断都会返回 1 个条目,并且您在 es:di 中提供一个指向 BIOS 可以存储它的位置的指针。我让 BIOS 从 050h:0h 开始构建它。我需要一个指向 0x50:0x0(0x500 线性)的指针以便稍后使用该映射。我仍然需要测试,但我做了以下操作:
mov ax, 0x50
mov es, ax
xor di, di
shl ax, 4
add ax, di
mov [mmr], ax
mmr 是这样声明的:
mmr:
dw 0 ; pointer to the first entry
db 0 ;entry count
db 24 ; entry size
I need a pointer to location which is always the same. So, how can I create a pointer to.. lets say memory address 0x20 and store it in some way to be able to access it later.
Note:
I do NOT want to store the result, but the actual pointer to the memory address (since I want to point to the beginning of an array).
Thanks in advance.
--
I think I have fixed it now. I use bios interrupt 0x15 to get a memory map. Every interrupt returns 1 entry and you provide a pointer in es:di to a place where the bios can store it. I let the bios build it up from 050h:0h. I needed a pointer to 0x50:0x0 (0x500 linear) to use the map later. I still have to test, but I did the following:
mov ax, 0x50
mov es, ax
xor di, di
shl ax, 4
add ax, di
mov [mmr], ax
And mmr is declared this way:
mmr:
dw 0 ; pointer to the first entry
db 0 ;entry count
db 24 ; entry size
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
指针只是一个内存地址,而内存地址只是一个数字。汇编不是类型语言,因此没有区别。
此外,汇编实际上没有变量。它具有寄存器和内存位置,两者都可用于存储值,包括地址/指针。
因此基本上 x86 MOV 指令有许多变体,可以将诸如
0x20
之类的指针存储在地址或寄存器中。您当然要考虑一下您正在执行 32 位还是 64 位 x86 汇编(或者 16 位甚至 8 位)。A pointer is just a memory address and a memory address is just a number. Assembly is not a typed language so there is no difference.
Also assembly doesn't really have variables. It has registers and memory locations, both of which can be used for storing values, including addresses/pointers.
So basically there are many variants of the x86
MOV
instruction that can store a pointer such as0x20
in an address or a register. You certainly want to think about whether you're doing 32-bit or 64-bit x86 assembly though (or 16-bit or even 8-bit for that matter).x86:
假设现在有一个名为
list
的数组,在 bx 寄存器中,您将有一个指向
list
的第一个内存位置的指针,以引用该内存位置中的数据您可以使用
[bx]
这里有一个使用 intel 语法的简短示例:
如果您想稍后使用指针,您可以这样做:
push bx
thenpop bx< /code> 当你想使用它时
或者
移动点,bx;在mmr中声明
x86:
suppose you have an array called
list
now, in the bx register you will have a pointer to the first memory location of
list
to refer to the data in the memory location you would use
[bx]
here's an brief example using intel syntax:
If you want to use the pointer later you can do this:
push bx
thenpop bx
when you want to use itor
mov point, bx ; declared in mmr