Author Topic: BNF descript of .IF statement  (Read 447 times)

StillLearningMasm

  • Regular Member
  • *
  • Posts: 21
BNF descript of .IF statement
« 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:
Code: [Select]
.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.

Code: [Select]
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:

Code: [Select]
.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

  • Member
  • *****
  • Posts: 1201
Re: BNF descript of .IF statement
« Reply #1 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

Code: [Select]
00000000  81 FB FFFFFFFF     cmp ebx,0ffffffffh
00000006  83 FB FF     cmp ebx,-1

I can walk on water but stagger on beer bourbon.

StillLearningMasm

  • Regular Member
  • *
  • Posts: 21
Re: BNF descript of .IF statement
« Reply #2 on: May 15, 2019, 03:21:41 AM »
Thank you

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6856
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: BNF descript of .IF statement
« Reply #3 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: