COSC2325 (3-2-4) – Computer Organization and Machine Language M5_ASSIGNMENT Solved

60.00 $

Category:

Description

5/5 - (1 vote)

Exercise 1: Convert into ARMV8 Assembly the following C code. Test/debug your code for different inputs. Name your solution file m5_ex1.s

static long m=0x5; static long n=0x7; static long k=0x2; static long z;

 int main(void){  if((m<n)&&(m<k)){

          z=m;

     }

     else if (n < k){

          z=n;

     }

     else{

          z=k;

     }

     return 0;

}

 

Exercise 2: Implement the following logic into ARMv8 Assembly. Test/debug your code for different inputs. Name your solution files m5_ex2a.s and m5_ex2b.s

a) int i=10; int j=5; int g=1; int f=0; while (i!=j){

     f=g+j;      j++;    }

   printf(“%d\n”,f);

b)    int m=5;       int k;       int a[5];

      for(int k=0; k<5;k++){           m=m+k;

          a[k]=k;            

      }

      printf(“m=%d\n”,m);       printf(“k=%d\n”,k);

 

 

   

Exercise 3: Convert into ARMV8 Assembly the following C code. Test/debug your code for different inputs. Name your solution file m5_ex3.s

int add(int a, int *b){         int c;         a = a << 0x1;         c = a + *b;         return c;

}

 

int main(){         int p, c;

        scanf(“Enter a number: “, &p)         scanf(“Enter a number: “, &c)

 

        printf(“%d\n”, add(c,&p));         return 0;

}

 

Exercise 4: Convert into ARMV8 Assembly the following C code. Test/debug your code for different inputs.

Name your solution file m5_ex4.s

int getMin(int a, int b, int c, int d, int e, int f) { if(b<a)    a=b; if(d<c)    c=d; if(c<a)    a=c; if(f<e)    e=f; if(e<a)    a=e; return a;

}

void printMin(int m) { printf(“The minimum number is: %d\n”, m);

}

int main(void) { int min;

min = getMin(1, 2, 3, 4, 5, 6); printMin(min); return 0;

}

 

 

Each exercise should be implemented in separate files. Attach ONLY the assembly code source files (.s file) implementing the solution to each exercise under corresponding assignment link in Blackbaord.

You are not allowed to use gcc -S for the solution of this lab. Turning in the output of “gcc -S” will result in a grade of zero. The labels in your code should be mnemonic names, NOT .LC_ nor compilergenerated labels.

Your program(s) must assemble/compile/run. Programs that do not assemble/compile will receive a grade of zero.