The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: xellos on November 01, 2010, 07:50:47 PM

Title: masm uses .if instead of jmp etc?
Post by: xellos on November 01, 2010, 07:50:47 PM
masm uses .if instead of jmp etc?
Title: Re: masm uses .if instead of jmp etc?
Post by: box on November 01, 2010, 07:57:10 PM
masm uses .if in addition to jmp etc.
Title: Re: masm uses .if instead of jmp etc?
Post by: xellos on November 01, 2010, 08:00:33 PM
so you can replace .if  with jmp?
Title: Re: masm uses .if instead of jmp etc?
Post by: Vortex on November 01, 2010, 08:14:22 PM
Quote from: xellos on November 01, 2010, 08:00:33 PM
so you can replace .if  with jmp?


.IF is a high-level construct, an important element of Macro Assemblers like Masm. You can replace .IF like the following :


include     IFtest.inc

BUFFER_SIZE equ 100

.data

msg1        db 'Please type your name :',13,10,0
msg2        db 'You did not type your name.',0
msg3        db 'Nice to meet you %s',0

.data?

buffer      db BUFFER_SIZE dup(?)

.code

start:

    invoke  crt_printf,ADDR msg1
    invoke  StdIn,ADDR buffer,BUFFER_SIZE

    invoke  StrLen,ADDR buffer
    sub     eax,2   ; remove CR+LF

    .IF eax==0

        invoke  crt_printf,ADDR msg2

    .ELSE

        invoke  crt_printf,ADDR msg3,ADDR buffer

    .ENDIF

    invoke  ExitProcess,0

END start


Converted to :


    invoke  StrLen,ADDR buffer
    sub     eax,2   ; remove CR+LF

    test    eax,eax
    jnz     @f

    invoke  crt_printf,ADDR msg2
    jmp     _exit

@@:

    invoke  crt_printf,ADDR msg3,ADDR buffer

_exit:   

    invoke  ExitProcess,0