News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

C++ Style operator

Started by ragdog, March 30, 2011, 07:45:18 PM

Previous topic - Next topic

ragdog

Hi

Gives to the c++ Operator style a macro or can it write it in masm32 in this style?

mov  numberone,10
mov  numbertwo,50
mov  numbersize,80

C++ sytle:

if(numbertwo >=numberone && numbertwo <=numberone+numbersize)

Masm style:

mov  ecx, numberone
add   ecx,numbersize
mov  eax, numbertwo

.if(eax >=numberone && eax <=ecx)

dedndave

'&&' means logical AND

i think expressions like these evaluate to either TRUE or FALSE
however, TRUE = all 1's (0FFFFFFFFh for 32-bit)

the math operators '>=' and '<=' are operated on before the logical AND
so, the expression could read
if((numbertwo >=numberone) && (numbertwo <=numberone+numbersize))

so...
if numbertwo is greater or equal to numberone
AND
numbertwo is less than or equal to (numberone+numbersize)
then the statement evaluates as TRUE

dedndave

assuming the values are signed integers...
        mov     eax,numberone
        mov     ecx,numbertwo
        cmp     eax,ecx
        jg      statement_not_true

        add     eax,numbersize
        cmp     eax,ecx
        jl      statement_not_true

;true code

        jmp     continue

statement_not_true:

;false code

continue:

qWord

Quote from: ragdog on March 30, 2011, 07:45:18 PM
Gives to the c++ Operator style a macro or can it write it in masm32 in this style?
...
if(numbertwo >=numberone && numbertwo <=numberone+numbersize)
well, you can write some 'helper'-macros: here just an short eaxmple how it could be done
Quoteinclude masm32rt.inc
.code

curr_line = -1

@GetReg macro
    IF curr_line EQ @Line
        IF @CatStr(<line_reg_used_>,%(@Line)) GE 3
            EXITM <error>
        ELSE
            EXITM @SubStr(<eax edx ecx>,@CatStr(<line_reg_used_>,%(@Line))*4+1,3)
        ENDIF
        @CatStr(<line_reg_used_>,%(@Line)) = @CatStr(<line_reg_used_>,%(@Line)) + 1
    ELSE
        curr_line = @Line
        @CatStr(<line_reg_used_>,%(@Line)) = 1
        EXITM <eax>
    ENDIF
endm

sum macro lit
   
    sum_p INSTR 1,<&lit>,<+>
    sum_m INSTR 1,<&lit>,<->
    sum_reg TEXTEQU @GetReg()
    IFDIFI sum_reg,<error>
        IF sum_p
            mov sum_reg,@SubStr(<&lit>,1,%(sum_p-1))
            add sum_reg,@SubStr(<&lit>,sum_p+1,)
            EXITM sum_reg
        ELSEIF sum_m
            mov sum_reg,@SubStr(<&lit>,1,%(sum_m-1))
            sub sum_reg,@SubStr(<&lit>,sum_m+1,)
            EXITM sum_reg
        ELSE
            .err <missing operator>
            EXITM <0>
        ENDIF
    ELSE
        .err <no more register free>
        EXITM <0>
    ENDIF
endm

ld macro lit
    ld_reg TEXTEQU @GetReg()
    IFDIFI ld_reg,<error>
        mov ld_reg,lit
        EXITM ld_reg
    ELSE
        .err <no more register free>
        EXITM <0>
    ENDIF
endm


main proc
LOCAL numberone:DWORD
LOCAL numbertwo:DWORD
LOCAL numbersize:DWORD

    mov  numberone,10
    mov  numbertwo,50
    mov  numbersize,80

    .if numbertwo >= ld(numberone) && numbertwo <= sum( numberone+numbersize)
       
    .endif
   
    inkey
    exit
   
main endp
end main
FPU in a trice: SmplMath
It's that simple!

ragdog

Then can i use my old code with push the variable to stack eax ,ecx

Quote
mov  ecx, numberone
add   ecx,numbersize
mov  eax, numbertwo

.if(eax >=numberone && eax <=ecx)

Have by the last ml and linker from Visual Studio 2010 what changed " if/else" style?

qWord

Quote from: ragdog on March 30, 2011, 08:56:13 PM
Then can i use my old code with push the variable to stack eax ,ecx

Quote
mov  ecx, numberone
add   ecx,numbersize
mov  eax, numbertwo

.if(eax >=numberone && eax <=ecx)

Have by the last ml and linker from Visual Studio 2010 what changed " if/else" style?
remove the braces - then it will work
.if eax >=numberone && eax <=ecx
FPU in a trice: SmplMath
It's that simple!

ragdog

Why this ?

What make this bracket wrong?

if program to run on an if (..) command, is considered the logical condition in the parentheses on their veracity.


if (c == 'E' | | c == 'e')    / / This condition is true if, in c
                                     / / the code of 'E 'or an 'e'is

I have make a test

WIth or without the Bracket have not any result

mov eax,4
.if (eax>=1)
;;;;TRUE
.endif

Ripp from olly Test With and Without the Bracket
And it have not any change it in olly
              
MOV EAX,4
CMP EAX,1
JB 004010EE
;;;;TRUE

I have read and i think this braket is only for better  readable the code and "if" statements

qWord

Quote from: ragdog on March 30, 2011, 10:13:25 PM
Why this ?

What make this bracket wrong?
sorry ragdog, my fault - there is nothing wrong with this brackets.
FPU in a trice: SmplMath
It's that simple!

ragdog

Other problem

input.c_str() if this a zero string like this?

szInput db "text",0


ragdog

correct

const std::string& input

Also must i this fill with

.data
szString1 db "String",0

.code

Call xyz

xyz proc
Local Input:DWORD

                  lea eax,szString1
                  mov Input,eax
push Input
call MyProc
ret
xyz endp


Or if this wrong?