From: slacky
No parentheses in your if-statement results in a single bitwise operation.
What are you talking about :S What do you mean "single bitwise operation" is being performed? These are logical operations being done.
Consider:
bool valid()
{
return this->X >= 0 && this->Y >= 0 && this->X < 8 && this->Y < 8;
}
bool bitwise()
{
return this->X >= 0 & this->Y >= 0 & this->X < 8 & this->Y < 8;
}
Or
boolean valid()
{
return this.X >= 0 && this.Y >= 0 && this.X < 8 && this.Y < 8;
}
boolean bitwise()
{
return this.X >= 0 & this.Y >= 0 & this.X < 8 & this.Y < 8;
}
Or
Function TPoint.ValidPoint : Boolean;
Begin
Result := Self.X >= 0 and Self.Y >= 0
and Self.X < 8
and Self.Y < 8;
End;
Function TPoint.Bitwise : Boolean;
Begin
Result := Integer(Self.X >= 0) and Integer(Self.Y >= 0)
and Integer(Self.X < 8)
and Integer(Self.Y < 8);
End;
Or:
format PE console
entry main
include 'Code/FASM/include/macro/import32.inc'
section '.idata' import data readable
library msvcrt,'msvcrt.dll'
import msvcrt, printf, 'printf',\
exit,'exit', getchar, 'getchar', scanf, 'scanf'
section '.data' data readable writeable
True db "true", 0
False db "false", 0
Response db 13, 10, "The point is valid: %s", 13, 10, 0
Value db 13, 10, "Value: %d", 13, 10, 0
struc Point X, Y
{
.X dd X
.Y dd Y
}
P Point -0x0, 0x08
section '.code' code readable executable
main:
push ebp
mov ebp,esp
;push dword -0x01 ;Point.X
;push dword 0x00 ;Point.Y
push dword [P.X]
push dword [P.Y]
call Point_Valid
add esp, 0x08
cmp eax, 0x01
jge .true
jmp .false
.true:
push True
jmp .end
.false:
push False
.end:
push Response
call [printf]
add esp, 0x08
mov esp, ebp
pop ebx
call [getchar]
mov eax, 0x00
ret
Point_Valid:
push ebp
mov ebp, esp
mov edx, 0x0
mov eax, [ebp + 0x0C] ;Point.X
call Greater_Than_Equal ;Is Point.X >= 0?
mov edi, eax
mov eax, [ebp + 0x08] ;Point.Y
call Greater_Than_Equal ;Is Point.Y >= 0?
and edi, eax
mov edx, 0x08
mov eax, [ebp + 0x0C] ;Point.X
call Less_Than ;Is Point.X < 8?
and edi, eax
mov eax, [ebp + 0x08] ;Point.Y
call Less_Than ;Is Point.Y < 8?
and edi, eax
mov edx, eax
mov esp, ebp
pop ebp
ret
Greater_Than_Equal:
cmp eax, edx
jge .true
jmp .false
.true:
mov eax, 0x01
jmp .end
.false:
mov eax, 0x00
.end:
ret
Less_Than:
cmp eax, edx
jl .true
jmp .false
.true:
mov eax, 0x1
jmp .end
.false:
mov eax, 0x00
.end:
ret
So what is wrong with it? No parenthesis in any of them.. But, only one of the examples above prints the wrong values.. And that example is:
TPoint.ValidPointThus something is wrong with Simba.. Short-Circuit Boolean evaluation here applies.. Hand wrote that assembly (a bit rusty) and it does the same job Simba
should be doing.. It doesn't take into account short-circuit boolean evaluation though.
The only time Simba should fail is if one of the and statements BEFORE the last instruction (before the last and statement) becomes false with {B+} as the pre-processor instruction, then short-circuit boolean evaluation is valid.
Simba/Lape should have similar instructions to what C, C++ and Java is doing.. but it doesn't.. Something is wrong then. OP's first block of code is perfectly valid even in languages that take short-circuit boolean evaluation into account and should not require any parenthesis at all.