Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Assembly 

TEST Instruction Equivalent in C ?

In need little bit help !
What
PHP Code

<?php 
TEST 
instruction equivalent in C or Higher level language ?
You don't need the test instruction in higher level languages because there are better ways to write the code. It's a bitwise and operation, so you can implement that if you wish. Truly, there is no direct equivalent to my knowledge, but there are many easy ways to achieve the same result.
(Feb 24, 2017 08:40 AM)webdev77 Wrote:  You don't need the test instruction in higher level languages because there are better ways to write the code. It's a bitwise and operation, so you can implement that if you wish. Truly, there is no direct equivalent to my knowledge, but there are many easy ways to achieve the same result.

Thanks. Appreciate it!
Code
include \masm32\include\masm32rt.inc

.code
start:
  mov ebx, 15    ; 1+2+4+8
  .if ebx & 4
    print "test 4 succeeded", 13, 10
  .else
    print "test 4 failed", 13, 10
  .endif
  .if ebx & 16
    print "test 16 succeeded", 13, 10
  .else
    print "test 16 failed", 13, 10
  .endif
  inkey "that was easy with Masm32, right?"
  exit

end start

Output:
Code
test 4 succeeded
test 16 failed

Now the same in C:
Code
#include <stdio.h>
#include <conio.h>

#pragma comment(linker, "/subsystem:console" )

int main(void) {
  int ebx=15;
  if (ebx & 4)
    printf("test 4 succeeded\n");
  else
    printf("test 4 failed\n");

  if (ebx & 16)
    printf("test 16 succeeded\n");
  else
    printf("test 16 failed\n");

    _getch();
}

Some stupid brackets more but otherwise pretty much the same.

P.S.: If you prefer "pure" assembler, you can use test ebx, 4:
Code
test ebx, 4
  .if !Zero?
    print "test 4 succeeded", 13, 10
  .else
    print "test 4 failed", 13, 10
  .endif
(Feb 24, 2017 08:32 AM)RobotCrack Wrote:  In need little bit help !
What
PHP Code

<?php 
TEST 
instruction equivalent in C or Higher level language ?

You don't need to worry about that, the compiler does.

C is modeled as an 'abstract machine'
Test operation:

if ( !(me & you) ) //where me and you == 0
{

}

equivalence:

test eax, eax ; where eax is 0.
;zf = 1
je ...


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Help] by AirbourneApr 8, 2023 12:02 PM 1 78 Apr 8, 2023 12:02 PM
Last Post: luctvmgrzfsxn754
[Assembly] by erig.cartmanSep 15, 2022 10:22 AM 0 119 Sep 15, 2022 10:22 AM
Last Post: erig.cartman
by SIM-3081018Dec 23, 2016 02:37 PM 2 154 Dec 23, 2016 02:37 PM
Last Post: SIM-3081018