Reputation: 27
I'm making a program that takes the first character of the second argument passed as a parameter and identifies whether it's an uppercase or lowercase character. The problem is that an error occurs that is not reported when I call the function that is implemented in another file in riscv64 assembly. The riscv64 assembly code returns 0, 1, 2 which is captured in the 'int result' variable in the .c file, which does not happen. The riscv64 assembly code has already been tested in isolation from the .c file and it worked perfectly. I have no idea where the error could be.
The code compiles without errors, but at the time of execution it freezes as if it was waiting for some kind of input
ARQUIVO.C:
#include <stdio.h>
extern int verificando(char*);
int main(int argc, char *argv[]){
argc = 3;
argv[1] = "maracuja";
argv[2] = "Graviola";
int result;
result = verificando(&(argv[2][0]));
if (result == 0){
printf("\n%s: Primeiro caracter da segunda string eh minusculo.\n", argv[2]);
}else if (result == 1){
printf("\n%s: Primeiro caracter da segunda string eh maiusculo.\n", argv[2]);
}else if (result == 2){
printf("\nNao existe uma segunda string.\n");
}else {
printf("\nErro\n");
}
return 0;
}
ARQUIVO.S:
.global verificando
verificando:
#ascii
li t5, 65
li t6, 90
li t3, 97
li t4, 122
# carrega o primeiro caracter do segundo argumento em t1 e verifica
lb t1, 0(a0)
jal verifica
verifica:
bge t6, t1, maiuscula
bge t1, t3, minuscula
bge t3, t1, erro
maiuscula:
bge t1, t5, maiuscula_2
bge t1, t3, minuscula
bge t5, t1, erro
minuscula:
bge t4, t1, minuscula_2
li a0, 2
ret
maiuscula_2: # returns 1
li a0, 1
ret
minuscula_2: # returns 0
li a0, 0
ret
erro: # returns 2
li a0, 2
ret
MAKEFILE:
default:
riscv64-linux-gnu-gcc -static arquivo.s arquivo.c -o arquivo.x
run: default
qemu-riscv64-static arquivo.x
clean:
rm -rf *.x
Upvotes: 0
Views: 176
Reputation: 27
I found the error, it's in " jal verifica ".
I had only tested the code from the .s file in the riscv-programming.org debugger and this jal command worked perfectly, but when compiling with a .c file the correct thing is to use " j verifica ".
Upvotes: 0