The MASM Forum

General => The Campus => Topic started by: sunshine33 on April 10, 2018, 11:56:49 PM

Title: Why does different Assemblers have different synatax's ?
Post by: sunshine33 on April 10, 2018, 11:56:49 PM
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 ?



Title: Re: Why does different Assemblers have different synatax's ?
Post by: hutch-- on April 11, 2018, 12:10:04 AM
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.
Title: Re: Why does different Assemblers have different synatax's ?
Post by: jj2007 on April 11, 2018, 12:14:34 AM
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 (http://www.terraspace.co.uk/uasm.html).
Title: Re: Why does different Assemblers have different synatax's ?
Post by: hutch-- on April 11, 2018, 01:30:46 AM
You can get a current version of ML.EXE from Microsoft.
Title: Re: Why does different Assemblers have different synatax's ?
Post by: sunshine33 on April 11, 2018, 04:30:11 AM
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

Title: Re: Why does different Assemblers have different synatax's ?
Post by: Vortex on April 11, 2018, 04:56:17 AM
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.
Title: Re: Why does different Assemblers have different synatax's ?
Post by: avcaballero 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:

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'
Title: Re: Why does different Assemblers have different synatax's ?
Post by: zedd151 on April 11, 2018, 08:23:10 AM
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)
Title: Re: Why does different Assemblers have different synatax's ?
Post by: jj2007 on April 11, 2018, 01:02:11 PM
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.
Title: Re: Why does different Assemblers have different synatax's ?
Post by: Lonewolff on April 11, 2018, 03:42:44 PM
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:
Title: Re: Why does different Assemblers have different synatax's ?
Post by: avcaballero on April 11, 2018, 06:37:03 PM
@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'
Title: Re: Why does different Assemblers have different synatax's ?
Post by: hutch-- on April 11, 2018, 07:24:08 PM
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.
Title: Re: Why does different Assemblers have different synatax's ?
Post by: jj2007 on April 11, 2018, 07:44:54 PM
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
Title: Re: Why does different Assemblers have different synatax's ?
Post by: 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 .
Title: Re: Why does different Assemblers have different synatax's ?
Post by: zedd151 on April 12, 2018, 12:52:03 AM
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:
Title: Re: Why does different Assemblers have different synatax's ?
Post by: felipe on April 12, 2018, 09:33:25 AM
Quote from: zedd151 on April 12, 2018, 12:52:03 AM

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

other code  here

pop esp
pop the registers previously pushed
---------
:biggrin: Let me correct that:

push   ebp
mov    ebp,esp
...
mov    esp,ebp
pop    ebp
Title: Re: Why does different Assemblers have different synatax's ?
Post by: zedd151 on April 12, 2018, 10:01:05 AM
yup what he said.

Been away from my computer too long. lol

will fix my previous post :lol:

See, I can write buggy code even without my computer and masm32.  :P

edit to add:

[note to self]
I really shouldnt try to post examples without the necessary tools at hand. :lol:
[/note to self]
Title: Re: Why does different Assemblers have different synatax's ?
Post by: jj2007 on April 12, 2018, 05:31:27 PM
Quote from: zedd151 on April 12, 2018, 10:01:05 AM
See, I can write buggy code even without my computer and masm32.  :P

Your code isn't buggy, it works perfectly:include \masm32\include\masm32rt.inc

.code
callme:
  push esi
  push esp
  mov ebp, esp
  print "hello world"
  pop esp
  pop esi
  retn

start:
  call callme
  print ", how are you?"
  exit

end start
Title: Re: Why does different Assemblers have different synatax's ?
Post by: sunshine33 on April 13, 2018, 03:38:33 AM
Hello zedd151

I have been collecting notes and i have been staring into example for some time now .

(https://s7.postimg.cc/rf5mgaexl/basics.png)

I have some experience with coding a dynamic website in Html , Javascript , Php and Mysql

After staring into Assembly language  , the other languages doesn't look much difficult .

But i have a very hard time understanding the if else like statements in Assembly language .

I seriously wish we had a section to talk about Assembly language somewhere in this forum.
Title: Re: Why does different Assemblers have different synatax's ?
Post by: felipe on April 13, 2018, 04:31:22 AM
Quote from: sunshine33 on April 13, 2018, 03:38:33 AM
I seriously wish we had a section to talk about Assembly language somewhere in this forum.
:shock:
Search harder, but don't expect things in some silver plate  :icon_exclaim:.
Title: Re: Why does different Assemblers have different synatax's ?
Post by: sunshine33 on April 13, 2018, 04:36:55 AM
Is this the section where i can ask the basic Assembly Language related questions ?


http://masm32.com/board/index.php?board=5.0 (http://masm32.com/board/index.php?board=5.0)
Title: Re: Why does different Assemblers have different synatax's ?
Post by: RuiLoureiro on April 13, 2018, 05:10:28 AM
 :biggrin: 
Hi Jochen,
               As you know, it is not a good idea to modify ebp inside a procedure without preserving it first...  ;)
Title: Re: Why does different Assemblers have different synatax's ?
Post by: felipe on April 13, 2018, 05:54:51 AM
Quote from: sunshine33 on April 13, 2018, 04:36:55 AM
Is this the section where i can ask the basic Assembly Language related questions ?
http://masm32.com/board/index.php?board=5.0 (http://masm32.com/board/index.php?board=5.0)

QuoteThe Campus: A protected forum where programmers learning assembler can ask questions in a sensible and safe atmosphere without being harassed or insulted. This is also targetted at experienced programmers from other languages learning assembler that don't want to be treated like kids. Note that 16 bit code or questions will be moved to the 16 bit forum.
Title: Re: Why does different Assemblers have different synatax's ?
Post by: zedd151 on April 13, 2018, 06:33:12 AM
Quote from: sunshine33 on April 13, 2018, 04:36:55 AM
Is this the section where i can ask the basic Assembly Language related questions ?


Usually new members asking for asm help post here in The Campus, where this thread is located.

Got a specific topic? Start a new thread.

I'm at work right now, gotta gooooo.....
Title: Re: Why does different Assemblers have different synatax's ?
Post by: sunshine33 on April 13, 2018, 06:58:12 AM
Thanks a lot everyone .
Title: Re: Why does different Assemblers have different synatax's ?
Post by: zedd151 on April 13, 2018, 07:00:12 AM
check your messages
Title: Re: Why does different Assemblers have different synatax's ?
Post by: sunshine33 on April 13, 2018, 07:06:01 AM
Yes i got it , replied   :biggrin:
Title: Re: Why does different Assemblers have different synatax's ?
Post by: jj2007 on April 13, 2018, 09:45:46 AM
Quote from: RuiLoureiro on April 13, 2018, 05:10:28 AMAs you know, it is not a good idea to modify ebp inside a procedure without preserving it first...  ;)

You are right, Lui - especially since this is The Campus ;)
Title: Re: Why does different Assemblers have different synatax's ?
Post by: RuiLoureiro on April 14, 2018, 07:51:13 AM
Exactly for that Jochen  ;)
Title: Re: Why does different Assemblers have different synatax's ?
Post by: hutch-- on April 14, 2018, 10:00:48 AM
Hi Sunshine,

The Campus is where you ask question of the type you are asking and that is why its here. Don't be afraid to ask questions in here, we all started somewhere and much of the reason why the older guys try and help out when they have the time is they often learnt assembler the hard way long ago.

Now note that the image you posted is dealing with old 16 bit assembler and that architecture is no longer useful in either 32 or 64 bit code. The 16 bit code uses a complicated segment / offset addressing mode due to hardware limitations of computers of that era where 32 and 64 bit code uses a much simpler and cleaner addressing mode that is called FLAT memory model, code and data in the same segment that only uses an OFFSET.
Title: Re: Why does different Assemblers have different synatax's ?
Post by: sunshine33 on April 15, 2018, 01:32:41 AM
hutch--

Thanks a lot for the reply .