-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
42 lines (39 loc) · 895 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*************************************************************************
> File Name: main.c
> Author: Schorsch
> Mail: [email protected]
> Created Time: Mi 27 Jul 2022 17:29:32 CEST
> Description:
************************************************************************/
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv)
{
if (argc != 2)
{
fprintf(stderr, "%s: invalid number of arguments\n", argv[0]);
return 1;
}
char *expr=argv[1];
printf(".globl main\n");
printf("main:\n");
printf(" li a0, %ld\n",strtol(expr,&expr,10));
while(*expr)
{
if(*expr=='+')
{
++expr;
printf(" addi a0, a0, %ld\n", strtol(expr,&expr,10));
continue;
}
if(*expr=='-')
{
++expr;
printf(" addi a0, a0, -%ld\n", strtol(expr,&expr,10));
continue;
}
}
// printf(" li a0, %d\n", atoi(argv[1]));
printf(" ret\n");
return 0;
}