我正在使用这个 lex 程序来分析每个寄存器的使用情况,无论它们是用作源、目标还是用作间接寻址,这些都是我的代码,我必须分析所有 12 个寄存器...有没有反对声明 36 个变量和 36 个规则的其他有效方法是什么?(我是学生)。
%{
#include <stdio.h>
int q,w,e,r,t,y,u,i,o,p,a,s = 0;
%}
%%
[push|dec]?+[ ]+(eax|EAX)+[,] q++ ;
[,| ]+(eax|EAX)+[ ]? w++ ;
['[']+(eax|EAX)+[ ]? e++ ;
[push|dec]?+[ ]+(ebx|EBX)+[,] r++ ;
[,| ]+(ebx|EBX)+[ ]? t++ ;
['[']+(ebx|EBX)+[ ]? y++ ;
[push|dec]?+[ ]+(ecx|ECX)+[,] u++ ;
[,| ]+(ecx|ECX)+[ ]? i++ ;
['[']+(ecx|ECX)+[ ]? o++ ;
[push|dec]?+[ ]+(edx|EDX)+[,] p++ ;
[,| ]+(edx|EDX)+[ ]? a++ ;
['[']+(edx|EDX)+[ ]? s++ ;
. ;
%%
main()
{
yylex() ;
printf("EAX as source: %d\n", q) ;
printf("EAX as destination: %d\n", w) ;
printf("EAX as indirect address: %d\n", e) ;
printf("EBX as source: %d\n", r) ;
printf("EBX as destination: %d\n", t) ;
printf("EBX as indirect address: %d\n", y) ;
printf("ECX as source: %d\n", u) ;
printf("ECX as destination: %d\n", i) ;
printf("ECX as indirect address: %d\n", o) ;
printf("EDX as source: %d\n", p) ;
printf("EDX as destination: %d\n", a) ;
printf("EDX as indirect address: %d\n", s) ;
}
这是我的输出:
EAX as source: 56
EAX as destination: 71
EAX as indirect address: 0
EBX as source: 25
EBX as destination: 38
EBX as indirect address: 0
ECX as source: 26
ECX as destination: 30
ECX as indirect address: 0
EDX as source: 30
EDX as destination: 38
EDX as indirect address: 0
ubuntu@ubuntu:~$ ^C
我要分析的文件在这里这是 asm 文件所在的位置