0 Replies - 344 Views - Last Post: 26 September 2013 - 02:44 AM Rate Topic: -----

#1 40mpg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 13-April 09

Using Lex to analyze an ASM file

Posted 26 September 2013 - 02:44 AM

Hello, I am using this lex program to analyze the usage of each register, whether they are used as a source, a destination, or used as an indirect addressing, these are my codes, i have to analyze all 12 registers...is there any other efficient way to do these as oppose to declaring 36 variables, and 36 rules? (I am a student).


%{
#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) ;
}




this is my output:

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


ive attached the asm file to be analyze too, give me some tips.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1