Author Topic: .for, .endfor MACROS  (Read 19132 times)

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: .for, .endfor MACROS
« Reply #15 on: June 11, 2012, 09:10:47 PM »
Mea culpa, huch :icon_mrgreen:
I was in hurry and still my mind was in the .for macro
however, it looks much better when in brackets, you have to admit that
So, what is actually that you are concerned with in that example?
Cod-Father

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: .for, .endfor MACROS
« Reply #16 on: June 11, 2012, 09:53:14 PM »
dedndave,
>i prefer to write code "old style"
I appreciate your opinion
however, sometimes readability of program is more important then speed
ml64 is out of game because of the "old style"

best regards
 
Cod-Father

jj2007

  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
Re: .for, .endfor MACROS
« Reply #17 on: June 11, 2012, 10:08:03 PM »
however, it looks much better when in brackets, you have to admit that

There is room for improvement then:
Code: [Select]
.if eax
nop
.endif

can become
Code: [Select]
.if (eax!=NULL);
;{
nop;
;}
.endif
;)

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: .for, .endfor MACROS
« Reply #18 on: June 11, 2012, 10:28:04 PM »
 :eusa_clap: jj2007, I like your cinizam
I take it as a great sense of humor
that is a masterpiece jock,  I see it first time in my life
you should publish it somewhere

BTW
I used to write in BSIC while using commodore 64 but just to transfer machine code to assembler or opposite
I like C more than BASIC but my favorite is ASM, nothing can compensate for it
Cod-Father

qWord

  • Member
  • *****
  • Posts: 1471
  • The base type of a type is the type itself
    • SmplMath macros
Re: .for, .endfor MACROS
« Reply #19 on: June 11, 2012, 10:46:55 PM »
For-loops are fine and I’ve also had the idea to create such a macro, but finial I end up that the resulting syntax doesn't look as nice as in C. Currently I can only see a change if it is directly implemented in the assembler:  jWasm.
For your macros, I see the problem of the used none-ASCII-characters (<<,>>), which are only visible, if the editor use the correct code page.
MREAL macros - when you need floating point arithmetic while assembling!

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: .for, .endfor MACROS
« Reply #20 on: June 11, 2012, 10:59:24 PM »
qWord, in this case you can use LT, GT, EQ, LE, NE, GE

>directly implemented in the assembler:  jWasm.

I have worked on it and already build the skeleton of it
but I did not have enough time to study the code necessary to translate operators into code

now I am planing to look at it
Cod-Father

jj2007

  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
Re: .for, .endfor MACROS
« Reply #21 on: June 12, 2012, 01:03:00 AM »
I used to write in BASIC while using commodore 64 but just to transfer machine code to assembler or opposite
I like C more than BASIC but my favorite is ASM, nothing can compensate for it

I see we are on the same wavelength :biggrin:
My "coding career" was always a mix of Basic (i.e. Gfa on the Atari ST - almost a Pascal dialect) and assembler (68k, later x86). So I am probably just too old for C - and anyway, in Olly they look remarkably similar ;-)

Excuse my ignorance: What is the syntax for an extra simple loop as shown below?
include \masm32\MasmBasic\MasmBasic.inc   ; download
   Init
   PrintLine "MasmBasic For...Next loop:"
   mov eax, 5
   For_ ecx=0 To eax-1
      Print Str$("ecx=%i ", ecx)
   Next

   PrintLine CrLf$, "Now Habran's macro:"
   ; .FOR (
   Inkey "ok"
   Exit
end start

Output:
MasmBasic For...Next loop:
ecx=0 ecx=1 ecx=2 ecx=3 ecx=4
Now Habran's macro:
ok


P.S.: Any news from JWasm? 2.07 pre is fine for most purposes but there are minor quirks to fix...

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: .for, .endfor MACROS
« Reply #22 on: June 12, 2012, 07:18:24 AM »
jj2007
wavelength? you mean we remember things happened deep in the last millennium?
no mobile, no internet, no computer no nothing except having sex 28 hour a day!!! 8)

try this because I did not try it:
Code: [Select]
Init
   PrintLine "MasmBasic For...Next loop:"
   .for (eax=5,ecx=0:SDWORD PTR eax GE 0:eax--)
      Print Str$("ecx=%i ", ecx)
      PrintLine CrLf$, "Now Habran's macro:"
      ; .FOR (
      Inkey "ok"
   .endfor
   Exit
end start

best regards neighbor

P.S.: "0" (JWasm news)
 
« Last Edit: June 12, 2012, 02:50:22 PM by habran »
Cod-Father

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4933
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: .for, .endfor MACROS
« Reply #23 on: June 12, 2012, 10:36:38 AM »
There is nothing wrong with the analog world, it keeps running when the digital world's batteries go flat.  :biggrin:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

dedndave

  • Member
  • *****
  • Posts: 8751
  • Still using Abacus 2.0
    • DednDave
Re: .for, .endfor MACROS
« Reply #24 on: June 12, 2012, 01:01:25 PM »
shouldn't ".endfor" be ".next"   :lol:

jj2007

  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
Re: .for, .endfor MACROS
« Reply #25 on: June 12, 2012, 01:17:47 PM »
wavelength? you mean we remember things happened deep in the last millennium?
no mobile, no internet, no computer no nothing except having sex 28 hour a day!!! 8)

Hutch, alarm!! We have a Martian on board - earthlings had only 24 hours available for this ;-)

Tried your code but no luck, it throws lots of error messages, see attachment...

include \masm32\MasmBasic\MasmBasic.inc   ; download
include FOR_M.inc   ; slightly modified
   Init

   PrintLine "MasmBasic For...Next loop:"
   mov eax, 5
   For_ ecx=0 To eax-1
      Print Str$("ecx=%i ", ecx)
   Next

   PrintLine CrLf$, "Now Habran's macro:"
   .for (eax=5:ecx=0:SDWORD PTR eax GE 0:eax--)
      nop
   .endfor   

   Inkey "ok"
   Exit
end start

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: .for, .endfor MACROS
« Reply #26 on: June 12, 2012, 02:58:14 PM »
jj2007
sorry it was supposed to be with comma not with column

like this: .for (eax=5,ecx=0:SDWORD PTR eax GE 0:eax--)

and I am not from Mars, I am your neighbor fro former Yugoslavia
but I am already 20 years in South Australia
Cod-Father

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: .for, .endfor MACROS
« Reply #27 on: June 12, 2012, 03:00:13 PM »
 :biggrin: Yeah hutch: analog sex 8)
Cod-Father

jj2007

  • Member
  • *****
  • Posts: 7756
  • Assembler is fun ;-)
    • MasmBasic
Re: .for, .endfor MACROS
« Reply #28 on: June 12, 2012, 03:42:05 PM »
jj2007
sorry it was supposed to be with comma not with column

like this: .for (eax=5,ecx=0:SDWORD PTR eax GE 0:eax--)

assembles fine now but doesn't do anything ::)
But I got it working in the end:

include \masm32\MasmBasic\MasmBasic.inc   ; download
include FOR_M.inc   ; slightly modified
   Init

   PrintLine "MasmBasic For...Next loop:"
   mov eax, 5
   For_ ecx=0 To eax-1
      Print Str$("ecx=%i ", ecx)
   Next

   PrintLine CrLf$, CrLf$, "Now Habran's macro: "
;   mov eax, 4
   .for (ecx=0 :SDWORD PTR ecx GE 4 : ecx++)
      Print Str$("ecx=%i ", ecx)
   .endfor   
   Inkey CrLf$, "ok"
   Exit
end start

Output:
MasmBasic For...Next loop:
ecx=0 ecx=1 ecx=2 ecx=3 ecx=4

Now Habran's macro:
ecx=0 ecx=1 ecx=2 ecx=3 ecx=4


Two minor issues:
   mov eax, 4
   .for (ecx=0 : SDWORD PTR ecx GE eax : ecx++)   ; reg32 instead of immediate: endless loop, eax gets trashed somewhere

   .for (ecx=0 : SDWORD PTR ecx GE 4 : ecx++)   ; blank before SDWORD: assembly hangs


Quote
and I am not from Mars, I am your neighbor fro former Yugoslavia
but I am already 20 years in South Australia

cosmically speaking, Mars is a close neighbour, too :biggrin:
by the way, if I remember well, even a century back that 24-hour activity was already digital ;)

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: .for, .endfor MACROS
« Reply #29 on: June 12, 2012, 05:10:39 PM »
jj2007

I will look at it tonigh :eusa_clap:

are you sure that we are from the same century? :lol:
Cod-Father