Author Topic: @while/@break/@endw for ML64 (and friends)  (Read 417 times)

HSE

  • Member
  • *****
  • Posts: 2361
  • AMD 7-32 / i3 10-64
@while/@break/@endw for ML64 (and friends)
« on: October 13, 2022, 10:49:27 AM »
Hi all!

A very simple transformation of @if/@else, etc apparently is working well.

Code: [Select]
    mov rax, 5
    mov value1, rax
    @while rax gt 0
        conout str$(rax),lf
        mov rax, value1
        sub rax, 1
        mov value1, rax
    @endw

    conout "--------------",lf

    mov rax, 0
    mov value1, rax
    @while rax le 7
        conout str$(rax),lf
        mov rax, value1
        add rax, 1
        mov value1, rax
    @endw


To work with floating point numbers, macros requiere SmplMath. The examples attached are very simple and don't need that.

Most tests are needed, could be interesting to know failures.

Thanks in advance, HSE.

updates:

     October 13, 2022, 10:49:27 AM -- flow.zip (7.62 kB - downloaded 3 times.)
                                                 --  missing a critical piece
     October 14, 2022, 04:07:08 AM -- flow1.zip (7.85 kB - downloaded 19 times.)
                                                 --  added @break and nesting capacity
« Last Edit: January 01, 2023, 02:57:08 AM by HSE »
Equations in Assembly: SmplMath

Biterider

  • Member
  • *****
  • Posts: 1076
  • ObjAsm Developer
    • ObjAsm
Re: @while/@endw for ML64 (and friends)
« Reply #1 on: October 13, 2022, 06:18:29 PM »
Hi HSE
Examples run fine here.
It is a good thing you added the 64bit code path  :thumbsup:

Will you add this code to one of your GitHub projects?

Biterider

HSE

  • Member
  • *****
  • Posts: 2361
  • AMD 7-32 / i3 10-64
Re: @while/@endw for ML64 (and friends)
« Reply #2 on: October 13, 2022, 11:14:22 PM »
Hi Biterider

Will you add this code to one of your GitHub projects?

Yes. But compiled .while/.endw have one less instruction using the negation. First I have to see if that is not so complex adapting Mabdelouahab's macros. Perhaps don't worth the effort, I don't know.

HSE
Equations in Assembly: SmplMath

HSE

  • Member
  • *****
  • Posts: 2361
  • AMD 7-32 / i3 10-64
Re: @while/@endw for ML64 (and friends)
« Reply #3 on: October 14, 2022, 04:14:14 AM »
Was working, but a piece was missing :biggrin:

Now with some combined conditions:
Code: [Select]
    mov eax, 6
    mov v1, eax
    @while eax ua 0 && ebx ua 3
        print str$(eax), 13, 10
        mov eax, v1
        sub eax, 1
        mov v1, eax
    @endw
    print " @while/@endw finished",13,10,13,10


Updated in first post.
Equations in Assembly: SmplMath

HSE

  • Member
  • *****
  • Posts: 2361
  • AMD 7-32 / i3 10-64
Re: @while/@break/@endw for ML64 (and friends)
« Reply #4 on: January 01, 2023, 03:19:04 AM »
Hi all!

While expecting New Year  :biggrin:

- Added @break macro:
Code: [Select]
    @while eax gt 0
        print str$(eax),13,10
        .if v1 >= 10
            @break
        .endif
       
        mov eax, v1
        add eax, 1
        mov v1, eax
    @endw

- Added nesting capacity (see complete examples in files):
Code: [Select]
    @while eax gt 0
        ···
        @while ecx lt 6
            ···
        @endw
        .if v1 >= 10
            @break
        .endif
        ···
    @endw
       

    "break" have default level 0. That means break cut current cycle.  Inside nesting cycles, using "break levels", break cut current cycle and levels previous cycles.

Code: [Select]
    @while eax gt 0
        ···
        @while ecx lt 6
            .if v1 >= 7 && v2 > 3
                @break 1
            .endif
            ···
        @endw
        .if v1 >= 10
             @break
        .endif
         ···
    @endw

Updates in first post.

Thanks for testings, HSE.
Equations in Assembly: SmplMath