免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4497 | 回复: 4
打印 上一主题 下一主题

NASM怎样定义局部数组? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-12-05 17:48 |只看该作者 |倒序浏览
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 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2007-12-05 17:56 |只看该作者
如果是:

enter %$localsize 5       ; 5个变量

那怎么访问呢?
第一个: ?
第二个: ?
。。。。。

例子中是:
mov     [old_ax] , ax
那总不能是:
mov     [old_ax[0]] , ax      ; 不对吧

论坛徽章:
0
3 [报告]
发表于 2007-12-05 18:06 |只看该作者
如果不能定义数组的话
那就只能多定义几个变量了。

%local old_ax:word, old_dx:word

但不知这些变量在堆栈中怎么分布的?

|                   |
| old_ax        |
|---------------|
| old_dx        |
|                   |
|                   |

or


|                   |
| old_dx        |
|---------------|
| old_ax        |
|                   |
|                   |

[ 本帖最后由 gjl606 于 2007-12-5 18:18 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2007-12-15 16:11 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
5 [报告]
发表于 2007-12-16 22:11 |只看该作者
局部的数组就在栈上分配嘛. 移动esp嘛,足够的空间然后赋址,可以用ebp寻址.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP