The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: David on November 26, 2009, 06:15:13 PM

Title: mASM BYTE
Post by: David on November 26, 2009, 06:15:13 PM
Hi, how is a BYTE done in mASM? I have tried the following, but it does not work:

BYTE sz[2] = {0x00, 0x00};
Title: Re: mASM BYTE
Post by: dedndave on November 26, 2009, 06:20:20 PM
we use DB (define byte) for bytes

Label0  db 0       ;byte - 1 byte
Label1  dw 0       ;word - 2 bytes
Label2  dd 0       ;dword - 4 bytes
Label3  dq 0       ;qword - 8 bytes
Label4  dt 0       ;tbyte - 10 bytes

for reals

Real0   Real4 1.0  ;4 bytes
Real1   Real8 1.0  ;8 bytes
Real2   Real10 1.0 ;10 bytes
Title: Re: mASM BYTE
Post by: David on November 26, 2009, 06:30:02 PM
Quote from: dedndave on November 26, 2009, 06:20:20 PM
we use DB (define byte) for bytes

Label0  db 0       ;byte - 1 byte
Label1  dw 0       ;word - 2 bytes
Label2  dd 0       ;dword - 4 bytes
Label3  dq 0       ;qword - 8 bytes
Label4  dt 0       ;tbyte - 10 bytes

for reals

Real0   Real4 1.0  ;4 bytes
Real1   Real8 1.0  ;8 bytes
Real2   Real10 1.0 ;10 bytes


Ah I see, but how would I define more then 1 byte?

Is it like this?

BYTE Label1[1] = {0x90}; = 1 byte :  Label0 db 0x90
BYTE Label1[2] = {0x90,0x90}; = 2 bytes : Label1 dw 0x90, 0x90
BYTE Label3[3] = {0x90, 0x90, 0x90}; = 3 bytes : ??
BYTE Label1[4] = {0x90, 0x90, 0x90, 0x90}; = 4 bytes : Label3 dd 0x90, 0x90, 0x90, 0x90

?

Title: Re: mASM BYTE
Post by: dedndave on November 26, 2009, 06:34:06 PM

Label0  db 20 dup(0)            ;creates 20 0's
Label1  db 'String',0,20 dup(?) ;creates a string, a 0, and 20 unknowns
Title: Re: mASM BYTE
Post by: oex on November 26, 2009, 06:40:33 PM
Quote from: dedndave on November 26, 2009, 06:34:06 PM

Label0  db 20 dup(0)            ;creates 20 0's
Label1  db 'String',0,20 dup(?) ;creates a string, a 0, and 20 unknowns


Is that effectively allocate 20 unknowns then 0 fill? Could (?) ever be anything other than (0)?
Title: Re: mASM BYTE
Post by: RuiLoureiro on November 26, 2009, 06:50:15 PM
Quote from: David on November 26, 2009, 06:15:13 PM
Hi, how is a BYTE done in mASM? I have tried the following, but it does not work:

BYTE sz[2] = {0x00, 0x00};
is
sz     db 2 dup (00h)                  ; 0x00 = 00h      0x90=90h

BYTE Label1[4] = {0x90, 0x90, 0x90, 0x90};
is
Label1   db 4 dup (90h) 
Rui
Title: Re: mASM BYTE
Post by: David on November 26, 2009, 06:58:15 PM
Quote from: RuiLoureiro on November 26, 2009, 06:50:15 PM
Quote from: David on November 26, 2009, 06:15:13 PM
Hi, how is a BYTE done in mASM? I have tried the following, but it does not work:

BYTE sz[2] = {0x00, 0x00};
is
sz     db 2 dup (00h)                  ; 0x00 = 00h      0x90=90h

BYTE Label1[4] = {0x90, 0x90, 0x90, 0x90};
is
Label1   db 4 dup (90h) 
Rui

How about if I want to create a BYTE with not just one value?  Like BYTE Label1[4] = {0x94, 0x19, 0x20, 0x20};

Title: Re: mASM BYTE
Post by: RuiLoureiro on November 26, 2009, 07:06:55 PM
Quote
How about if I want to create a BYTE with not just one value?  Like BYTE Label1[4] = {0x94, 0x19, 0x20, 0x20};
Quote
Label1    db 94h                    or    Label1  db 94h,19h,20h,20h
             db 19h
             db 20h
             db 20h
Label X ...
Rui
Title: Re: mASM BYTE
Post by: David on November 26, 2009, 07:07:30 PM
Thank you very much.
Title: Re: mASM BYTE
Post by: hutch-- on November 28, 2009, 06:36:02 AM
Try this,


LOCAL Buffer[128]:BYTE


128 bytes allocated on the stack with local scope. Note that the content of the allocated stack buffer is undefined, it can be any trash on the stack. If you want it initialised to anything you must do it yourself.

You get the start address with LEA.


    lea eax, Buffer
  ; set it to zero length for zero terminated strings
    mov BYTE PTR [eax], 0