### Author Topic: Jumping into an END IF Block  (Read 2778 times)

0 Members and 1 Guest are viewing this topic.

#### Theo Gottwald

• Administrator
• Hero Member
• Posts: 935
• User-Rate: +30/-4
##### Jumping into an END IF Block
« on: October 08, 2010, 10:55:57 AM »
I have just found myself to code a MACRO like this:

Code: [Select]
`REGISTER R01 as LONGMACRO AGS_SP(P1,P2,P3)Macrotemp Labx if ismissing(P1) then goto Labx S03=Trim\$(P1):R01=Len(S03) if (R01>0) then R01=T06.SB SetBit(R01,P2) T06.P3=S03 T06.SB=R01 else Labx: R01=T06.SB              ClearBit(R01,P2) T06.SB=R01 T06.P3="" end ifEND MACRO `
I could have done it in another way, less optimized.

but this way seems completely "legal" to me, as in PB, the "END IF" in the resulting compiled ASM Code is just an adress. Means there is nothing why not to jump into an END IF Block.

Just wanted share this with you. Anybody else also done this?

#### Charles Pegge

• Global Moderator
• Hero Member
• Posts: 678
• User-Rate: +27/-1
##### Re: Jumping into an END IF Block
« Reply #1 on: October 08, 2010, 03:42:10 PM »
Hi Theo,

I do that sometimes as well.

One solution is to use another goto

I find that this arrangement makes the code a little easier to maintain and clarifies the logic. Essentially what you have is an inline function called Labx and you mark its end boundary with nLabx. In future this might evolve into a conventional out-of-line function, and the required code transform would be simpler.

Code: [Select]
`MACRO AGS_SP(P1,P2,P3)Macrotemp Labx if ismissing(P1) then goto Labx S03=Trim\$(P1):R01=Len(S03) ' if (R01>0) then R01=T06.SB SetBit(R01,P2) T06.P3=S03 T06.SB=R01        goto nLabx end if ' Labx: R01=T06.SB              ClearBit(R01,P2) T06.SB=R01 T06.P3="" nLabx: 'END MACRO`
« Last Edit: October 08, 2010, 04:01:09 PM by Charles Pegge »

#### Theo Gottwald

• Administrator
• Hero Member
• Posts: 935
• User-Rate: +30/-4
##### Re: Jumping into an END IF Block
« Reply #2 on: October 09, 2010, 09:29:11 AM »
Thats a good Point, Charles.
Another GOTO would also solve the Problem.
While internally, after compile,
both versions will be all the same, because this is just what the ELSE will be compiled to, a Jump.