Author Topic: how do i declare local variable array ?  (Read 19455 times)

david

  • Guest
how do i declare local variable array ?
« on: December 06, 2007, 02:37:07 AM »
MASM declare loacl variable array and access it like this :

local  aa[10]: byte

mov byte ptr aa[0], 16

i want to know how to do it by nasm ?

it seems like need to use %local .

the example in nasm nasm_man:

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

i want to know how to declare local variable array ?

nobody

  • Guest
Re: how do i declare local variable array ?
« Reply #1 on: January 07, 2008, 04:21:54 PM »
I'd like to know the same thing =/
Maybe var:dword:dword... ? But I need a 1024 byte local var.
If there's someway to do a data size type like dword, etc..

nobody

  • Guest
Re: how do i declare local variable array ?
« Reply #2 on: January 08, 2008, 02:02:36 AM »
> MASM declare loacl variable array and access it like this :
> local aa[10]: byte
> mov byte ptr aa[0], 16
> i want to know how to do it by nasm ?
> it seems like need to use %local .

Maybe there are other ways but you always can "push" EBP, "mov" EBP,ESP and "sub" the ESP manually so your array will land below EBP ;-)

Philippe RIO

  • Guest
Re: how do i declare local variable array ?
« Reply #3 on: May 04, 2008, 10:31:08 AM »
MASM declare loacl variable array and access it like this : LOCAL, that's all. I am not sure you are speaking about MS ASM ?

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: how do i declare local variable array ?
« Reply #4 on: February 08, 2010, 07:19:20 PM »
I know this thread is old, but I've noticed people viewing it a lot lately and there never was really a clear answer. To create local variables in a simple manner, I use STRUC's.

Code: [Select]
SampleProc:
STRUC @SPL
.dwTest    RESD 1    ; Local dwTest:DWORD
.arTest     RESD 10  ; Local arTest[10]:DWORD
ENDSTRUC
    Push Ebp
    Mov Ebp, Esp
    Sub Esp, @SPL_size

        ;; Access your locals through [Ebp - 8 - @SPL.dwTest] and [EBP - 8 - @SPL.arTest]

    Leave
    Ret

About Bryant Keller
bkeller@about.me