News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Why does different Assemblers have different synatax's ?

Started by sunshine33, April 10, 2018, 11:56:49 PM

Previous topic - Next topic

sunshine33

I know each processor has a different instruction set
But if you are aiming to Assemble some code for a 32 bit intel x86 processor .

What is my next issue ?
Choosing an OS like Linux or Windows ?

The OS you will target will have certainly its own OS services, both in terms of what services are available, and how they are invoked, so while for example x86 32 bit mode instructions are same both in windows and Linux, the service calls are completely different and simple examples like "hello world" in console are not compatible, but require completely different system calls

And different types of Assemblers have different syntax,s right ?

So , Why would one choose MASM32 Assembler above other Assemblers ?




hutch--

If a processor is x86 or x86/64 they will have basically the same instruction set. Later version generally have more instructions added and if you are using the exotic later stuff you must know if the processor has those instructions. This is generally not a problem with all but the very latest instructions, 265 and 512 bit instructions but as a learner, you will not be touching them for some time as there is much to learn. The most important stuff are the older integer instructions as they structure much of how the later stuff is written.

jj2007

Quote from: sunshine33 on April 10, 2018, 11:56:49 PMAnd different types of Assemblers have different syntax,s right ?

So , Why would one choose MASM32 Assembler above other Assemblers ?

The differences between Masm and other assemblers like Nasm or Fasm are not that big, because the producers of cpus (Intel & AMD) have standardised the x86/x64 instruction set. So mov eax, 123 is the same in Masm, Fasm, Nasm.

The "M" in Masm stands for Macro, and this is Masm's strong point. Try a print str$(ecx), " is ecx" in Fasm or Nasm...

Btw the Masm32 SDK comes with an old version (6.14) of Masm. You better get one of the Masm clones, e.g. UAsm.

hutch--

You can get a current version of ML.EXE from Microsoft.

sunshine33

Thanks for the replies
Currently i am looking for examples to practice with MASM32 .
Some of the examples in the example folder looks a bit too complicated .

Not sure what to try to code right now .

Anyway thanks


Vortex

QuoteSome of the examples in the example folder looks a bit too complicated .

Don't worry. Time and practice will help you to understand the examples. Probably everyone of us had similar impressions in the beginning.

avcaballero

Quote from: jj2007 on April 11, 2018, 12:14:34 AM
Try a print str$(ecx), " is ecx" in Fasm or Nasm...
fasm, surely it may be better done  :biggrin:

format PE GUI 4.0
entry start

; macros for `invoke`, `cinvoke`, ...
include 'win32ax.inc'

macro print num {
  cinvoke wsprintf, szbuffer, '%d', num
  mov     [szbuffer + eax], 0
  invoke  MessageBox, 0, szbuffer, 'result', MB_OK
}

; code section
section '.text' code readable writable executable
     ; text buffer for the number to display
     szbuffer  rb 64  ; 64 bytes

     ; program start
  start:

     mov     eax, 1234
     print   eax

     print   1645
     ; calling exit
     invoke  ExitProcess, 0

section '.idata' import readable writable
     library   kernel32, 'KERNEL32.DLL',\
               user32,   'USER32.DLL'

     include   'api\kernel32.inc'
     include   'api\user32.inc'

zedd151

Quote from: sunshine33 on April 11, 2018, 04:30:11 AM
Some of the examples in the example folder looks a bit too complicated .

Choose a very simple and basic example to start with..

You should find an example titled "minimum"

What that program does is simply display a message box, with title and message text of your choosing.

Aftet you press "OK" the program calls "ExitProcess" to close the program.


zedd   8)

jj2007

Quote from: caballero on April 11, 2018, 05:15:48 AM
Quote from: jj2007 on April 11, 2018, 12:14:34 AM
Try a print str$(ecx), " is ecx" in Fasm or Nasm...
fasm, surely it may be better done  :biggrin:
...
     mov     eax, 1234
     print   eax

You note the subtle difference? Your print can display only numbers. Masm32 prints whatever pointer is passed to it, but that's not the point here: It's the pointer returned by str$(...). Fasm macros cannot return a pointer.

Lonewolff

Quote from: Vortex on April 11, 2018, 04:56:17 AM
Don't worry. Time and practice will help you to understand the examples. Probably everyone of us had similar impressions in the beginning.

Just a few days ago for me  :biggrin:

avcaballero

@JJ
What do you mean with "returning a pointer", give a value to eax? Why not?

format PE GUI 4.0
entry start

include 'win32ax.inc'

macro print tipo, que {
  if tipo eq "num"
    cinvoke wsprintf, szbuffer, '%d', que
    mov     dword [szbuffer + eax], 0
    invoke  MessageBox, 0, szbuffer, 'result', MB_OK
  else if tipo eq "str"
    invoke  MessageBox, 0, que, 'result', MB_OK
  end if
}

section '.text' code readable writable executable
     szbuffer  rb 64  ; 64 bytes
  start:
     mov     eax, 1234
     print   "num", eax
     print   "num", 1645
     print   "str", "hello, jj"

     invoke  ExitProcess, 0

section '.idata' import readable writable
     library   kernel32, 'KERNEL32.DLL',\
               user32,   'USER32.DLL'
     include   'api\kernel32.inc'
     include   'api\user32.inc'

hutch--

You will find that FASM and MASM are different animals pointed at different markets. While the pre-processor in MASM is a bad mannered old pig, it is also more powerful than the system in FASM. The Campus is not really the place for comparisons between different assemblers, for those who are familiar with either, they can get the results they want and have no reason to be concerned about other tools.

FASM has its own forum and MASM has its own forum, this is not an item of competition.

jj2007

include \masm32\include\masm32rt.inc ; plain Masm32 for the fans of pure assembler

FileExists MACRO fname
  invoke exist, reparg(fname)
  EXITM <eax>                        ; <<<<<<<<<<<<<< THIS MACRO RETURNS SOMETHING
ENDM

.code
start:
.if FileExists("\Masm32\include\Windows.inc")
print "WinInc exists", 13, 10
.else
print "WinInc does not exist", 13, 10
.endif
.if FileExists("\Masm32\include\Windoze.inc")
inkey "WinDoze.inc exists"
.else
inkey "WinDoze.inc does not exist"
.endif
exit
end start

sunshine33

Thanks a lot for all the replies .
I really love to start somewhere ,Just like everything else it is going to take time i guess ...
I will make this learning assembly language my life long goal .

zedd151

Quote from: sunshine33 on April 11, 2018, 10:51:15 PM
Thanks a lot for all the replies .
I really love to start somewhere ,Just like everything else it is going to take time i guess ...
I will make this learning assembly language my life long goal .

Once you start understanding how and why certain things are done the way they are in asm, the easier everything else becomes.

for instance:

-------------
push some registers (edi, esi, for example)
push ebp
mov ebp, esp

other code  here

mov esp, ebp
pop ebp
pop the registers previously pushed

---------

What that does is sets up a 'stack frame', and preserves the values in edi and esi.

The stack frame becomes invaluable for creating and using local variables. (via ebp) As well as preserving any registers value to what it was before the stack frame was generated. Dont have much time for more now gotta go back to work. :shock: