The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: edhalsim on February 28, 2005, 08:15:04 PM

Title: How to setup an array?
Post by: edhalsim on February 28, 2005, 08:15:04 PM
I need to create an array as follows:

myArray    db  8 DUP(000h)
                db  8 DUP(001h)
                db  8 DUP(002h)
                db  8 DUP(003h)
                db  8 DUP(004h)
                db  8 DUP(005h)
                db  8 DUP(006h)
                db  8 DUP(007h)
                db  8 DUP(008h)
                db  8 DUP(009h)
                db  8 DUP(00Ah)
                db  8 DUP(00Bh)
                db  8 DUP(00Ch)
                db  8 DUP(00Dh)
                db  8 DUP(00Eh)
                db  8 DUP(00Fh)
                db  8 DUP(010h)
etc., all the way up to
                db  8 DUP(0FFh)

In other assemblers, I've seen something like this:
   %assign iter 0
   %rep 256
      db   iter,iter,iter,iter,iter,iter,iter,iter
      %assign iter iter+1
   %endrep
Is there a similar construct in MASM?

Thanks for your help.


Title: Re: How to setup an array?
Post by: MichaelW on March 01, 2005, 05:04:55 AM
One of several methods:

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\kernel32.lib
    include \masm32\macros\macros.asm
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
        initializer = 0
        myArray db 8 dup(0)
        REPEAT 255
          initializer = initializer + 1
          db 8 dup(initializer)
        ENDM
    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    ; Verify first 16 elements:
    mov   ebx,OFFSET myArray
    REPEAT 16
      print uhex$([ebx])
      print chr$(13,10)
      add   ebx,8
    ENDM

    mov   eax,input(13,10,"Press enter to exit...")
    exit
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start