Implement bitwise exclusive OR as a series of Mic1 instructi

Implement bitwise exclusive OR as a series of Mic-1 instructions for the Java Virtual Machine.

The algorithm is:

Pop two words (top two values) from the stack as
Q = m[SP], P = m[SP - 1]
Perform Result = (NOT(P) AND Q) OR (P AND NOT(Q))
Push the result as
m[SP - 1] = Result

Thanks

Solution

// Implemented in JAVA

import java.util.Scanner;
#define SIZE 5
int a[SIZE],t;
public push()
{
    int n;
    Scanner sc = new Scanner(System.in);
   if(t==SIZE)
       System.out.println(\"Stack is Overflow...!\");

   else
   {
       System.out.println(\"Enter Element:\");
       int n = sc.nextInt();
       a[t++]=n;

   }
}
public mic_1()
{
    int Q, P, Result;
         Q = a[sp], P = a[sp - 1];
        System.out.println(\"Q = \" +Q);
        System.out.println(\"P = \" +P);
        Result = ( !(P) & Q ) | (P & !(Q));
        a[sp - 1] = Result;
       System.out.println(\"Result = \" +Result);
  
  
}
public display ()
{
    int i;  
   System.out.println(\"Stack after Operation..!\");
   for(i=0;i<SIZE;i++){
   System.out.println(\"a= \" +a[i]);
   }
  
}
public class stackimp{

     public static void main(String []args){
       
    Scanner sc = new Scanner(System.in);
   while(1)
   {
       System.out.println(\"Choose a Option:\ 1)PUSH\ 2)mic_1\ 3)display\ 4\");
       int op = sc.nextInt();
       if(op==1)
           push();
       if(op==2)
            mic_1();
       if(op==3)
            display();
       
      
     }
}

// Implemented in C

#include<stdio.h>
#define SIZE 5
int a[SIZE],t;
void push();
void mic_1(void);
void print(void);
main()
{
   int op;
   while(1)
   {
       printf(\"Choose a Option:\ 1)PUSH\ 2)Mic_1\ 3)PRINT\ \");
       scanf(\"%d\",&op);
       if(op==1)
           push();
       if(op==2)
            mic_1();
       if(op==3)
           print();
       //else
               //exit(0);
   }
}

void push()
{    
   int n,sp;

if(t==SIZE)
                printf(\"Stack is Overflow..!\ \");

        else
        {
                printf(\"Enter Element:\");
                scanf(\"%d\",&n);
                a[t++]=n;
                sp = t-1;

        }

}

void mic_1(void)
{
        int Q, P, Result;
         Q = a[sp], P = a[sp - 1];
        printf(\"Q = %d, P = %d \ \",Q,P);
        Result = ( !(P) & Q ) | (P & !(Q));
        a[sp - 1] = Result;
        printf(\"Result %d , a[sp-1] = %d\ \",Result, a[sp-1]);

}

void print(void)
{
   int i;
   printf(\"Stack after Operation..!\ \");
   for(i=t-1;i>=0; i--)
                printf(\"%d\ \",a[i]);
}

Implement bitwise exclusive OR as a series of Mic-1 instructions for the Java Virtual Machine. The algorithm is: Pop two words (top two values) from the stack a
Implement bitwise exclusive OR as a series of Mic-1 instructions for the Java Virtual Machine. The algorithm is: Pop two words (top two values) from the stack a
Implement bitwise exclusive OR as a series of Mic-1 instructions for the Java Virtual Machine. The algorithm is: Pop two words (top two values) from the stack a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site