News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

About MASM32 syntax

Started by Dasar, June 11, 2006, 10:23:52 AM

Previous topic - Next topic

Dasar

hi all

i have searched alot about MASM32 Syntax tutorials , but i can't find any useful one, i have read the first 3 iczelion's tutorials, but i noticed that iczelion didn't focus on syntax of masm32...

i have a good experience in delphi and win32 API, and i know a little about assembly, i know what is the stack, registers, and some asm instructions, such as , mov, add, sub, mul, jpm, push, pop....

in short, i want a list of data types in masm32, and how to declare my own types, how to make a structures, how to make arrays, what is the syntax of loops and how many loop type are in masm32, procedure and functions , if & else statements,  variables, comments, etc....

btw, i searched alot in google, but the best tutorials i found are iczelion's tutorials   : '(

could anyone please give me links, books, articles ... ?


thank you alot in advance :)

Ossa

You want the MASM Programmer's Guide, it is (along with a lot of other MASM documentation) available on Randall's site: http://webster.cs.ucr.edu/AsmTools/MASM/index.html

Quote from: Dasar on June 11, 2006, 10:23:52 AM
in short, i want to know how to declare types, how to make a structures, how to make arrays, what is the syntax of loops in masm32, procedure and functions , if & else statements,  variables, comments, etc....

The other good way to find out about these is to look in the help file that comes with the MASM32 package (in the help folder). Then look up information on:
TYPEDEF, STRUCT, UNION, DUP, PROC, PROTO, .if, .elseif, .else, .while, EXTERNDEF, EXTERN, ;, COMMENT, LOCAL

and many many more - if you have specific questions, just ask them here.

Ossa
Website (very old): ossa.the-wot.co.uk

Dasar

Ossa, thank you alot for your fast reply : )

this is exactly what i was search about :-D

you're a nice one ^_^


dsouza123

For an array:
  arrayname dd 256 dup (2)
This creates an arrary of 256 dwords each dword initialized with the value 2.

another way is
  arrayname dd 15, 3500, 182, 64
This creates an array of 4 dwords each initialized with a different value.

Access to the array, (the 4 item one)

mov eax, arrayname     ; will copy the value 15 from the first dword into eax
mov ebx, arrayname+4   ; copies 3500 into ebx
mov ecx, arrayname+8   ; copies 182 into ecx
mov edx, arrayname+12  ; copies 64 into edx

because a dword is 4 bytes, the increment between items in a dword array is 4.
Arrays are 0 based, the first item is at address arrayname+0.

A more flexible alternative to hardcoding the offset from the start of the array is

  mov esi, 3
  mov edx, [arrayname + esi*4] 

this will get the dword (value 64) starting at 3*4=12  bytes
past the address of arrayname
it is array item 3 if counting 0,1,2,3 for the item index.

By having the item index in a register, any item can be accessed just by
modifying the register. 

Then it would be the same as the following Delphi/Pascal

type
  arrtype = array[0..3] of longword = (15, 3500, 182, 64);
var
  d   : longword;
  i   : longword;
  arr : arrtype;

begin
  i := 3;
  d := arr[i];


Some storage types
dd is also specified dword is a 32 bit unsigned integer, values 0 to 4294967295
dw aka word is a 16 bit unsigned integer, values 0 to 65535
db  aka byte is a 8 bit unsigned integer, values 0 to 255

sdword, sword, sbyte are signed versions able to contain negative or zero or postive values.
sdword -2147483648 to 0 to 2147483647
sword -32768 to 0 to 32767
sbyte -128 to 0 to 127

Dasar

dsouza123 thank you very much, very useful explanation ; )

Q1:

if i did:

SomeName dd 256                            
i declare an initialized var

and if i did
SomeName dd 256 dup(?)
i declare an uninitialized array   ,   right ?


Q2:

what does the "DUP" stands for ?

thank you ;)

hutch--

Dasar,

The "dup" operator stands for DUPLICATE and its useful for filling a .DATA section buffer with a repeat character and it works on different data sizes.


.data
  buffer db 128 dup (0)  ; 128 zero filled bytes

.data
  wbuffer dw 128 dup (?)  ; 128 WORD (2 byte) uninitialised. 256 bytes
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Dasar

hutch-- thank you our Administrator ^_^