UMBC CMSC 211

UMBC | CSEE


Bit Instructions in High-Level Languages

C/C++/Java

The AND, OR and XOR mnemonics are represented as the bit-wise operators in C, C++, and Java. Those are:
Assembly C/C++/Java
AND &
OR |
XOR ^

Examples

C

    #define OUTOFPAPER 8            /* 00001000b */

    value = status & OUTOFPAPER;    /* status is the printer status word
                                       from the printer status port.
				       How it got into the variable status 
				       is not important
                                       for this example.   */

    if ( value != 0 )
    {
       printf( "Printer is out of paper.\n" );
    }
  

Assembly

msg        db      'Printer is out of paper.', 10, 13,'$'

OUTOFPAPER EQU     00001000B

           mov	   ax, status
           and     ax, OUTOFPAPER
           mov     ax, value
	   jne     lab1            ; Flag set by the AND instruction
           _PutStr msg
lab1:
  


UMBC | CSEE