Problems getting an assembly code from gcc - did my best
I'm working under linux, and having some problems while trying to create a MIPS assembly file from my *.c code.
All I'm getting is a *.s file with a code that looks like this (for example):
.file "1.c"
.section .rodata
.LC0:
.string "Please enter your string: \n"
.LC1:
.string "Please enter char to find: "
.LC2:
.string "The char %c appears %d times\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $160, %esp
movl %gs:20, %eax
movl %eax, 156(%esp)
xorl %eax, %eax
movl $0, 16(%esp)
movl $.LC0, (%esp)
call puts
movl stdin, %eax
movl %eax, 8(%esp)
movl $128, 4(%esp)
leal 28(%esp), %eax
movl %eax, (%esp)
call fgets
movl $.LC1, %eax
movl %eax, (%esp)
call printf
call getchar
movb %al, 27(%esp)
movl $0, 20(%esp)
jmp .L2
.L4:
movl 20(%esp), %eax
movzbl 28(%esp,%eax), %eax
cmpb 27(%esp), %al
jne .L3
addl $1, 16(%esp)
.L3:
addl $1, 20(%esp)
.L2:
movl 20(%esp), %eax
movzbl 28(%esp,%eax), %eax
testb %al, %al
jne .L4
movsbl 27(%esp),%edx
movl $.LC2, %eax
movl 16(%esp), %ecx
movl %ecx, 8(%esp)
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
movl $0, %eax
movl 156(%esp), %edx
xorl %gs:20, %edx
je .L6
call __stack_chk_fail
.L6:
leave
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.4.1-4ubuntu8) 4.4.1"
.section .note.GNU-stack,"",@progbits
All i did was writing gcc -S 1.c and the file been created.. BUT i need it to be a MIPS code not a 808x assembly code... what shall i do ? I did my best to understand the mystery of cross compilers, but nothing.... i didn't understood anything...
If someone that do hold that cross compiler can do it for me for the following 2 codes, I will be more than happy...
The first code is:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 128
int main ()
{
char mychar , string [SIZE];
int i;
int count =0 ;
printf ("Please enter your string: \n\n");
fgets (string, SIZE, stdin);
printf ("Please enter char to find: ");
mychar = getchar();
for (i=0 ; string[i] != '\0' ; i++ )
if ( string[i] == mychar )
count++;
printf ("The char %c appears %d times\n" ,mychar ,count);
return 0;
}
And the second code is:
#include <stdio.h>
#include <string.h>
void SIFT(int x_arr[ ], int y_arr[]);
int main ()
{
int x[20] = {0} , y[2开发者_开发问答0] = {0};
int m=0,temp=0,curr=0,i=0,j=0;
printf("Please enter your numbers now:\n\n");
/*enter numbers one by one. if x[i+1] value < x[i] value, err msg.
when user want to end the series he must enter '0' which means end of string (it wont included in x[]) */
while ( (scanf("%d",&temp) ) != 5 )
{
if (temp >= curr)
{
x[i] = temp;
curr = temp;
i++;
}
else
{
printf("The numbers are not at the right order !\n\nProgram will now terminate...\n\n");
}
}
SIFT(x,y);
for (i=0 ; y[i]=='0' ; i++) /*strlen(y) without ('0')'s includes*/
m++;
/*Prints m , y's organs*/
printf("\n\nm = %d",m);
printf("Y = ");
while (y[j]!='0')
{
printf ("%d ,",y[j]);
j++;
}
return 0;
}
void SIFT(int x_arr[ ], int y_arr[])
{
int i=0,j=0;
while (x_arr[i] != '0')
{
if (x_arr[i] == x_arr[i+1]) /*if current val. equals next val. -> jump dbl at x_arr*/
{
y_arr[j] = x_arr[i];
i+=2;
j++;
}
else
{
y_arr[j]=x_arr[i];
i++;
j++;
}
}
}
I really do appreciate all efforts !
Do you have a build of GCC that generates MIPS code? It looks like you're passing your code to an x86 compiler! A list of GCC options for MIPS can be found in the GCC documentation. If those don't work, you're going to need to build yourself a compiler that does work with MIPS. Some pre-built Linux options and instructions to build your own can be found at the LinuxMIPS wiki.
精彩评论