The MASM Forum

General => The Campus => Topic started by: StillLearningMasm on May 14, 2019, 07:58:01 AM

Title: BNF descript of .IF statement
Post by: StillLearningMasm on May 14, 2019, 07:58:01 AM
I have read the BNF Grammar on the .IF statement and according to it I should be able to do the follow fragment of code:

.486
.model small

.data

myvalue db 5
example dw 7

.code
.if ebx == (size example eq 2)
inc eax
.else
dec eax
.endif

end



The code for the .IF is correct.


00000003  83 FB FF    *     cmp    ebx, size example eq 002h
00000006  75 13    *     jne    @C0001


But If I change the .IF statement from this:
.if ebx == (size example eq 2)
to this:
.if ebx == (size example eq 4)

The code that is created for the .IF statement is this:


.if ebx == (size example eq 4)
00000003  0B DB    *     or ebx, ebx
00000005  75 13    *     jne    @C0001


Is this type of expression not supported, even though masm says it is?

notice there is no cmp for the ebx register
Title: Re: BNF descript of .IF statement
Post by: sinsi on May 14, 2019, 08:25:36 AM
(size example eq 2) evaluates to TRUE (0FFFFFFFFh)
(size example eq 4) evaluates to FALSE (0)

MASM will try to optimise, so 83 FB FF uses the signed byte version of CMP (think of 0FFFFFFFFh as -1)
and uses OR EBX,EBX which is shorter than CMP EBX,0


00000000  81 FB FFFFFFFF     cmp ebx,0ffffffffh
00000006  83 FB FF     cmp ebx,-1


Title: Re: BNF descript of .IF statement
Post by: StillLearningMasm on May 15, 2019, 03:21:41 AM
Thank you
Title: Re: BNF descript of .IF statement
Post by: hutch-- on May 15, 2019, 03:27:03 AM
This is incorrect.

> .model small

It should be,

      .486                                      ; create 32 bit code
      .model flat, stdcall                      ; 32 bit memory model
      option casemap :none                      ; case sensitive


The small memory model belongs to MS-DOS, not win32.