##this a bubble sort program, reads input from file and write the sorted data in the output file### but i want to converted it in assembly code,,,GCC in linux converted the code given after this…can anyone hepl me???
#################################################################
#include
int main(void){
int n, i, j, tmp;
int A[10000];
FILE *file, *file2;
file = fopen(“input.txt”, “r+”);
file2 = fopen(“output.txt”, “w+”);
if(file==NULL){
printf(“Error: can’t open file to read.\n”);
return 1;
}
if(file2==NULL){
printf(“Error: can’t open file to write.\n”);
return 1;
}
else{
i=0;
while(!feof(file)){
fscanf(file,”%d”,(int *)&A[i]);
i++;
}
n=i-1;
}
fclose(file);
for(i=0; i
for(j=i; j
if(A[j]
tmp=A[j];
A[j]=A[i];
A[i]=tmp;
}
}
}
for(i=0;i
fprintf(file2,”%d\n”,A[i]);
fclose(file2);
return 0;
}
===================================================================
#converted assembly code:#
.file”bsort.c”
.section.rodata.str1.1,”aMS”,@progbits,1
.LC0:
.string”r+”
.LC1:
.string”/home/francis/input.txt”
.LC2:
.string”w+”
.LC3:
.string”/home/francis/output.txt”
.section.rodata.str1.4,”aMS”,@progbits,1
.align 4
.LC4:
.string”Error: can’t open file to read.”
.align 4
.LC5:
.string”Error: can’t open file to write.”
.section.rodata.str1.1
.LC6:
.string”%d”
.LC7:
.string”%d\n”
.text
.p2align 4,,15
.globl main
.typemain, @function
main:
leal4(%esp), %ecx
andl$-16, %esp
pushl-4(%ecx)
pushl%ebp
movl%esp, %ebp
pushl%edi
pushl%esi
pushl%ebx
pushl%ecx
subl$40024, %esp
movl$.LC0, 4(%esp)
movl$.LC1, (%esp)
callfopen
movl%eax, -40024(%ebp)
movl$.LC2, 4(%esp)
movl$.LC3, (%esp)
callfopen
movl-40024(%ebp), %edx
testl%edx, %edx
movl%eax, -40020(%ebp)
je.L17
movl-40020(%ebp), %eax
testl%eax, %eax
je.L4
leal-40016(%ebp), %ebx
xorl%esi, %esi
jmp.L5
.L6:
movl%ebx, 8(%esp)
addl$1, %esi
addl$4, %ebx
movl$.LC6, 4(%esp)
movl-40024(%ebp), %eax
movl%eax, (%esp)
callfscanf
.L5:
movl-40024(%ebp), %eax
movl%eax, (%esp)
callfeof
testl%eax, %eax
je.L6
movl-40024(%ebp), %eax
leal-1(%esi), %edi
movl%eax, (%esp)
callfclose
testl%edi, %edi
jle.L7
xorl%ebx, %ebx
xorl%esi, %esi
.p2align 4,,7
.p2align 3
.L10:
leal-40016(%ebp,%ebx,4), %edx
.p2align 4,,7
.p2align 3
.L9:
movl(%edx), %ecx
movl-40016(%ebp,%esi,4), %eax
cmpl%eax, %ecx
jge.L8
movl%eax, (%edx)
movl%ecx, -40016(%ebp,%esi,4)
.L8:
addl$1, %ebx
addl$4, %edx
cmpl%ebx, %edi
jg.L9
addl$1, %esi
cmpl%esi, %edi
movl%esi, %ebx
jg.L10
xorl%ebx, %ebx
.p2align 4,,7
.p2align 3
.L11:
movl-40016(%ebp,%ebx,4), %eax
addl$1, %ebx
movl$.LC7, 8(%esp)
movl$1, 4(%esp)
movl%eax, 12(%esp)
movl-40020(%ebp), %eax
movl%eax, (%esp)
call__fprintf_chk
cmpl%ebx, %edi
jg.L11
.L7:
movl-40020(%ebp), %eax
movl%eax, (%esp)
callfclose
xorl%eax, %eax
.L3:
addl$40024, %esp
popl%ecx
popl%ebx
popl%esi
popl%edi
popl%ebp
leal-4(%ecx), %esp
ret
.L4:
movl$.LC5, (%esp)
callputs
movl$1, %eax
jmp.L3
.L17:
movl$.LC4, (%esp)
callputs
movl$1, %eax
jmp.L3
.sizemain, .-main
.ident”GCC: (Ubuntu 4.3.2-1ubuntu11) 4.3.2″
.section.note.GNU-stack,”",@progbits
this is totally a rubbish output…please help.
I need to run it in WINDLX…but GCC conversion does not support basic file operations in C. it also does not support scanf() function…
ok, i am agree with the code procedure…but if this is an converted assembly code…why it is not running in WINDLX??? is there any version problem?
Thats right….the GCC conversion is not compatible for WinDLX….as they are of different set of instructions. Thanks a bunch for your replies…