News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

BNF descript of .IF statement

Started by StillLearningMasm, May 14, 2019, 07:58:01 AM

Previous topic - Next topic

StillLearningMasm

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

sinsi

(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




hutch--

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.