Author Topic: EasyCode with NASM/YASM  (Read 21340 times)

David BS

  • Regular Member
  • *
  • Posts: 30
EasyCode with NASM/YASM
« on: July 11, 2014, 01:46:56 PM »
Hi folks,

I had utilized EasyCode with MASM32 successfully - the IDE is really great! Congratulations Ramon!

I would like to know if there is some way to put YASM/NASM within EasyCode. I would like to compile some INTEL source codes (built to YASM/NASM) and adapt them to DLL (they're almost all built to console mode).

If it's not possible, could you recommend any other IDE to work with YASM/NASM, or, any tool to convert source code from NASM to MASM?

Thanks in advance!


jj2007

  • Member
  • *****
  • Posts: 8774
  • Assembler is fun ;-)
    • MasmBasic
Re: EasyCode with NASM/YASM
« Reply #1 on: July 11, 2014, 04:20:07 PM »
any tool to convert source code from NASM to MASM?

The NASM example here is hilariously complicated, but it looks feasible. If you can post a source with, say, 500 lines, I could give it a try with RosAsm2Masm.

sinsi

  • Member
  • *****
  • Posts: 1072
Re: EasyCode with NASM/YASM
« Reply #2 on: July 11, 2014, 04:35:26 PM »
The NASM example here is hilariously complicated, but it looks feasible.

I weep for the future of ASM
Code: [Select]
        sub     esp, 4          ; Allocate space on the stack for one 4 byte parameter
 
        lea     eax, [fmtStr]
        mov     [esp], eax      ; Arg1: pointer to format string
Pretty sure that nasm has a push instruction...
I can walk on water but stagger on beer.

jj2007

  • Member
  • *****
  • Posts: 8774
  • Assembler is fun ;-)
    • MasmBasic
Re: EasyCode with NASM/YASM
« Reply #3 on: July 11, 2014, 05:26:56 PM »
I weep for the future of ASM

Just in case the noobs who are reading this don't understand why we are whining here:

include \masm32\include\masm32rt.inc
 
.data
        fmtStr  db 'hello, world',0Ah,0
 
.code
main:
  if 0            ; MASM syntax, "pure" assembler, 14 bytes
      push offset fmtStr
      call crt_printf
      add esp, 4

  elseif 0            ; MASM syntax using invoke, 14 bytes
      invoke crt_printf, chr$("hello, world", 10)

  elseif 1            ; MASM syntax using a macro, 14 bytes
      printf("hello, world\n")

  else            ; NASM example, 21 bytes
        sub     esp, 4          ; Allocate space on the stack for one 4 byte parameter
        lea     eax, [fmtStr]
        mov     [esp], eax      ; Arg1: pointer to format string
        call    crt_printf         ; Call printf(3):
        add     esp, 4          ; Pop stack once

  endif
        ret
end main


BTW the 50% increase in code size is not the fault of NASM but rather of the Wiki author :(

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: EasyCode with NASM/YASM
« Reply #4 on: July 11, 2014, 08:10:22 PM »
Code: [Select]
        sub        esp, 4

should be replaced by
Code: [Select]
        sub        esp, byte 4
It's shorter and faster. Works with NASM as well as with YASM.

Gunther
Get your facts first, and then you can distort them.

jj2007

  • Member
  • *****
  • Posts: 8774
  • Assembler is fun ;-)
    • MasmBasic
Re: EasyCode with NASM/YASM
« Reply #5 on: July 11, 2014, 08:25:50 PM »
With MASM syntax for the NASM example, sub esp, 4 uses already the short 3-byte encoding.

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: EasyCode with NASM/YASM
« Reply #6 on: July 11, 2014, 08:53:09 PM »
Jochen,

my point was the original code from your link.

Gunther
Get your facts first, and then you can distort them.

dedndave

  • Member
  • *****
  • Posts: 8808
  • Still using Abacus 2.0
    • DednDave
Re: EasyCode with NASM/YASM
« Reply #7 on: July 12, 2014, 12:31:46 AM »
i've seen things like that in compiled code
i suppose, under the right circumstances, it might be justified
for example, you have several larger arguments to pass

so - the SUB ESP,x construct is a "cookie-cutter" template for more complex calls
they calculate the total space required for parameters - then fill it in
one that i saw was for COM - there were a few VARIANT structures passed

the problem i see there is crashability - lol
if you are near the stack limit - SUB ESP,x will get you a silent termination   :redface:

rsala

  • Moderator
  • Member
  • *****
  • Posts: 273
    • Easy Code
Re: EasyCode with NASM/YASM
« Reply #8 on: July 12, 2014, 02:36:32 AM »
Hi David BS,

Thanks for your kind words about Easy Code!

Although the IDE is prepared for working with Masm and/or GoAsm, I guess you could use Nasm/Yasm if you disabled all syntax correction and set the compiler path to the folder where Nasm/Yasm is.

Regards,

Ramon
EC coder

David BS

  • Regular Member
  • *
  • Posts: 30
Re: EasyCode with NASM/YASM
« Reply #9 on: July 12, 2014, 01:08:17 PM »
Although the IDE is prepared for working with Masm and/or GoAsm, I guess you could use Nasm/Yasm if you disabled all syntax correction and set the compiler path to the folder where Nasm/Yasm is.

Hmmm.... I understood everything you wrote guys. Thanks.

But my doubt was really about what Ramon answered: if I could put EasyCode to compile code using Yasm AND having syntax correction and some built-in macros. Of course I would like to get that usefull help...

Thank you Ramon. And congrats for the very nice job.

I really don't know what I'm going to do now: if I'll try to translate INTEL's YASM code to MASM (and have EasyCode working and making easier my life) or try anything else. 

One question: is not clear to me in YASM syntax if I have to define the DLLMain routine/header to build a DLL file - as I do in MASM syntax. It's not clear if it is performed just by the compiler and its parameters or if in addition I must define it is a DLL within the code.  Anyone can help me in that question?

Thanks again to all.
Regards.

jj2007

  • Member
  • *****
  • Posts: 8774
  • Assembler is fun ;-)
    • MasmBasic
Re: EasyCode with NASM/YASM
« Reply #10 on: July 12, 2014, 05:41:41 PM »
if I'll try to translate INTEL's YASM code to MASM (and have EasyCode working and making easier my life) or try anything else.
That is really your decision. Writing a converter is easy, but are you more hooked on YASM, or are you equally comfortable with MASM syntax?

If you can post a source with, say, 500 lines, I could give it a try with RosAsm2Masm.

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: EasyCode with NASM/YASM
« Reply #11 on: July 13, 2014, 08:12:53 PM »
Hi Jochen,

if I'll try to translate INTEL's YASM code to MASM (and have EasyCode working and making easier my life) or try anything else.
That is really your decision. Writing a converter is easy, but are you more hooked on YASM, or are you equally comfortable with MASM syntax?

YASM and MASM syntax are not so far apart. That's a fact. AT&T syntax is another world. There's no doubt about that.

Gunther
Get your facts first, and then you can distort them.

rsala

  • Moderator
  • Member
  • *****
  • Posts: 273
    • Easy Code
Re: EasyCode with NASM/YASM
« Reply #12 on: July 13, 2014, 11:48:45 PM »
Hi,

I am afraid I was to optimistic in my first answer. Easy Code, both Masm and GoAsm, internally write some compiler options, so it might not work with Nasm/Yasm. I think the best you can do (not just for using Easy Code, but for making things simple) is trying to translate the code to Masm or GoAsm syntax.

Regards,

Ramon
EC coder

David BS

  • Regular Member
  • *
  • Posts: 30
Re: EasyCode with NASM/YASM
« Reply #13 on: July 15, 2014, 03:15:21 AM »
 :dazzled:

Thanks you all for the answers.

I feel confortable with MASM and, since I'm a Visual Studio programmer, I suppose I can utilize the internal source code debugger to step-by-step my ASM sources during the debug session (for instance, to see if the Visual Basic call and parameters are being correctly sent/received and so forth). I'm not sure if with YASM I have the same environment.

EasyCode really makes the job easier, since it has a lot of functions/macros to help us. So, the union between MASM and EasyCode is preferable to me.

BUT, unfortunetly, all INTEL source codes are made to be YASM/NASM compiled and I believe the most of them are to be linked with C or C++ (argh!  :icon13:). I hate C/C++ since the language is in my view the worst between two worlds: the High Level and Low Level languages.  I can make a whole system utilizing Visual Basic in just ONE DAY, what sould be impossible utilizing C++ or C.  The sources I send now here are being focused into .LIB files, which Visual Basic does not see!

For instance, one of my doubts is about how make a DLL file in YASM!  I cannot see any source example! May I have to define the DLLEntry point there or YASM/NASM will create it automatically?  And the EXPORT directive, must I define in within the code?  Should I have also to create .DEF files?

In MASM I know how to create them and make the MASM/LINK undertstand them to create a DLL file, but with these samples I'm not getting succes with YASM. Or it creates an EXE file or a LIB file - and none of them are my target.

Can anyone light my way?
Thank you very much.
Regards!

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: EasyCode with NASM/YASM
« Reply #14 on: July 15, 2014, 03:37:09 AM »
Hi David,

I hope that link will help you.

Gunther
Get your facts first, and then you can distort them.