You are on page 1of 2

Computer Science & Engineering Department

I. I. T. Kharagpur
Compilers Laboratory: CS39003
3rd Year CSE: 5th Semester
Assignment - 1 Marks: 10
Assignment Out: 29
nd
July, 2010 Report on or before: 8
th
August, 2010
1. Translate the following C program using GCC/Linux to the assembly language program
of x86-32 (Intel 32-bit processor).
cc -Wall -S <le name>.c (do not give any optimization option). The le name
should be groupnn.c where nn is your group number e.g 02, 12 etc..
Write comments in the assembly language code corresponding to the function print()
and xyz() in the le groupnn.s. The comments should explain the corresponding
assembly language instructions and should also clearly show the connection between
the C program and the assembly language program.
#include <stdio.h>
#define MAX 100
void print(int data[], int n){
int i;
printf("{");
for(i=0; i<n; ++i) printf("%d, ", data[i]) ;
if(n == 0) printf("}\n");
else printf("\b\b}\n") ;
}
int xyz(int data[], int comb[], int combI, int n, int r) {
int count ;
if(r == 0) {
print(comb, combI);
return 1;
}
if(n == r) {
int i ;
for(i = 0; i < n; ++i) comb[combI+i] = data[i] ;
print(comb, combI+n);
return 1 ;
}
comb[combI] = data[0] ;
count = xyz(data+1, comb, combI+1, n-1, r-1);
count += xyz(data+1, comb, combI, n-1, r);
return count;
}
1
int main()
{
int data[MAX], comb[MAX], n = 0, r, i, nor;
printf("Enter distinct integers, terminate by Ctrl+D:\n");
while(scanf("%d", &data[n]) != EOF) n++;
printf("Enter a +ve integer (0 <= r <= %d): ", n);
scanf("%d", &r);
printf("Input: ") ;
for(i=0; i<n; ++i) printf("%d ", data[i]);
printf("\nEnumeration:\n");
nor = xyz(data, comb, 0, n, r) ;
printf("(%d choose %d) = %d\n", n, r, nor);
return 0 ;
} // ass1.c
2. Try to modify the assembly language code corresponding to the function xyz() to reduce
its size (save the original code before making any change).
3. The nal commented and modied assembly language program should remain syntac-
tically correct and semantically equivalent to the original code.
4. Intel assembly language manual and other reading materials are available at
http://cse.iitkgp.ac.in/~goutam/compiler/
5. Down-load the executable le submit from http://cse.iitkgp.ac.in/~goutam, change
the mode of the le to 755 and give the following command:
$ ./submit 1 le-name
The system will ask for the pass-word. Enter compiler123. You get a response:
le-name 100% 332 0.3KB/s 00:00
The command-line argument 1 is the assignment number.
2

You might also like