The MASM Forum

Projects => Rarely Used Projects => Archival JWASM postings => Topic started by: habran on October 12, 2014, 06:27:37 AM

Title: Signed Flags
Post by: habran on October 12, 2014, 06:27:37 AM
Hi there,

I have added these signed flags to JWasm:
  SCARRY?           JGE    Sign flag = overflow flag               
  !SCARRY?            JL     Sign flag != overflow flag             
  SZERO?             JLE    Zero flag is set or sign != overflow   
  !SZERO?            JG     Zero flag is clear and sign = overflow 


I have encountered this C source:
Code: [Select]
  //Align to 16 pixel
  ptScale.x+=ptScale.x % 16;


it is compiled to this:
Code: [Select]
mov edx, DWORD PTR ptScale
mov ecx, edx
and ecx, -2147483633 ; ffffffff8000000fH
jge SHORT $LN10
dec ecx
or ecx, -16
inc ecx
$LN10:
add edx, ecx
  mov DWORD PTR ptScale, edx

we can write it like this:
Code: [Select]
  mov eax,ptScale.x                                   
and eax,8000000Fh
jge @F
dec eax               
or eax, -16                                 
inc eax
@@:
add ptScale.x, eax

assembled to:
Code: [Select]
  mov eax,ptScale.x                                   
000000013F8411C7 8B 84 24 90 00 00 00 mov         eax,dword ptr [ptScale] 
and eax,8000000Fh
000000013F8411CE 25 0F 00 00 80       and         eax,8000000Fh 
jge @F
000000013F8411D3 7D 07                jge         main+1Dh (013F8411DCh) 
dec eax               
000000013F8411D5 FF C8                dec         eax 
or eax, -16                                 
000000013F8411D7 83 C8 F0             or          eax,0FFFFFFF0h 
inc eax
000000013F8411DA FF C0                inc         eax 
@@:
add ptScale.x, eax
000000013F8411DC 01 84 24 90 00 00 00 add         dword ptr [ptScale],eax 
it would look better if we write it like this:
Code: [Select]
    mov eax,ptScale.x
    and eax, 8000000fH
    .if (SCARRY?)
      dec eax
      or eax, -16
      inc eax
    .endif
    add ptScale.x, eax
assembled to:
Code: [Select]
    mov eax,ptScale.x
000000013FCB11E3 8B 84 24 90 00 00 00 mov         eax,dword ptr [ptScale] 
    and eax, 8000000fH
000000013FCB11EA 25 0F 00 00 80       and         eax,8000000Fh 
    .if (SCARRY?)
000000013FCB11EF 7D 07                jge         main+39h (013FCB11F8h) 
      dec eax
000000013FCB11F1 FF C8                dec         eax 
      or eax, -16
000000013FCB11F3 83 C8 F0             or          eax,0FFFFFFF0h 
      inc eax
000000013FCB11F6 FF C0                inc         eax 
    .endif
    add ptScale.x, eax
000000013FCB11F8 01 84 24 90 00 00 00 add         dword ptr [ptScale],eax
your comments would be appreciated :biggrin:

if you agree about it I will post both 32bit and 64bit JWasm.exe here
Title: Re: Signed Flags
Post by: dedndave on October 12, 2014, 11:26:53 AM
these are the flag operators supported by MASM:
Code: [Select]
ZERO?
OVERFLOW?
SIGN?
CARRY?
PARITY?

these are the x86 conditional branch instructions (not including LOOPxx instructions):
Code: [Select]
------------------------------------------------------------------------
Group     Instruction  Description               Condition       Aliases
------------------------------------------------------------------------
Equality  JZ           Jump if equal             ZF=1            JE
          JNZ          Jump if not equal         ZF=0            JNE

Unsigned  JA           Jump if above             CF=0 and ZF=0   JNBE
          JAE          Jump if above or equal    CF=0            JNC JNB
          JB           Jump if below             CF=1            JC JNAE
          JBE          Jump if below or equal    CF=1 or ZF=1    JNA

Signed    JG           Jump if greater           SF=OF or ZF=0   JNLE
          JGE          Jump if greater or equal  SF=OF           JNL
          JL           Jump if less              SF<>OF          JNGE
          JLE          Jump if less or equal     SF<>OF or ZF=1  JNG
          JO           Jump if overflow          OF=1
          JNO          Jump if no overflow       OF=0
          JS           Jump if sign              SF=1
          JNS          Jump if no sign           SF=0

Parity    JP           Jump if parity            PF=1            JPE
          JNP          Jump if no parity         PF=0            JPO

it would be nice if the assembler "examined" combinations to see if code reduction is possible
for example, the source:
Code: [Select]
    .repeat
        add     eax,dwTestVar
    .until !CARRY? && !ZERO?
would generate the code:
Code: [Select]
@@:     add     eax,dwTestVar
        jbe     @B

a couple of advantages:
1) The programmer doesn't have to consciously check flag conditions against branch instructions.
   If the statement allows the use of the shorter form, substitution takes place automatically.
2) No change in current list of reserved keywords.
   No need for SCARRY? or SZERO? operators.
Title: Re: Signed Flags
Post by: habran on October 12, 2014, 02:20:58 PM
Hi Dave,
Thanks for replaying

check this code:
Code: [Select]
    mov eax,ptScale.x
000000013FCF11F1 8B 84 24 90 00 00 00 mov         eax,dword ptr [ptScale] 
    and eax, 8000000fH
000000013FCF11F8 25 0F 00 00 80       and         eax,8000000Fh 
    .if (CARRY? && SIGN?)
000000013FCF11FD 73 09                jae         main+49h (013FCF1208h) 
000000013FCF11FF 79 07                jns         main+49h (013FCF1208h) 
      dec eax
000000013FCF1201 FF C8                dec         eax 
      or eax, -16
000000013FCF1203 83 C8 F0             or          eax,0FFFFFFF0h 
      inc eax
000000013FCF1206 FF C0                inc         eax 
    .endif
    add ptScale.x, eax
000000013FCF1208 01 84 24 90 00 00 00 add         dword ptr [ptScale],eax
now compare it with the above one with SCARRY?
Title: Re: Signed Flags
Post by: dedndave on October 12, 2014, 03:04:05 PM
yah - there is no Jcc for (carry=0 AND sign=0)  :P

typically, carry is used for unsigned operations and sign is used for signed operations
Title: Re: Signed Flags
Post by: habran on October 12, 2014, 05:50:50 PM
So you now do agree with me that SCARRY? is actually not so SCARY  ;)
Title: Re: Signed Flags
Post by: ToutEnMasm on October 12, 2014, 06:34:02 PM
More sign are a good idea
Quote
ZERO?
OVERFLOW?
SIGN?
CARRY?
PARITY?
;-----------------------------------
SCARRY?           JGE    Sign flag = overflow flag               
  !SCARRY?            JL     Sign flag != overflow flag             
  SZERO?             JLE    Zero flag is set or sign != overflow   
  !SZERO?            JG     Zero flag is clear and sign = overflow 

Title: Re: Signed Flags
Post by: habran on October 12, 2014, 06:58:11 PM
ToutEnMasm MERCIE BEAUCOUP :t
Title: Re: Signed Flags
Post by: dedndave on October 13, 2014, 07:36:04 AM
Code: [Select]
;*****************************
; SIGNED OPERATIONS
;*****************************

;JG           Jump if greater           SF=OF or ZF=0
;JGE          Jump if greater or equal  SF=OF
;JL           Jump if less              SF<>OF
;JLE          Jump if less or equal     SF<>OF or ZF=1
;
;if this code were supported, then signed operations would be feasible:

;   .if SIGN?==OVERFLOW?        ;MASM generates error
;       nop
;   .endif

;the assembler would also need to code:
;"(SIGN?==OVERFLOW?) || (!ZERO?)" as a JG instruction
;and
;"(SIGN?!=OVERFLOW?) || (ZERO?)" as a JLE instruction

;other combinations form the inverted logic of the same instructions
;for instance, ".if xxx" performs code if xxx is true
;the inverse logic is used in ".until xxx", where the branch occurs if xxx is not true

Code: [Select]
;*****************************
; UNSIGNED OPERATIONS
;*****************************

;JA           Jump if above             CF=0 and ZF=0

    .if !CARRY? && !ZERO?
        nop
    .endif

;MASM assembles that code as:

        jb      label0
        jz      label0
        nop
label0:

;it would be nice if it was coded as:

        ja      label0
        nop
label0:

;-----------------------------

;JBE          Jump if below or equal    CF=1 or ZF=1

    .if CARRY? || ZERO?
        nop
    .endif

;MASM assembles that code as:

        jb      label1
        jnz     label2
label1: nop
label2:

;it would be nice if it was coded as:

        jbe     label1
        nop
label1:
Title: Re: Signed Flags
Post by: habran on October 13, 2014, 09:54:30 AM
This is written in MASM Programmer's Guide:

Instruction Jumps if
JC/JB/JNAE   Carry flag is set
JNC/JNB/JAE Carry flag is clear
JBE/JNA        Either carry or zero flag is set
JA/JNBE        Carry and zero flag are clear
JE/JZ            Zero flag is set
JNE/JNZ        Zero flag is clear
JL/JNGE        Sign flag != overflow flag
JGE/JNL        Sign flag = overflow flag
JLE/JNG        Zero flag is set or sign != overflow
JG/JNLE        Zero flag is clear and sign = overflow
JS                Sign flag is set
JNS              Sign flag is clear
JO                Overflow flag is set
JNO              Overflow flag is clear
JP/JPE           Parity flag is set (even parity)
JNP/JPO        Parity flag is clear (odd parity)

I can make this happen in JWasm:
ZRORCRY?      jbe
!ZRORCRY?     ja

and instead of  SZERO?   and !SZERO? :


SZRORCRY?      jle
!SZRORCRY?     jg

Title: Re: Signed Flags
Post by: habran on October 13, 2014, 10:16:49 AM
here you are:
Code: [Select]
    mov eax,ptScale.x
000000013FB211F1 8B 84 24 90 00 00 00 mov         eax,dword ptr [ptScale] 
    and eax, 8000000fH
000000013FB211F8 25 0F 00 00 80       and         eax,8000000Fh 
    .if (SZRORCRY? )
000000013FB211FD 7E 07                jle         main+47h (013FB21206h) 
      dec eax
000000013FB211FF FF C8                dec         eax 
      or eax, -16
000000013FB21201 83 C8 F0             or          eax,0FFFFFFF0h 
      inc eax
000000013FB21204 FF C0                inc         eax 
    .endif
    add ptScale.x, eax
000000013FB21206 01 84 24 90 00 00 00 add         dword ptr [ptScale],eax 

    mov ecx, eax
000000013FB2120D 8B C8                mov         ecx,eax 
    and ecx, 8000000fH
000000013FB2120F 81 E1 0F 00 00 80    and         ecx,8000000Fh 
    .if (!SZRORCRY? )
000000013FB21215 7F 07                jg          main+5Fh (013FB2121Eh) 
    dec ecx
000000013FB21217 FF C9                dec         ecx 
    or ecx, -16
000000013FB21219 83 C9 F0             or          ecx,0FFFFFFF0h 
    inc ecx
000000013FB2121C FF C1                inc         ecx 
    .endif
    add eax, ecx
000000013FB2121E 03 C1                add         eax,ecx 
    mov eax, 16
000000013FB21220 B8 10 00 00 00       mov         eax,10h 
    mov ecx, eax
000000013FB21225 8B C8                mov         ecx,eax 
    and ecx, 8000000fH
000000013FB21227 81 E1 0F 00 00 80    and         ecx,8000000Fh 
    .if (!ZRORCRY? )
000000013FB2122D 77 07                ja          main+77h (013FB21236h) 
    dec ecx
000000013FB2122F FF C9                dec         ecx 
    or ecx, -16
000000013FB21231 83 C9 F0             or          ecx,0FFFFFFF0h 
    inc ecx
000000013FB21234 FF C1                inc         ecx 
    .endif
    add eax, ecx
000000013FB21236 03 C1                add         eax,ecx 
   
    mov ecx, eax
000000013FB21238 8B C8                mov         ecx,eax 
    and ecx, 8000000fH
000000013FB2123A 81 E1 0F 00 00 80    and         ecx,8000000Fh 
    .if (ZRORCRY?)
000000013FB21240 76 07                jbe         main+8Ah (013FB21249h) 
    dec ecx
000000013FB21242 FF C9                dec         ecx 
    or ecx, -16
000000013FB21244 83 C9 F0             or          ecx,0FFFFFFF0h 
    inc ecx
000000013FB21247 FF C1                inc         ecx 
    .endif
    add eax, ecx
000000013FB21249 03 C1                add         eax,ecx 

Title: Re: Signed Flags
Post by: habran on October 13, 2014, 10:29:53 AM
if you can come with more clear notation I'll be happy to accept it
all I need is to have  JG, JGE, JL, JLE, JA, JBE  branches  without using CMP, TST, OR, AND
Title: Re: Signed Flags
Post by: dedndave on October 13, 2014, 10:43:20 AM
no - i see what you are trying to do - and it's good
there have been many times when i go back to the old branch label method to get what i want
sometimes because of the lack of Jcc support - sometimes due to complex branch construction

i can't state my case any clearer, i guess - lol
my thinking was that - one of the goals is to have JwAsm compatible with Masm
so - if i write a program for one, it should assemble with the other - minimal modification required
i don't know if that is really one of Andreas' primary goals or not
Title: Re: Signed Flags
Post by: habran on October 13, 2014, 01:08:12 PM
JWasm CAN do anything what MASM can do but MASM is just a little brother to grown up JWasm
Why would we need a backward compatibility? There would be no point to develop it
JWasm is flexible and getting better and better   

I can not go back to MASM it would be the same as trying to wear shoes from my childhood :bgrin:

I found somewhere on this forum that jj2007  also pointed out these missing flags

IMO we can not let C or C++ or any other HLL to be more capable than ASM
there would be no point to do programming in ASM
That is why, when ever I stumble on something missing or not good enough in JWasm I try to make it better
 (fortunately that source code is available)
 remember THE BEATLES Lyrics:"Take a sad song and make it better" :biggrin:
Title: Re: Signed Flags
Post by: habran on October 13, 2014, 02:07:09 PM
I can change SCARRY?  to SIGNEQUO? and !SCARRY? to !SIGNEQUO?
than we would have 6 new jumps:
Instruction Jumps if:
SIGNEQUO?     jge  Sign flag = overflow flag
!SIGNEQUO?    jl     Sign flag != overflow flag
SZRORCRY?     jle    Zero flag is set or sign != overflow
!SZRORCRY?    jg     Zero flag is clear and sign = overflow
ZERORCRY?     jbe    Either carry or zero flag is set
!ZERORCRY?    ja     Carry and zero flag are clear
Title: Re: Signed Flags
Post by: dedndave on October 13, 2014, 03:05:48 PM
the names you assign aren't critical - i would try to use something readable

Code: [Select]
Unsigned
JA           Jump if above             CF=0 and ZF=0
JBE          Jump if below or equal    CF=1 or ZF=1

Code: [Select]
Signed
JG           Jump if greater           SF=OF or ZF=0
JGE          Jump if greater or equal  SF=OF
JL           Jump if less              SF<>OF
JLE          Jump if less or equal     SF<>OF or ZF=1

for unsigned, ABOVE? should do the job
Code: [Select]
JA    !ABOVE?
JBE   ABOVE?

for signed, LESS? and GREATER?
Code: [Select]
JG    !GREATER?
JGE   LESS?
JL    !LESS?
JLE   GREATER?

notice that you branch if the case is false, so they seem backwards   :P
Code: [Select]
    .if A !GREATER? B
        ;do some code
    .endif
the branch is used to jump around the code, so a JG instruction is used in that case

GREATERTHAN and LESSTHAN would also be good choices

still, the info i posted in reply #7 is valid - i.e., both could be supported
go back and read that reply again - if it is not clear to you, i will try to make 6 code examples
Title: Re: Signed Flags
Post by: ToutEnMasm on October 13, 2014, 07:15:05 PM
I prefered  also name without abreviations.
I find !ZEROANDCARRY?  better than !ZERORCRY?
Pseudo code is also better in the explain.
NOT (ZERO AND CARRY)
.if !ZEROANDCARRY?
.......
Title: Re: Signed Flags
Post by: habran on October 13, 2014, 08:04:00 PM
Hey Dave, your suggestion is brilliant, it is simple and clear :t
I have to admit that I was also thinking about it but was not able to find proper words
Thank you :biggrin:
I will take it exactly as you suggested:
JGE   LESS?
JL    !LESS?   
JG    !GREATER?
JLE   GREATER?
JA    !ABOVE?
JBE   ABOVE?

Thanks ToutEnMasm for your involvement, I appreciate it :t
 
I'll be back!
Title: Re: Signed Flags
Post by: habran on October 13, 2014, 08:25:36 PM
done!
Code: [Select]
    mov eax, ptScale.x
000000013FC611F1 8B 84 24 90 00 00 00 mov         eax,dword ptr [ptScale] 
    and eax, 8000000fH
000000013FC611F8 25 0F 00 00 80       and         eax,8000000Fh 
    .if (LESS?)
000000013FC611FD 7D 07                jge         main+47h (013FC61206h) 
    dec eax
000000013FC611FF FF C8                dec         eax 
    or eax, -16
000000013FC61201 83 C8 F0             or          eax,0FFFFFFF0h 
    inc eax
000000013FC61204 FF C0                inc         eax 
    .endif
    add ptScale.x, eax
000000013FC61206 01 84 24 90 00 00 00 add         dword ptr [ptScale],eax 

    mov eax, ptScale.x
000000013FC6120D 8B 84 24 90 00 00 00 mov         eax,dword ptr [ptScale] 
    and eax, 8000000fH
000000013FC61214 25 0F 00 00 80       and         eax,8000000Fh 
    .if (!LESS?)
000000013FC61219 7C 07                jl          main+63h (013FC61222h) 
    dec eax
000000013FC6121B FF C8                dec         eax 
    or eax, -16
000000013FC6121D 83 C8 F0             or          eax,0FFFFFFF0h 
    inc eax
000000013FC61220 FF C0                inc         eax 
    .endif
    add ptScale.x, eax
000000013FC61222 01 84 24 90 00 00 00 add         dword ptr [ptScale],eax 

    mov eax,ptScale.x
000000013FC61229 8B 84 24 90 00 00 00 mov         eax,dword ptr [ptScale] 
    and eax, 8000000fH
000000013FC61230 25 0F 00 00 80       and         eax,8000000Fh 
    .if (GREATER? )
000000013FC61235 7E 07                jle         main+7Fh (013FC6123Eh) 
      dec eax
000000013FC61237 FF C8                dec         eax 
      or eax, -16
000000013FC61239 83 C8 F0             or          eax,0FFFFFFF0h 
      inc eax
000000013FC6123C FF C0                inc         eax 
    .endif
    add ptScale.x, eax
000000013FC6123E 01 84 24 90 00 00 00 add         dword ptr [ptScale],eax 

    mov ecx, eax
000000013FC61245 8B C8                mov         ecx,eax 
    and ecx, 8000000fH
000000013FC61247 81 E1 0F 00 00 80    and         ecx,8000000Fh 
    .if (!GREATER? )
000000013FC6124D 7F 07                jg          main+97h (013FC61256h) 
    dec ecx
000000013FC6124F FF C9                dec         ecx 
    or ecx, -16
000000013FC61251 83 C9 F0             or          ecx,0FFFFFFF0h 
    inc ecx
000000013FC61254 FF C1                inc         ecx 
    .endif
    add eax, ecx
000000013FC61256 03 C1                add         eax,ecx 

    mov eax, 16
000000013FC61258 B8 10 00 00 00       mov         eax,10h 
    mov ecx, eax
000000013FC6125D 8B C8                mov         ecx,eax 
    and ecx, 8000000fH
000000013FC6125F 81 E1 0F 00 00 80    and         ecx,8000000Fh 
    .if (ABOVE?)
000000013FC61265 76 07                jbe         main+0AFh (013FC6126Eh) 
    dec ecx
000000013FC61267 FF C9                dec         ecx 
    or ecx, -16
000000013FC61269 83 C9 F0             or          ecx,0FFFFFFF0h 
    inc ecx
000000013FC6126C FF C1                inc         ecx 
    .endif
    add eax, ecx
000000013FC6126E 03 C1                add         eax,ecx 
   
    mov ecx, eax
000000013FC61270 8B C8                mov         ecx,eax 
    and ecx, 8000000fH
000000013FC61272 81 E1 0F 00 00 80    and         ecx,8000000Fh 
    .if (!ABOVE?)
000000013FC61278 77 07                ja          main+0C2h (013FC61281h) 
    dec ecx
000000013FC6127A FF C9                dec         ecx 
    or ecx, -16
000000013FC6127C 83 C9 F0             or          ecx,0FFFFFFF0h 
    inc ecx
000000013FC6127F FF C1                inc         ecx 
    .endif
    add eax, ecx
000000013FC61281 03 C1                add         eax,ecx 

Title: Re: Signed Flags
Post by: dedndave on October 13, 2014, 09:08:12 PM
i guess some of those are not really necessary, come to think of it

Masm (and probably JwAsm) supports ">=", "<=", "<", and ">"
and, signed comparisons by using the SDWORD PTR specifier

later today, i'll play with some code to see what's missing
Title: Re: Signed Flags
Post by: habran on October 13, 2014, 09:15:16 PM
Hey Dave SDWORD doesn't work in these cases that's why I went through all this

here are binaries   
Title: Re: Signed Flags
Post by: nidud on October 13, 2014, 10:09:20 PM
Code: [Select]
.data
val sdword -1
.code
.if sdword ptr eax < 0
    inc eax
.endif
.if val < eax
    inc eax
.endif
        end

Code: [Select]
00000000                        .if sdword ptr eax < 0
00000000  83F800            *   cmp sdword ptr eax , 0
00000003  7D01              *   jnl @C0001
00000005  40                    inc eax
00000006                        .endif
00000006                    *   @C0001:
00000006                        .if val < eax
00000006  390500000000      *   cmp val , eax
0000000C  7D01              *   jnl @C0002
0000000E  40                    inc eax
0000000F                        .endif
0000000F                    *   @C0002:
Title: Re: Signed Flags
Post by: dedndave on October 13, 2014, 11:02:23 PM
right - that was before my first cup of coffee - lol
ignore that post   :P

we are talking about pre-existing flag conditions - not compares
Title: Re: Signed Flags
Post by: habran on October 13, 2014, 11:18:00 PM
Yes Dave, that is good wording pre-existing flag conditions
(reminds me on premature... something) ;)
your English is pretty good
Actually I am never sure if you Americans speak English or American
I know for sure that Australians speak Australian language because when I came here
they did not understand my 'English' (which we were taught in my school) :biggrin:
Title: Re: Signed Flags
Post by: dedndave on October 13, 2014, 11:25:25 PM
British English is pretty strange, too - lol
Title: Re: Signed Flags
Post by: habran on October 13, 2014, 11:30:13 PM
Certainly!
If you want to learn nice smooth English watch the SBS news (here in OZ)
Do you also have SBS news in US?
Title: Re: Signed Flags
Post by: ToutEnMasm on October 13, 2014, 11:34:23 PM

I had dowloaded the new JWASM
"JWASM isn't a valid WIN32 aplication"

Seems there is a problem ? (xp sp3)
 
Title: Re: Signed Flags
Post by: habran on October 13, 2014, 11:40:56 PM
I have Window 7
If you want I can post here hll.c
the rest of source you take from my last post
and than build it with your favorite program
Title: Re: Signed Flags
Post by: habran on October 13, 2014, 11:45:20 PM
here is hll.c
replace former with this one
Title: Re: Signed Flags
Post by: nidud on October 14, 2014, 12:01:53 AM
Code: [Select]
.ifa
.ifb
        .ife
.ifg
.ifl
...
.ifae
.ifbe
.ifge
.ifle
...
Title: Re: Signed Flags
Post by: habran on October 14, 2014, 06:00:42 AM
Hi nidud :biggrin:
which one looks better?
Code: [Select]
  .repeat 
    .if LESS?
      inc eax
    .endif
  .until  ABOVE?
 
  .repeat 
    .if .ifge
      inc eax
    .endif
  .until .ifa
Title: Re: Signed Flags
Post by: habran on October 14, 2014, 06:03:04 AM
ToutEnMasm have you succeeded to build JWasm on your machine?
Title: Re: Signed Flags
Post by: ToutEnMasm on October 14, 2014, 06:08:52 AM

That's a great question.I have a source code than I can compile with vc express 2010.
Question is :
Wich source code to download and wich file to add/modify ?
With an answer ,I can do it.
Title: Re: Signed Flags
Post by: nidud on October 14, 2014, 06:18:42 AM
:biggrin:

I'm testing..
directive.h:
Code: [Select]
/* hll directives */

res(DOT_IF,     .if, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)

#ifdef __IFFLAG
/*
*    JA   Jump if Above CF=0 and ZF=0
*    JNBE   Jump if Not Below or Equal CF=0 and ZF=0
*    JAE   Jump if Above or Equal CF=0
*    JNB   Jump if Not Below CF=0
*    JNC   Jump if Not Carry CF=0
*    JB   Jump if Below CF=1
*    JC   Jump if Carry CF=1
*    JNAE   Jump if Not Above or Equal CF=1
*    JBE   Jump if Below or Equal CF=1 or ZF=1
*    JNA   Jump if Not Above CF=1 or ZF=1
*    JE   Jump if Equal ZF=1
*    JZ   Jump if Zero ZF=1
*    JNE   Jump if Not Equal ZF=0
*    JNZ   Jump if Not Zero ZF=0
*    JG   Jump if Greater (signed) ZF=0 and SF=OF
*    JNLE   Jump if Not Less or Equal (signed) ZF=0 and SF=OF
*    JGE   Jump if Greater or Equal (signed) SF=OF
*    JNL   Jump if Not Less (signed) SF=OF
*    JL   Jump if Less (signed) SF != OF
*    JNGE   Jump if Not Greater or Equal (signed) SF != OF
*    JLE   Jump if Less or Equal (signed) ZF=1 or SF != OF
*    JNG   Jump if Not Greater (signed) ZF=1 or SF != OF
*    JNS   Jump if Not Signed (signed) SF=0
*    JS   Jump if Signed (signed) SF=1
*    JNO   Jump if Not Overflow (signed) OF=0
*    JO   Jump if Overflow (signed) OF=1
*    JNP   Jump if No Parity PF=0
*    JP   Jump if Parity PF=1
*    JPE   Jump if Parity Even PF=1
*    JPO   Jump if Parity Odd PF=0
*/
res(DOT_IFA,     .ifa, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNBE,     .ifnbe, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFB,     .ifb, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFC,     .ifc, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNAE,     .ifnae, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFG,     .ifg, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNLE,     .ifnle, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFE,     .ife, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFZ,     .ifz, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFL,     .ifl, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNGE,     .ifnge, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFAE,     .ifae, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFBE,     .ifbe, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNA,     .ifna, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFGE,     .ifge, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNL,     .ifnl, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFLE,     .ifle, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNG,     .ifng, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNC,     .ifnc, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNB,     .ifnb, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNE,     .ifne, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNZ,     .ifnz, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFO,     .ifo, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNO,     .ifno, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFP,     .ifp, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNP,     .ifnp, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFPO,     .ifpo, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFPE,     .ifpe, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFS,     .ifs, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)
res(DOT_IFNS,     .ifns, DF_CGEN|DF_CEXPR|DF_NOSTRUC|DF_STORE|DF_PROC, DRT_HLLSTART, 0, P_86, 0)

res(DOT_ELSEIFA,    .elseifa, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNBE,  .elseifnbe, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFB,    .elseifb, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFC,    .elseifc, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNAE,  .elseifnae, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFG,    .elseifg, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNLE,  .elseifnle, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFE,    .elseife, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFZ,    .elseifz, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFL,    .elseifl, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNGE,  .elseifnge, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFAE,   .elseifae, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFBE,   .elseifbe, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNA,   .elseifna, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFGE,   .elseifge, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNL,   .elseifnl, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFLE,   .elseifle, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNG,   .elseifng, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNC,   .elseifnc, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNB,   .elseifnb, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNE,   .elseifne, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNZ,   .elseifnz, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFO,    .elseifo, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNO,   .elseifno, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFP,    .elseifp, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNP,   .elseifnp, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFPO,   .elseifpo, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFPE,   .elseifpe, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFS,    .elseifs, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)
res(DOT_ELSEIFNS,   .elseifns, DF_CGEN|DF_CEXPR,                             DRT_HLLEXIT,  0, P_86, 0)

#endif

hll.c:
Code: [Select]
    switch ( cmd ) {
#ifdef __IFFLAG
    case T_DOT_IFA:
    case T_DOT_IFNBE:
    case T_DOT_IFB:
    case T_DOT_IFC:
    case T_DOT_IFNAE:
    case T_DOT_IFE:
    case T_DOT_IFZ:
    case T_DOT_IFG:
    case T_DOT_IFNLE:
    case T_DOT_IFL:
    case T_DOT_IFNGE:
    case T_DOT_IFAE:
    case T_DOT_IFBE:
    case T_DOT_IFNA:
    case T_DOT_IFGE:
    case T_DOT_IFNL:
    case T_DOT_IFLE:
    case T_DOT_IFNG:
    case T_DOT_IFNE:
    case T_DOT_IFNZ:
    case T_DOT_IFS:
    case T_DOT_IFNS:
    case T_DOT_IFNB:
    case T_DOT_IFNC:
    case T_DOT_IFO:
    case T_DOT_IFNO:
    case T_DOT_IFP:
    case T_DOT_IFPE:
    case T_DOT_IFNP:
    case T_DOT_IFPO:

hll->flags = 0;
hll->labels[LSTART] = 0; /* not used by .IF */
hll->labels[LTEST] = GetHllLabel();
hll->cmd = HLL_IF;
GetLabelStr(hll->labels[LTEST], buff);

        switch ( cmd ) {
case T_DOT_IFA:
        case T_DOT_IFNBE:
            strcpy(buffer, "jbe ");
    break;
case T_DOT_IFB:
case T_DOT_IFC:
case T_DOT_IFNAE:
    strcpy(buffer, "jae ");
    break;
case T_DOT_IFE:
case T_DOT_IFZ:
    strcpy(buffer, "jne ");
    break;
case T_DOT_IFG:
        case T_DOT_IFNLE:
    strcpy(buffer, "jle ");
    break;
case T_DOT_IFL:
case T_DOT_IFNGE:
    strcpy(buffer, "jge ");
    break;
case T_DOT_IFNB:
case T_DOT_IFNC:
case T_DOT_IFAE:
    strcpy(buffer, "jb ");
    break;
case T_DOT_IFBE:
        case T_DOT_IFNA:
    strcpy(buffer, "ja ");
    break;
case T_DOT_IFGE:
        case T_DOT_IFNL:
    strcpy(buffer, "jl ");
    break;
case T_DOT_IFLE:
case T_DOT_IFNG:
    strcpy(buffer, "jg ");
    break;
case T_DOT_IFS:
    strcpy(buffer, "jns ");
    break;
case T_DOT_IFNS:
    strcpy(buffer, "js ");
    break;
case T_DOT_IFNE:
case T_DOT_IFNZ:
    strcpy(buffer, "jz ");
    break;
case T_DOT_IFO:
    strcpy(buffer, "jno ");
    break;
case T_DOT_IFNO:
    strcpy(buffer, "jo ");
    break;
case T_DOT_IFP:
case T_DOT_IFPE:
    strcpy(buffer, "jnp ");
    break;
case T_DOT_IFNP:
case T_DOT_IFPO:
    strcpy(buffer, "jp ");
    break;
}
strcat(buffer, buff);
        QueueTestLines(buffer);
break;
#endif
    case T_DOT_IF:

test case:
Code: [Select]
.386
.model flat
.code

.ifa
    nop
.endif

.ifnbe
    nop
.endif

.ifb
    nop
.endif

.ifc
    nop
.endif

.ifnae
    nop
.endif

.ifg
    nop
.endif

.ifnle
    nop
.endif

.ife
    nop
.endif

.ifz
    nop
.endif

.ifl
    nop
.endif

.ifnge
    nop
.endif

.ifae
    nop
.endif

.ifbe
    nop
.endif

.ifna
    nop
.endif

.ifge
    nop
.endif

.ifnl
    nop
.endif

.ifle
    nop
.endif

.ifng
    nop
.endif

.ifnc
    nop
.endif

.ifnb
    nop
.endif

.ifne
    nop
.endif

.ifnz
    nop
.endif

.ifo
    nop
.endif

.ifno
    nop
.endif

.ifp
    nop
.endif

.ifnp
    nop
.endif

.ifpo
    nop
.endif

.ifpe
    nop
.endif

.ifs
    nop
.endif

.ifns
    nop
.endif

end

list file:
Code: [Select]
00000000                        .ifa
00000000  7601              *   jbe @C0001
00000002  90                        nop
00000003                        .endif
00000003                    *   @C0001:

00000003                        .ifnbe
00000003  7601              *   jbe @C0002
00000005  90                        nop
00000006                        .endif
00000006                    *   @C0002:

00000006                        .ifb
00000006  7301              *   jae @C0003
00000008  90                        nop
00000009                        .endif
00000009                    *   @C0003:

00000009                        .ifc
00000009  7301              *   jae @C0004
0000000B  90                        nop
0000000C                        .endif
0000000C                    *   @C0004:

0000000C                        .ifnae
0000000C  7301              *   jae @C0005
0000000E  90                        nop
0000000F                        .endif
0000000F                    *   @C0005:

0000000F                        .ifg
0000000F  7E01              *   jle @C0006
00000011  90                        nop
00000012                        .endif
00000012                    *   @C0006:

00000012                        .ifnle
00000012  7E01              *   jle @C0007
00000014  90                        nop
00000015                        .endif
00000015                    *   @C0007:

00000015                        .ife
00000015  7501              *   jne @C0008
00000017  90                        nop
00000018                        .endif
00000018                    *   @C0008:

00000018                        .ifz
00000018  7501              *   jne @C0009
0000001A  90                        nop
0000001B                        .endif
0000001B                    *   @C0009:

0000001B                        .ifl
0000001B  7D01              *   jge @C000A
0000001D  90                        nop
0000001E                        .endif
0000001E                    *   @C000A:

0000001E                        .ifnge
0000001E  7D01              *   jge @C000B
00000020  90                        nop
00000021                        .endif
00000021                    *   @C000B:

00000021                        .ifae
00000021  7201              *   jb @C000C
00000023  90                        nop
00000024                        .endif
00000024                    *   @C000C:

00000024                        .ifbe
00000024  7701              *   ja @C000D
00000026  90                        nop
00000027                        .endif
00000027                    *   @C000D:

00000027                        .ifna
00000027  7701              *   ja @C000E
00000029  90                        nop
0000002A                        .endif
0000002A                    *   @C000E:

0000002A                        .ifge
0000002A  7C01              *   jl @C000F
0000002C  90                        nop
0000002D                        .endif
0000002D                    *   @C000F:

0000002D                        .ifnl
0000002D  7C01              *   jl @C0010
0000002F  90                        nop
00000030                        .endif
00000030                    *   @C0010:

00000030                        .ifle
00000030  7F01              *   jg @C0011
00000032  90                        nop
00000033                        .endif
00000033                    *   @C0011:

00000033                        .ifng
00000033  7F01              *   jg @C0012
00000035  90                        nop
00000036                        .endif
00000036                    *   @C0012:

00000036                        .ifnc
00000036  7201              *   jb @C0013
00000038  90                        nop
00000039                        .endif
00000039                    *   @C0013:

00000039                        .ifnb
00000039  7201              *   jb @C0014
0000003B  90                        nop
0000003C                        .endif
0000003C                    *   @C0014:

0000003C                        .ifne
0000003C  7401              *   jz @C0015
0000003E  90                        nop
0000003F                        .endif
0000003F                    *   @C0015:

0000003F                        .ifnz
0000003F  7401              *   jz @C0016
00000041  90                        nop
00000042                        .endif
00000042                    *   @C0016:

00000042                        .ifo
00000042  7101              *   jno @C0017
00000044  90                        nop
00000045                        .endif
00000045                    *   @C0017:

00000045                        .ifno
00000045  7001              *   jo @C0018
00000047  90                        nop
00000048                        .endif
00000048                    *   @C0018:

00000048                        .ifp
00000048  7B01              *   jnp @C0019
0000004A  90                        nop
0000004B                        .endif
0000004B                    *   @C0019:

0000004B                        .ifnp
0000004B  7A01              *   jp @C001A
0000004D  90                        nop
0000004E                        .endif
0000004E                    *   @C001A:

0000004E                        .ifpo
0000004E  7A01              *   jp @C001B
00000050  90                        nop
00000051                        .endif
00000051                    *   @C001B:

00000051                        .ifpe
00000051  7B01              *   jnp @C001C
00000053  90                        nop
00000054                        .endif
00000054                    *   @C001C:

00000054                        .ifs
00000054  7901              *   jns @C001D
00000056  90                        nop
00000057                        .endif
00000057                    *   @C001D:

00000057                        .ifns
00000057  7801              *   js @C001E
00000059  90                        nop
0000005A                        .endif
0000005A                    *   @C001E:
Title: Re: Signed Flags
Post by: habran on October 14, 2014, 06:19:07 AM
It is JWasmHabran.zip this link http://masm32.com/board/index.php?topic=3149.0 (http://masm32.com/board/index.php?topic=3149.0)

the folder contains JWasm binaries and MVS13 Expres solution
it also contains changed sources
because of forum limitation I couldn't upload complete sources
so if someone wants to build it, must download it from Japheth site and than add missing sources
headers are all there so you don't need to touch the H folder
Title: Re: Signed Flags
Post by: habran on October 14, 2014, 06:29:58 AM
great job nidud :t
Title: Re: Signed Flags
Post by: nidud on October 14, 2014, 07:38:17 AM
here is the .elseif code
Code: [Select]
#ifdef __IFFLAG
    idx = 0;
#endif
    switch ( cmd ) {
#ifdef __IFFLAG
    case T_DOT_ELSEIFA:
    case T_DOT_ELSEIFNBE:
    case T_DOT_ELSEIFB:
    case T_DOT_ELSEIFC:
    case T_DOT_ELSEIFNAE:
    case T_DOT_ELSEIFE:
    case T_DOT_ELSEIFZ:
    case T_DOT_ELSEIFG:
    case T_DOT_ELSEIFNLE:
    case T_DOT_ELSEIFL:
    case T_DOT_ELSEIFNGE:
    case T_DOT_ELSEIFAE:
    case T_DOT_ELSEIFBE:
    case T_DOT_ELSEIFNA:
    case T_DOT_ELSEIFGE:
    case T_DOT_ELSEIFNL:
    case T_DOT_ELSEIFLE:
    case T_DOT_ELSEIFNG:
    case T_DOT_ELSEIFNE:
    case T_DOT_ELSEIFNZ:
    case T_DOT_ELSEIFS:
    case T_DOT_ELSEIFNS:
    case T_DOT_ELSEIFNB:
    case T_DOT_ELSEIFNC:
    case T_DOT_ELSEIFO:
    case T_DOT_ELSEIFNO:
    case T_DOT_ELSEIFP:
    case T_DOT_ELSEIFPE:
    case T_DOT_ELSEIFNP:
    case T_DOT_ELSEIFPO:
idx = 1;
#endif
    case T_DOT_ELSEIF:
hll->flags |= HLLF_ELSEIF;
    case T_DOT_ELSE:
if ( hll->cmd != HLL_IF ) {
    DebugMsg(("HllExitDir(%s): labels[LTEST]=%X\n", tokenarray[i].string_ptr, hll->labels[LTEST]));
    return( EmitErr( BLOCK_NESTING_ERROR, tokenarray[i].string_ptr ) );
}
/* v2.08: check for multiple ELSE clauses */
if ( hll->flags & HLLF_ELSEOCCURED ) {
    return( EmitError( DOT_ELSE_CLAUSE_ALREADY_OCCURED_IN_THIS_DOT_IF_BLOCK ) );
}

/* the 'exit'-label is only needed if an .ELSE branch exists.
* That's why it is created delayed.
*/
if ( hll->labels[LEXIT] == 0 )
    hll->labels[LEXIT] = GetHllLabel();
AddLineQueueX( JMPPREFIX "jmp %s", GetLabelStr( hll->labels[LEXIT], buff ) );

if ( hll->labels[LTEST] > 0 ) {
    AddLineQueueX( "%s" LABELQUAL, GetLabelStr( hll->labels[LTEST], buff ) );
    hll->labels[LTEST] = 0;
}
i++;
#ifdef __IFFLAG
if (idx) {
    hll->labels[LTEST] = GetHllLabel();
    switch ( cmd ) {
    case T_DOT_ELSEIFA:
    case T_DOT_ELSEIFNBE:
strcpy(buffer, "jbe ");
break;
    case T_DOT_ELSEIFB:
    case T_DOT_ELSEIFC:
    case T_DOT_ELSEIFNAE:
strcpy(buffer, "jae ");
break;
    case T_DOT_ELSEIFE:
    case T_DOT_ELSEIFZ:
strcpy(buffer, "jne ");
break;
    case T_DOT_ELSEIFG:
    case T_DOT_ELSEIFNLE:
strcpy(buffer, "jle ");
break;
    case T_DOT_ELSEIFL:
    case T_DOT_ELSEIFNGE:
strcpy(buffer, "jge ");
break;
    case T_DOT_ELSEIFNB:
    case T_DOT_ELSEIFNC:
    case T_DOT_ELSEIFAE:
strcpy(buffer, "jb ");
break;
    case T_DOT_ELSEIFBE:
    case T_DOT_ELSEIFNA:
strcpy(buffer, "ja ");
break;
    case T_DOT_ELSEIFGE:
    case T_DOT_ELSEIFNL:
strcpy(buffer, "jl ");
break;
    case T_DOT_ELSEIFLE:
    case T_DOT_ELSEIFNG:
strcpy(buffer, "jg ");
break;
    case T_DOT_ELSEIFS:
strcpy(buffer, "jns ");
break;
    case T_DOT_ELSEIFNS:
strcpy(buffer, "js ");
break;
    case T_DOT_ELSEIFNE:
    case T_DOT_ELSEIFNZ:
strcpy(buffer, "jz ");
break;
    case T_DOT_ELSEIFO:
strcpy(buffer, "jno ");
break;
    case T_DOT_ELSEIFNO:
strcpy(buffer, "jo ");
break;
    case T_DOT_ELSEIFP:
    case T_DOT_ELSEIFPE:
strcpy(buffer, "jnp ");
break;
    case T_DOT_ELSEIFNP:
    case T_DOT_ELSEIFPO:
strcpy(buffer, "jp ");
break;
    }
    strcat(buffer, GetLabelStr(hll->labels[LTEST], buff));
    AddLineQueue(buffer);
} else
#endif
if ( cmd == T_DOT_ELSEIF ) {

extended test case:
Code: [Select]
.ifns
    nop
;
;
.elseifa
    nop
.elseifnbe
    nop
.elseifb
    nop
.elseifc
    nop
.elseifnae
    nop
.elseifg
    nop
.elseifnle
    nop
.elseife
    nop
.elseifz
    nop
.elseifl
    nop
.elseifnge
    nop
.elseifae
    nop
.elseifbe
    nop
.elseifna
    nop
.elseifge
    nop
.elseifnl
    nop
.elseifle
    nop
.elseifng
    nop
.elseifnc
    nop
.elseifnb
    nop
.elseifne
    nop
.elseifnz
    nop
.elseifo
    nop
.elseifno
    nop
.elseifp
    nop
.elseifnp
    nop
.elseifpo
    nop
.elseifpe
    nop
.elseifs
    nop
.elseifns
    nop
.endif

end

result:
Code: [Select]
00000057                        .ifns
00000057  7806              *   js @C001E
00000059  90                        nop
                                ;
                                ;
0000005A                        .elseifa
0000005A  E9A0000000        *   jmp @C001F
0000005F                    *   @C001E:
0000005F  7606              *   jbe @C0020
00000061  90                        nop
00000062                        .elseifnbe
00000062  E998000000        *   jmp @C001F
00000067                    *   @C0020:
00000067  7606              *   jbe @C0021
00000069  90                        nop
0000006A                        .elseifb
0000006A  E990000000        *   jmp @C001F
0000006F                    *   @C0021:
0000006F  7306              *   jae @C0022
00000071  90                        nop
00000072                        .elseifc
00000072  E988000000        *   jmp @C001F
00000077                    *   @C0022:
00000077  7306              *   jae @C0023
00000079  90                        nop
0000007A                        .elseifnae
0000007A  E980000000        *   jmp @C001F
0000007F                    *   @C0023:
0000007F  7303              *   jae @C0024
00000081  90                        nop
00000082                        .elseifg
00000082  EB7B              *   jmp @C001F
00000084                    *   @C0024:
00000084  7E03              *   jle @C0025
00000086  90                        nop
00000087                        .elseifnle
00000087  EB76              *   jmp @C001F
00000089                    *   @C0025:
00000089  7E03              *   jle @C0026
0000008B  90                        nop
0000008C                        .elseife
0000008C  EB71              *   jmp @C001F
0000008E                    *   @C0026:
0000008E  7503              *   jne @C0027
00000090  90                        nop
00000091                        .elseifz
00000091  EB6C              *   jmp @C001F
00000093                    *   @C0027:
00000093  7503              *   jne @C0028
00000095  90                        nop
00000096                        .elseifl
00000096  EB67              *   jmp @C001F
00000098                    *   @C0028:
00000098  7D03              *   jge @C0029
0000009A  90                        nop
0000009B                        .elseifnge
0000009B  EB62              *   jmp @C001F
0000009D                    *   @C0029:
0000009D  7D03              *   jge @C002A
0000009F  90                        nop
000000A0                        .elseifae
000000A0  EB5D              *   jmp @C001F
000000A2                    *   @C002A:
000000A2  7203              *   jb @C002B
000000A4  90                        nop
000000A5                        .elseifbe
000000A5  EB58              *   jmp @C001F
000000A7                    *   @C002B:
000000A7  7703              *   ja @C002C
000000A9  90                        nop
000000AA                        .elseifna
000000AA  EB53              *   jmp @C001F
000000AC                    *   @C002C:
000000AC  7703              *   ja @C002D
000000AE  90                        nop
000000AF                        .elseifge
000000AF  EB4E              *   jmp @C001F
000000B1                    *   @C002D:
000000B1  7C03              *   jl @C002E
000000B3  90                        nop
000000B4                        .elseifnl
000000B4  EB49              *   jmp @C001F
000000B6                    *   @C002E:
000000B6  7C03              *   jl @C002F
000000B8  90                        nop
000000B9                        .elseifle
000000B9  EB44              *   jmp @C001F
000000BB                    *   @C002F:
000000BB  7F03              *   jg @C0030
000000BD  90                        nop
000000BE                        .elseifng
000000BE  EB3F              *   jmp @C001F
000000C0                    *   @C0030:
000000C0  7F03              *   jg @C0031
000000C2  90                        nop
000000C3                        .elseifnc
000000C3  EB3A              *   jmp @C001F
000000C5                    *   @C0031:
000000C5  7203              *   jb @C0032
000000C7  90                        nop
000000C8                        .elseifnb
000000C8  EB35              *   jmp @C001F
000000CA                    *   @C0032:
000000CA  7203              *   jb @C0033
000000CC  90                        nop
000000CD                        .elseifne
000000CD  EB30              *   jmp @C001F
000000CF                    *   @C0033:
000000CF  7403              *   jz @C0034
000000D1  90                        nop
000000D2                        .elseifnz
000000D2  EB2B              *   jmp @C001F
000000D4                    *   @C0034:
000000D4  7403              *   jz @C0035
000000D6  90                        nop
000000D7                        .elseifo
000000D7  EB26              *   jmp @C001F
000000D9                    *   @C0035:
000000D9  7103              *   jno @C0036
000000DB  90                        nop
000000DC                        .elseifno
000000DC  EB21              *   jmp @C001F
000000DE                    *   @C0036:
000000DE  7003              *   jo @C0037
000000E0  90                        nop
000000E1                        .elseifp
000000E1  EB1C              *   jmp @C001F
000000E3                    *   @C0037:
000000E3  7B03              *   jnp @C0038
000000E5  90                        nop
000000E6                        .elseifnp
000000E6  EB17              *   jmp @C001F
000000E8                    *   @C0038:
000000E8  7A03              *   jp @C0039
000000EA  90                        nop
000000EB                        .elseifpo
000000EB  EB12              *   jmp @C001F
000000ED                    *   @C0039:
000000ED  7A03              *   jp @C003A
000000EF  90                        nop
000000F0                        .elseifpe
000000F0  EB0D              *   jmp @C001F
000000F2                    *   @C003A:
000000F2  7B03              *   jnp @C003B
000000F4  90                        nop
000000F5                        .elseifs
000000F5  EB08              *   jmp @C001F
000000F7                    *   @C003B:
000000F7  7903              *   jns @C003C
000000F9  90                        nop
000000FA                        .elseifns
000000FA  EB03              *   jmp @C001F
000000FC                    *   @C003C:
000000FC  7801              *   js @C003D
000000FE  90                        nop
000000FF                        .endif
000000FF                    *   @C003D:
000000FF                    *   @C001F:
Title: Re: Signed Flags
Post by: habran on October 14, 2014, 09:51:28 AM
Hey nidud :biggrin:
that is remarkable how your brains work :eusa_clap:
However, with only a few changes in original source code we can get all of this
this is hll.c
here I added last 3 characters
Code: [Select]
/* items in table below must match order COP_ZERO - COP_OVERFLOW */
static const char flaginstr[] = { 'z', 'c', 's', 'p', 'o', 'l', 'g', 'a'};
Code: [Select]
enum c_bop {
  COP_NONE,
  COP_EQ,   /* == */
  COP_NE,   /* != */
  COP_GT,   /* >  */
  COP_LT,   /* <  */
  COP_GE,   /* >= */
  COP_LE,   /* <= */
  COP_AND,  /* && */
  COP_OR,   /* || */
  COP_ANDB, /* &  */
  COP_NEG,  /* !  */
  COP_ZERO, /* ZERO?   not really a valid C operator */
  COP_CARRY,/* CARRY?  not really a valid C operator */
  COP_SIGN, /* SIGN?   not really a valid C operator */
  COP_PARITY,  /* PARITY?   not really a valid C operator */
  COP_OVERFLOW, /* OVERFLOW? not really a valid C operator */
  //added by habran
  COP_LESS,/* SIGN=OVERFLOW  not really a valid C operator */
  COP_GREATER, /* SIGNED ZERO OR CARRY   not really a valid C operator */
  COP_ABOVE  /* ZERO OR CARRY  not really a valid C operator */
};

Code: [Select]
  else {
    if (item->token != T_ID)
      return(COP_NONE);
    /* a valid "flag" string must end with a question mark */
    size = strlen(p);
    if (*(p + size - 1) != '?')
      return(COP_NONE);
    if (size == 5 && (0 == _memicmp(p, "ZERO", 4)))
      rc = COP_ZERO;
    else if (size == 6 && (0 == _memicmp(p, "CARRY", 5)))
      rc = COP_CARRY;
    else if (size == 5 && (0 == _memicmp(p, "SIGN", 4)))
      rc = COP_SIGN;
    else if (size == 7 && (0 == _memicmp(p, "PARITY", 6)))
      rc = COP_PARITY;
    else if (size == 9 && (0 == _memicmp(p, "OVERFLOW", 8)))
      rc = COP_OVERFLOW;
    //added by habran
    else if (size == 5 && (0 == _memicmp(p, "LESS", 4)))
      rc = COP_LESS;
    else if (size == 8 && (0 == _memicmp(p, "GREATER", 7)))
      rc = COP_GREATER;
    else if (size == 6 && (0 == _memicmp(p, "ABOVE", 5)))
      rc = COP_ABOVE;
    else
      return(COP_NONE);
  }


Title: Re: Signed Flags
Post by: habran on October 14, 2014, 10:20:57 AM
I have uploaded the C source in the post 1 of this thread and headers post 3 because they are together greater than 512K
Title: Re: Signed Flags
Post by: nidud on October 16, 2014, 10:29:11 PM
Code: [Select]
.if[all_possible_flag_combinations]

The solution I made works well for the above test but an expression should also be made to cover all combinations.

Code: [Select]
.if <all_possible_flag_combinations> [<expression>]

Quote
However, with only a few changes in original source code we can get all of this

The problem here is that the naming fell short of logic since each flag-bit have a name. The combination of flag-bits should then follow the same logic.

Code: [Select]
NOTCARRYANDNOTZERO?
CARRYORZERO?
NOTZEROANDSIGNEDEQOVERFLOW?
SIGNEDEQOVERFLOW?
SIGNEDNOTEQOVERFLOW?
ZEROORSIGNEDNOTEQOVERFLOW?

This is however a very bad solution, but using ABOVE? and CARRY? is also a bad solution. If using Above then Below should also be added. Equal and all possible flag combinations then follows which ends up in the same (bad) situation.

The single-bit flags are fine and useful as they are, but creating jump conditions based on ZF=1 or SF != OF is way to complicated. The combination that could work in this case are the jump instructions (Jxx) already used. However, you need to include all of them to create a coherent language out of it. The combination could then be FLAGSxx?

The implementation in HLL.C will then be:

Code: [Select]
    COP_OVERFLOW, /* OVERFLOW? not really a valid C operator */
#ifdef __IFFLAG
COP_FLAGSA,
// COP_FLAGSNBE,
COP_FLAGSAE,
// COP_FLAGSNB,
// COP_FLAGSNC,
// COP_FLAGSB,
// COP_FLAGSC,
// COP_FLAGSNAE,
COP_FLAGSBE,
// COP_FLAGSNA,
// COP_FLAGSE,
// COP_FLAGSZ,
// COP_FLAGSNE,
COP_FLAGSNZ,
COP_FLAGSG,
// COP_FLAGSNLE,
COP_FLAGSGE,
// COP_FLAGSNL,
COP_FLAGSL,
// COP_FLAGSNGE,
COP_FLAGSLE,
// COP_FLAGSNG,
// COP_FLAGSS,
COP_FLAGSNS,
// COP_FLAGSO,
COP_FLAGSNO,
// COP_FLAGSP,
// COP_FLAGSPE,
COP_FLAGSNP
// COP_FLAGSPO,
#endif
};
/* items in table below must match order COP_ZERO - COP_OVERFLOW */
static const char flaginstr[] = { 'z',  'c',  's',  'p',  'o'
#ifdef __IFFLAG
,'a','b','a','z','g','l','l','g','s','o','p'
/*
COP_FLAGSA a
COP_FLAGSAE nb
COP_FLAGSBE na
COP_FLAGSNZ nz
COP_FLAGSG g
COP_FLAGSGE nl
COP_FLAGSL l
COP_FLAGSLE ng
COP_FLAGSNS ns
COP_FLAGSNO no
COP_FLAGSNP np
*/
#endif
};

the (long) parsing in GetCOp(...):
Code: [Select]
else if ( size == 9 && ( 0 == _memicmp( p, "OVERFLOW", 8 ) ) )
    rc = COP_OVERFLOW;
#ifdef __IFFLAG
else if ( size == 7 && ( 0 == _memicmp( p, "FLAGSA", 6 ) ) )
    rc = COP_FLAGSA;
else if ( size == 9 && ( 0 == _memicmp( p, "FLAGSNBE", 8 ) ) )
    rc = COP_FLAGSA;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSAE", 7 ) ) )
    rc = COP_FLAGSAE;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSNB", 7 ) ) )
    rc = COP_FLAGSAE;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSNC", 7 ) ) )
    rc = COP_FLAGSAE;
else if ( size == 7 && ( 0 == _memicmp( p, "FLAGSB", 6 ) ) )
    rc = COP_CARRY;
else if ( size == 7 && ( 0 == _memicmp( p, "FLAGSC", 6 ) ) )
    rc = COP_CARRY;
else if ( size == 9 && ( 0 == _memicmp( p, "FLAGSNAE", 8 ) ) )
    rc = COP_CARRY;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSBE", 7 ) ) )
    rc = COP_FLAGSBE;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSNA", 7 ) ) )
    rc = COP_FLAGSBE;
else if ( size == 7 && ( 0 == _memicmp( p, "FLAGSE", 6 ) ) )
    rc = COP_ZERO;
else if ( size == 7 && ( 0 == _memicmp( p, "FLAGSZ", 6 ) ) )
    rc = COP_ZERO;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSNE", 7 ) ) )
    rc = COP_FLAGSNZ;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSNZ", 7 ) ) )
    rc = COP_FLAGSNZ;
else if ( size == 7 && ( 0 == _memicmp( p, "FLAGSG", 6 ) ) )
    rc = COP_FLAGSG;
else if ( size == 9 && ( 0 == _memicmp( p, "FLAGSNLE", 8 ) ) )
    rc = COP_FLAGSG;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSGE", 7 ) ) )
    rc = COP_FLAGSGE;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSNL", 7 ) ) )
    rc = COP_FLAGSGE;
else if ( size == 7 && ( 0 == _memicmp( p, "FLAGSL", 6 ) ) )
    rc = COP_FLAGSL;
else if ( size == 9 && ( 0 == _memicmp( p, "FLAGSNGE", 8 ) ) )
    rc = COP_FLAGSL;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSLE", 7 ) ) )
    rc = COP_FLAGSLE;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSNG", 7 ) ) )
    rc = COP_FLAGSLE;
else if ( size == 7 && ( 0 == _memicmp( p, "FLAGSS", 6 ) ) )
    rc = COP_SIGN;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSNS", 7 ) ) )
    rc = COP_FLAGSNS;
else if ( size == 7 && ( 0 == _memicmp( p, "FLAGSO", 6 ) ) )
    rc = COP_OVERFLOW;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSNO", 7 ) ) )
    rc = COP_FLAGSNO;
else if ( size == 7 && ( 0 == _memicmp( p, "FLAGSP", 6 ) ) )
    rc = COP_PARITY;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSPE", 7 ) ) )
    rc = COP_PARITY;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSNP", 7 ) ) )
    rc = COP_FLAGSNP;
else if ( size == 8 && ( 0 == _memicmp( p, "FLAGSPO", 7 ) ) )
    rc = COP_FLAGSNP;
#endif
else
    return( COP_NONE );

The parsing of the Jcc is done in RenderJcc() called from GetSimpleExpression(). Some of the NOT functions needs to be inverted here.
Code: [Select]
    bool true;
    ...
    if ( op >= COP_ZERO ) {
if ( op1.kind != EXPR_EMPTY ) {
    DebugMsg(( "GetSimpleExpression: non-empty expression rejected: %s\n", tokenarray[op1_pos].tokpos ));
    return( EmitError( SYNTAX_ERROR_IN_CONTROL_FLOW_DIRECTIVE ) );
}
p = buffer;
hllop->lastjmp = p;
#ifdef __IFFLAG
true = !is_true;
switch (op) {
case COP_FLAGSAE:
case COP_FLAGSBE:
case COP_FLAGSNZ:
case COP_FLAGSGE:
case COP_FLAGSLE:
case COP_FLAGSNS:
case COP_FLAGSNO:
case COP_FLAGSNP:
    true = is_true;
}
RenderJcc( p, flaginstr[ op - COP_ZERO ], true, label );
#else
RenderJcc( p, flaginstr[ op - COP_ZERO ], !is_true, label );
#endif
return( NOT_ERROR );
    }

This is the test case used:
Code: [Select]
;--- ASM v1.10 - HLL flag test

.386
.model flat
.code

.if FLAGSA?
    nop
.elseif FLAGSNBE?
    nop
.elseif FLAGSAE?
    nop
.elseif FLAGSNB?
    nop
.elseif FLAGSNC?
    nop
.elseif FLAGSB?
    nop
.elseif FLAGSC?
    nop
.elseif FLAGSNAE?
    nop
.elseif FLAGSBE?
    nop
.elseif FLAGSNA?
    nop
.elseif FLAGSE?
    nop
.elseif FLAGSZ?
    nop
.elseif FLAGSNE?
    nop
.elseif FLAGSNZ?
    nop
.elseif FLAGSG?
    nop
.elseif FLAGSNLE?
    nop
.elseif FLAGSGE?
    nop
.elseif FLAGSNL?
    nop
.elseif FLAGSL?
    nop
.elseif FLAGSNGE?
    nop
.elseif FLAGSLE?
    nop
.elseif FLAGSNG?
    nop
.elseif FLAGSS?
    nop
.elseif FLAGSNS?
    nop
.elseif FLAGSO?
    nop
.elseif FLAGSNO?
    nop
.elseif FLAGSP?
    nop
.elseif FLAGSPE?
    nop
.elseif FLAGSNP?
    nop
.elseif FLAGSPO?
    nop
.endif

.if !FLAGSA?
    nop
.elseif !FLAGSNBE?
    nop
.elseif !FLAGSAE?
    nop
.elseif !FLAGSNB?
    nop
.elseif !FLAGSNC?
    nop
.elseif !FLAGSB?
    nop
.elseif !FLAGSC?
    nop
.elseif !FLAGSNAE?
    nop
.elseif !FLAGSBE?
    nop
.elseif !FLAGSNA?
    nop
.elseif !FLAGSE?
    nop
.elseif !FLAGSZ?
    nop
.elseif !FLAGSNE?
    nop
.elseif !FLAGSNZ?
    nop
.elseif !FLAGSG?
    nop
.elseif !FLAGSNLE?
    nop
.elseif !FLAGSGE?
    nop
.elseif !FLAGSNL?
    nop
.elseif !FLAGSL?
    nop
.elseif !FLAGSNGE?
    nop
.elseif !FLAGSLE?
    nop
.elseif !FLAGSNG?
    nop
.elseif !FLAGSS?
    nop
.elseif !FLAGSNS?
    nop
.elseif !FLAGSO?
    nop
.elseif !FLAGSNO?
    nop
.elseif !FLAGSP?
    nop
.elseif !FLAGSPE?
    nop
.elseif !FLAGSNP?
    nop
.elseif !FLAGSPO?
    nop
.endif


.if FLAGSGE? && eax
    nop
.endif

.if FLAGSGE? || eax
    nop
.endif

end
Title: Re: Signed Flags
Post by: habran on October 17, 2014, 06:34:03 AM
Hi nidud :biggrin:
I admire your intellect, enthusiasm and programming skills 8)
I also came to this idea but I realized that it would be to complex and confusing :dazzled:
Whatever changes I have done to JWasm is because of my needs, and I find this solution simple and clear:
signed jumps
   LESS?             JGE skip
   !LESS?            JL   skip
   GREATER?       JLE skip
  !GREATER?      JG   skip
unsigned missing jumps
   ABOVE?         JBE skip
   !ABOVE?        JA   skip
As we can see only Dave and ToutEnMasm are interested in this matter and they both agree with above flags,
so I decided to keep them
Thank you for your interest and time spent on this matter, I appreciate it :t