[SOLVED] Compiler Laboratory: CS39003

35.00 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (1 vote)

3rd year CSE, 5th Semester
1. Translate the following C program using GCC/Linux to the assembly language program of x86-64 (Intel 64-bit processor) without optimization.
cc -Wall -S ass1.c
C Program: ass1.c
/*
* ass1.c Generate assembly code of x86-64 and comment
*/
#include <stdio.h> #define MAXSIZE 100
void inst_sort(int num[],int n); int bsearch(int num[],int n,int item);
int main()
{ int n, a[MAXSIZE], item, i, loc;
printf(“Enter how many elements you want: “); scanf(“%d”, &n);
printf(“Enter the %d elements: “, n); for(i = 0; i < n; i++) scanf(“%d”, &a[i]);
inst_sort(a,n);
printf(” Enter the item to search “); scanf(“%d”, &item); loc=bsearch(a,n,item);
1
if (item == a[loc]) { printf(” %d found in position: %d “, item, loc + 1);
} else { printf(” Item is not present in the list. “);
}
return 0;
}
void inst_sort(int num[],int n)
{ int i,j,k;
for(j=1;j<n;j++) { k=num[j]; for(i=j-1;i>=0 && k<num[i];i–) num[i+1]=num[i]; num[i+1]=k;
} }
int bsearch(int a[],int n,int item)
{ int mid, top, bottom;
bottom = 1; top = n; do { mid = (bottom + top) / 2; if (item < a[mid]) top = mid – 1;
else if (item > a[mid]) bottom = mid + 1;
} while (item != a[mid] && bottom <= top); return mid; }
2. Rename the generated assembly file as ass1 roll.s (where roll is your roll number). Add comments for each of the assembly language instruction. Your comment should explain the functionality of the instruction and the connection to the original C program. Please make sure that your commented file can be compiled to generate executable file. Upload your file (ass1 roll.s) in Moodle server.
2

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.