gjl606 发表于 2007-12-05 17:48

NASM怎样定义局部数组?

MASM中可以用local定义局部变量,定义数组也很简单。。

例如:
localaa:byte

mov byte ptr aa, 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   ,ax   ; swap ax & bx
      mov   ,dx   ; and swap dx & cx
      mov   ax,bx
      mov   dx,cx
      mov   bx,
      mov   cx,
      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 编辑 ]

gjl606 发表于 2007-12-05 17:56

如果是:

enter %$localsize 5       ; 5个变量

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

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

gjl606 发表于 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 编辑 ]

端午粽子节 发表于 2007-12-15 16:11

随风缘 发表于 2007-12-16 22:11

局部的数组就在栈上分配嘛. 移动esp嘛,足够的空间然后赋址,可以用ebp寻址.
页: [1]
查看完整版本: NASM怎样定义局部数组?