我正在linux下工作,並在嘗試從* .c代碼創建MIPS彙編文件時遇到一些問題。從gcc獲取彙編代碼的問題 - 盡了我最大的努力
所有我得到的是一個代碼* .s文件看起來像這樣(例如):
.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
我所做的就是寫GCC -S 1.C和文件被創建..但我需要它是一個MIPS代碼而不是808x彙編代碼...我該怎麼辦? 我盡我所能去了解交叉編譯器的神祕面紗,但沒有....我不明白什麼...
如果有人這樣做認爲,交叉編譯器可以爲我做以下2碼,我會很樂意......
第一個代碼是:
#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;
}
和第二代碼是:
#include <stdio.h>
#include <string.h>
void SIFT(int x_arr[ ], int y_arr[]);
int main()
{
int x[20] = {0} , y[20] = {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++;
}
}
}
我真的很感謝所有的努力!
如果你在學校爲MIPS課做這件事,你會很失望地發現GCC可能不一定現在如何根據你的教授可能想要你的方式來翻譯printf等函數。當我參加MIPS課程時,教授希望將printf調用轉換爲系統調用,而GCC可能只是向printf插入調用。 – Tyler 2014-06-11 04:14:08