Question

assembly language for and, or, xor in assembly, what does it do with clear, set and change bit. please give example

assembly language

for and, or, xor in assembly, what does it do with clear, set and change bit.

please give example

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here I am writing all the parts of the question below,

In assembly language AND , OR and XOR.

AND:

AND operation can be used for clearing one or more bits.For example BL register contains 0011 1100 ,if you want to clear high-order bits to ZERO, you AND it with 0FH.

         AND    BL,   0FH   ; This sets BL to 0000 1010

        next,

        AND     AL, 01H          ; ANDing with 0000 0001
        JZ    EVEN_NUMBER

       Example:

section .text
   global _start            ;must be declared for using gcc
        
_start:                     ;tell linker entry point
   mov   ax,   8h           ;getting 8 in the ax 
   and   ax, 1              ;and ax with 1
   jz    evnn
   mov   eax, 4             ;system call number (sys_write)
   mov   ebx, 1             ;file descriptor (stdout)
   mov   ecx, odd_msg       ;message to write
   mov   edx, len2          ;length of message
   int   0x80               ;call kernel
   jmp   outprog

evnn:   
  
   mov   ah,  09h
   mov   eax, 4             ;system call number (sys_write)
   mov   ebx, 1             ;file descriptor (stdout)
   mov   ecx, even_msg      ;message to write
   mov   edx, len1          ;length of message
   int   0x80               ;call kernel

outprog:

   mov   eax,1              ;system call number (sys_exit)
   int   0x80               ;call kernel

section   .data
even_msg  db  'Even Number!' ;message showing even number
len1  equ  $ - even_msg 
   
odd_msg db  'Odd Number!'    ;message showing odd number
len2  equ  $ - odd_msg

OR :-

The OR Instruction used for supporting by performing bitwise OR operation. The OR operator returns 1 if the matching bits are either or both will be one.else returns 0.if both bits are 0.

             Operand1:     0101
             Operand2:     0011

             After Operation ----------------- 0111

        The OR operation can be used for setting one or more bits. For example, let us assume the AL register contains 0011    1010, you need to set the four low-order bits, you can OR it with a value 0000 1111 .

           OR BL, 0FH                   ; This sets BL to  0011 1111

          Example:-                

           OR AL, BL

                      

section .text
   global _start            ;must be declared for using gcc
        
_start:                     ;tell linker entry point
   mov    al, 5             ;getting 5 in the al
   mov    bl, 3             ;getting 3 in the bl
   or     al, bl            ;or al and bl registers, result should be 7
   add    al, byte '0'      ;converting decimal to ascii
        
   mov    [result],  al
   mov    eax, 4
   mov    ebx, 1
   mov    ecx, result
   mov    edx, 1 
   int    0x80
    
outprog:
   mov    eax,1             ;system call number (sys_exit)
   int    0x80              ;call kernel
        
section    .bss
result resb 1

XOR Instruction:

The XOR instruction implements the bitwise XOR operation. The XOR operation sets the resultant bit to 1, if and only if the bits from the operands are different. If the bits from the operands are same (both 0 or both 1), the resultant bit is cleared to 0.

Operand1:     0101
Operand2:     0011
After XOR -> Operand1:    0110

Ex:-(simple way)

XOR     EAX, EAX        

Here,coming to CLEAR ,SET and change bit.

CLEAR:

Clears a register. This instruction performs an Exclusive OR between a register and itself. This will clear all bits in the register.

Ex:-

clr r18 ; clear r18
loop: inc r18 ; increase r18
...
cpi r18, $50 ; Compare r18 to $50
brne loop

SET:-

Here,it will sets bit value to some given value.

Ex:-

      CF=1 ;    sets carry flag is 1.

change bit:-

It will changes the bit value to opposite value.

For example:

if bit value contains 1 , then changes to 0.

if bit value contains 0 , then changes to 1.

Add a comment
Know the answer?
Add Answer to:
assembly language for and, or, xor in assembly, what does it do with clear, set and change bit. please give example
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT