NASM怎样定义局部数组?
MASM中可以用local定义局部变量,定义数组也很简单。。
例如:
local aa[10]:byte
mov byte ptr aa[0], 1
NASM中有个%local可以定义,但怎么定义数组,没说明。。有知道的吗?
--------------------------------------------------------------------------------
4.9.3 %local Directive
The %local directive is used to simplify the use of local temporary stack variables allocated in a stack frame. Automatic local variables in C are an example of this kind of variable. The %local directive is most useful when used with the %stacksize (see section 4.9.2 and is also compatible with the %arg directive (see section 4.9.1). It allows simplified reference to variables on the stack which have been allocated typically by using the ENTER instruction (see section B.4.65 for a description of that instruction). An example of its use is the following:
silly_swap:
%push mycontext ; save the current context
%stacksize small ; tell NASM to use bp
%assign %$localsize 0 ; see text for explanation
%local old_ax:word, old_dx:word
enter %$localsize,0 ; see text for explanation
mov [old_ax],ax ; swap ax & bx
mov [old_dx],dx ; and swap dx & cx
mov ax,bx
mov dx,cx
mov bx,[old_ax]
mov cx,[old_dx]
leave ; restore old bp
ret ;
%pop ; restore original context
The %$localsize variable is used internally by the %local directive and must be defined within the current context before the %local directive may be used. Failure to do so will result in one expression syntax error for each %local variable declared. It then may be used in the construction of an appropriately sized ENTER instruction as shown in the example.
从这段话里面看不出怎么定义数组?是不是和%$localsize有关?
[ 本帖最后由 gjl606 于 2007-12-5 17:53 编辑 ]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果是:
enter %$localsize 5 ; 5个变量
那怎么访问呢?
第一个: ?
第二个: ?
。。。。。
例子中是:
mov [old_ax] , ax
那总不能是:
mov [old_ax[0]] , ax ; 不对吧
如果不能定义数组的话
那就只能多定义几个变量了。
%local old_ax:word, old_dx:word
但不知这些变量在堆栈中怎么分布的?
| |
| old_ax |
|---------------|
| old_dx |
| |
| |
or
| |
| old_dx |
|---------------|
| old_ax |
| |
| |
[ 本帖最后由 gjl606 于 2007-12-5 18:18 编辑 ]
局部的数组就在栈上分配嘛. 移动esp嘛,足够的空间然后赋址,可以用ebp寻址.