a 'turbo' assembly language
From: RR (RR_at_RR.RR)
Date: 12/24/04
- Next message: Betov: "Re: a 'turbo' assembly language"
- Previous message: Phil Carmody: "Re: [ Attn: Randy ] Ad-hoc Parsing?"
- Next in thread: Betov: "Re: a 'turbo' assembly language"
- Reply: Betov: "Re: a 'turbo' assembly language"
- Reply: Randall Hyde: "Re: a 'turbo' assembly language"
- Reply: C: "Re: a 'turbo' assembly language"
- Maybe reply: Betov: "Re: a 'turbo' assembly language"
- Maybe reply: Betov: "Re: a 'turbo' assembly language"
- Maybe reply: Betov: "Re: a 'turbo' assembly language"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 24 Dec 2004 09:34:46 GMT
I say that if
you try this language you could write what you belive
impossible in the 1/50 of the time, with more +1000% of readability.
This means that if you are an old assembly programmer and do 1kb
of code for one day, with this you could do 50kb code / day
With this You will go more fast of a C (or whatever language you want)
programmer because debugging assembly program is easier.
In few words: the nasm assembly language would be a subset of the
language so you can write old assembly nasm language too but
"/" is= to ";", ";" is= "\n", "|" is= "\n"
If some error is found you can read the .asm translation: find errors
in an assembly program should be trivial.
The macro subsitutions
"a" <->"eax"; "b" <->"ebx"; "c"<->"ecx"; "sj"<->"di" ;
"i" <->"esi"; "j" <->"edi"; "r"<->"edx"; "rx"<->"dx" ;
"rl"<->"dl" ; "rh"<->"dh" ; "s"<->"esp"; "k" <->"ebp";
"kp"<->"bp" ;
/* col carattere di escape _ ||==or &==end **=per etc */
"||"<->"|"; "**"<->"*"; "*"<->"[";
"## x1"<->"jmp x1"; "# x1"<->"jmp short x1";
"x1 = x2" <->"mov x1, x2"; "x1 += x2" <->"add x1, x2";
"x1 -= x2" <->"sub x1, x2"); "x1 ++= x2"<->"adc x1, x2";
"x1 --= x2"<->"sbb x1, x2"); "x1 <-> x2"<->"xchg x1, x2";
"x1 =^ x2" <->"mov x1, [ esp + x2 ]";
"x1 = ^ x2"<->"mov x1, [ esp + x2 ]";
"^ x1 = x2"<->"mov [ esp + x1 ], x2";
"D"<->"dword"; "W"<->"word"; "B"<->"byte"; "Q"<->"qword";
"T"<->"tword";
"x1 <<= x2" <->"shl x1, x2"; "x1 >>= x2" <->"shr x1, x2";
"x1 <<<= x2"<->"rcl x1, x2"; "x1 >>>= x2"<->"rcr x1, x2";
"x1 & x2" <->"test x1, x2"; "x1 = & x2" <->"lea x1, x2";
"x1 =& x2" <->"lea x1, x2"; "x1 &= x2" <->"and x1, x2";
"x1 |= x2" <->"or x1, x2"; "x1 ^= x2" <->"xor x1, x2";
"x1 =* x2" <->"mov x1, [x2]";
"< x1"<->"push x1";
"> x1"<->"pop x1";
"< x1 , x2 , ... , xn"
<->"push x1 \npush x2 \n ... \npush xn";
"> x1 , x2 , ... , xn"
<->"pop xn \npop x3 \n ... \npop x1";
"x1 ()" <->"call x1";
"x1 ( )"<->"call x1";
"x1 ( x2 < )"<->"call x1";
"x1 ( x2 <)" <->"call x1";
"x1 = x2 ( x3 < )"<->"call x2 \nmov x1, x3";
"x1 = x2 ( x3 <)" <->"call x2 \nmov x1, x3";
"x1 ( x2 < x3 , x4 , ... , xn )"<->
"push xn \n ... \npush x4 \npush x3 \ncall x1";
"x1 = x2 ( x3 < x4 , ... , xn )"<->
"push xn \n ... \npush x4 \ncall x2\nmov x1, x3";
"x1 <( x2 < x3 , ... , xn )"<->
"push xn \n ... \npush x3 \ncall x1 \nadd esp, 4*(n-2)";
"x1 = x2 <( x3 < x4 , ... , xn )"<->
"push xn \n ...\npush x4 \ncall x2 \nadd esp, 4*(n-3) \nmov x1, x3";
"x1 = x2 ( )"<->"call x2 \nmov x1, eax";
"x1 = x2 ()" <->"call x2 \nmov x1, eax";
"x1 ( x2 )" <->"push x2 \ncall x1";
"x1 = x2 ( x3 )"<->"push x3 \ncall x2 \nmov x1, eax";
"x1 <( x2 )" <->
"push x2 \ncall x1\nadd esp, 4";
"x1 = x2 <( x3 )"<->
"push x3 \ncall x2\nadd esp, 4\nmov x1, eax";
"x1 ( x2 , ... , xn )"<->
"push xn \n ... \npush x2 \ncall x1";
"x1 = x2 ( x3 , ... , xn )"<->
"push xn \n ... \npush x3 \ncall x2\nmov x1, eax";
"x1 <( x2 , ... , xn )"<->
"push x4 \n ... \npush x2 \ncall x1\nadd esp, 4*(n-1)";
"x1 = x2 <( x3 , ... , xn )"<->
"push xn \n ... \npush x3 \ncall x2\nadd esp, 4*(n-2)\nmov x1, eax";
"++ x1"<->"inc x1 ";
"-- x1"<->"dec x1 "; /* --[a+si]*/
"++ x1 , x2"<->"inc x1 \ninc x2 ";
"-- x1 , x2"<->"dec x1 \ndec x2 ";
"++ x1 , x2 , x3"<->"inc x1 \ninc x2 \ninc x3 ";
"-- x1 , x2 , x3"<->"dec x1 \ndec x2 \ndec x3 ";
"++ x1 , x2 , x3 , x4"<->"inc x1 \ninc x2 \ninc x3 \ninc x4 ";
"-- x1 , x2 , x3 , x4"<->"dec x1 \ndec x2 \ndec x3 \ndec x4 ";
"-- x1 # x2" <->"dec x1 \njnz x2 ";
"-- x1 !# x2" <->"dec x1 \njz x2 ";
"x1 <> x2" <->"cmp x1, x2 ";
"x1 # x2" <->"cmp x1, 0 \njne x2";
"x1 !# x2" <->"cmp x1, 0 \nje x2";
"x1 < x2 # x3" <->"cmp x1, x2 \njb x3 "; /*numeri senza segno*/
"x1 & x2 # x3" <->"test x1, x2 \njnz x3 ";
"x1 > x2 # x3" <->"cmp x1, x2 \nja x3 ";
"x1 <= x2 # x3"<->"cmp x1, x2 \njbe x3 ";
"x1 >= x2 # x3"<->"cmp x1, x2 \njae x3 ";
"x1 == x2 # x3"<->"cmp x1, x2 \nje x3 ";
"x1 != x2 # x3"<->"cmp x1, x2 \njne x3 ";
"x1 >= x2 !# x3"<->"cmp x1, x2 \njb x3 ";
"x1 <= x2 !# x3"<->"cmp x1, x2 \nja x3 ";
"x1 > x2 !# x3" <->"cmp x1, x2 \njbe x3 ";
"x1 & x2 !# x3" <->"test x1, x2 \njz x3 ";
"x1 < x2 !# x3" <->"cmp x1, x2 \njae x3 ";
"x1 != x2 !# x3"<->"cmp x1, x2 \nje x3 ";
"x1 == x2 !# x3"<->"cmp x1, x2 \njne x3 ";
"x1 < x2 ?# x3" <->"cmp x1, x2 \njl x3 "; /* numeri col segno */
"x1 > x2 ?# x3" <->"cmp x1, x2 \njg x3 ";
"x1 <= x2 ?# x3"<->"cmp x1, x2 \njle x3 ";
"x1 >= x2 ?# x3"<->"cmp x1, x2 \njge x3 ";
"x1 == x2 ?# x3"<->"cmp x1, x2 \nje x3 ";
"x1 != x2 ?# x3"<->"cmp x1, x2 \njne x3 ";
"x1 >= x2 ?!# x3"<->"cmp x1, x2 \njl x3 ";
"x1 <= x2 ?!# x3"<->"cmp x1, x2 \njg x3 ";
"x1 > x2 ?!# x3" <->"cmp x1, x2 \njle x3 ";
"x1 < x2 ?!# x3" <->"cmp x1, x2 \njge x3 ";
"x1 != x2 ?!# x3"<->"cmp x1, x2 \nje x3 ";
"x1 == x2 ?!# x3"<->"cmp x1, x2 \njne x3 ";
"x1 = x2 + x3"<->"mov x1, x2 \nadd x1, x3 ";
"x1 = x2 - x3"<->"mov x1, x2 \nsub x1, x3 ";
/* label: istruzione = istruzione \0 commento */
"=# x1" <->"je x1 "; /* numeri senza segno */
"<# x1" <->"jb x1 "; "># x1" <->"ja x1 ";
"<=# x1"<->"jbe x1 "; ">=# x1"<->"jae x1 ";
"=?# x1"<->"je x1 ";
"<?# x1" <->"jl x1 "; /* numeri con segno */
">?# x1" <->"jg x1 "; "<=?# x1"<->"jle x1 ";
">=?# x1"<->"jge x1 ";
"!=# x1"<->"jne x1 ";
"!<# x1"<->"jae x1 "; /* numeri senza segno */
"!># x1"<->"jbe x1 ";
"!<=# x1"<->"ja x1 ";
"!>=# x1"<->"jb x1 ";
"!=?# x1"<->"jne x1 ";
"!<?# x1"<->"jge x1 "; /* numeri con segno */
"!>?# x1"<->"jle x1 ";
"!<=?# x1"<->"jg x1 ";
"!>=?# x1"<->"jl x1 ";
"( x1 , x2 ) <<= x3"<->"shld x1, x2, x3 ";
"( x1 , x2 ) >>= x3"<->"shrd x1, x2, x3 ";
"( x1 , x2 )<<= x3" <->"shld x1, x2, x3 ";
"( x1 , x2 )>>= x3" <->"shrd x1, x2, x3 ";
"<< x1 = x2"<->"%define x1 x2";
">> x1"<->"%undef x1";
"<< x1 = x2 , x3 = x4"<->
"%define x1 x2 \n%define x3 x4 ");
">> x1 , x2"<->
"%undef x1 \n%undef x2 " );
"<< x1 = x2 , ... , x(n-1) = xn"<->
"%define x1 x2 \n ... \n%define x(n-1) xn ");
">> x1 , ... , xn"<->
"%undef x1 \n ... \n%undef xn " );
"== x1 == x2"<->"extern x1 \nimport x1 x2 ");
"== x1 , x2 == x3", <->
"extern x1, x2 \nimport x1 x3 \nimport x2 x3 ");
"== x1 , ... , xn == x(n+1)"<->
"extern x1, ..., xn \nimport x1 x(n+1) \nimport x2 x(n+1)
\nimport xn x(n+1) ");
"x1 , x2 = x3"<->
"[section .data] \nx2 x1 x3 , 0 \n__SECT__ ");
"x1 , x2 = x3 , x4 = x5"<->
"[section .data] \nx2 x1 x3 , 0 \nx4 x1 x5 , 0 \n__SECT__ ");
"x1 , x2 = x3 , ... , x(n-1) = xn"<->
"[section .data] \nx2 x1 x3 , 0\n...\nx(n-1) x1 xn , 0 \n__SECT__ ");
an example
/* like (better) the C language function sprintf
/* eax:len AsmPrints<(char* string, uint size, char* fmt, ...);
/* k=0k, 4k, 8ra, 12@string, 16@size, 20@fmt, 24P1, 28P2 etc
/* NOTARE < in AsmPrints<(
/* fmt="%i %d %u %x %p %f %8f %L %2L %s" %i=%d=int_*valore*,
/* %u=uint_val,
/* %p=%x==4bytesHEX, %f=punta a *memoria* ove 8bytes float(double),
/* %L idem con 10bytes float(double),%s=string puntatore a *memoria*
AsmPrints:
< k, k
k = s;
< b, c, r, i, j
s-=128;
<< @string=[k+12], @size=[k+16], @fmt=[k+20], @asize=[s]
c = & [k+24]; j=@string; i=@fmt; D @asize=0;
j==0#.ee; i==0#.ce; D @size<=1#.ce; #.c0;
.ce: B*j=0;
.ee: a=0; D[k]=1; ##.cf;
.c0: b=i; #.x0
.c1: ++i; .x0: al=*i; al==0#.c2; al!='%'#.c1
.c2: r=i-b; a=@asize; a+=r; a>=@size#.x1
@asize=a; ++r; #.x2
.x1: D[k]=1;
.ca: a=@asize; B*j=0; ##.cf;
.c3: ++b,j; .x2: al=*b; *j=al; --r#.c3;
.c4: al#.c5 | D[k]=0 | ##.ca;
.c5: ++i; al=*i; ++i; b=6;
al=='%'!#.c6
++D @asize; ++j; ##.c0;
.c6: al=='i'!#.c8;
.x3: r=&[s+8]; itoa(r, D[c]); c+=4;
a+=@asize; a<@size#.c7; ##.x1;
.c7: @asize=a; copy_str(j, r); j+=a;
##.c0;
.c8: al=='d' #.x3;
al=='u'!#.cb;
r=&[s+8]; utoa(r, D[c]); c+=4;
a+=@asize; a<@size#.c9; ##.x1;
.c9: ##.c7;
.cb: al=='L'!#.ch;
.w0: a=c; r=&[s+8]; a=*a; c+=4; FLD T [a];
.x4: St0ToAscii(r, 0, b); FSTP st0;
a+=@asize; a<@size#.cg; ##.x1;
.cg: ##.c7;
.ch: al=='f'!#.x5;
.w1: a=c; r=&[s+8]; a=*a; c+=4; FLD Q [a];
##.x4;
.x5: al=='s'!#.cn;
a=c; a=*a; c+=4; r=a;
len_str(a); a+=@asize; a<@size#.cm; ##.x1
.cm: ##.c7;
.cn: al=='x'!#.x7;
.y0: r=&[s+8]; utoh(r, D[c]); a=8; c+=4;
a+=@asize; a<@size#.x6; ##.x1;
.x6: ##.c7;
.x7: al=='p' #.y0;
al>'9'#.xc; al<'0'#.xc;
B*i=='f'#.x8; B*i=='L'#.x9; #.xc
.x8: al-='0'; b^=b; ++i; bl=al;##.w1
.x9: al-='0'; b^=b; ++i; bl=al;##.w0
.xc: a=@asize; a+=2; a<@size#.cp; ##.x1;
.cp: @asize=a; B*j='%'; ++j; al=[i-1];
al#.cq; --D @asize; D[k]=0; ##.ca;
.cq: *j=al; ++j;
##.c0; /* non trova arg in %'arg'
.cf: /* scrive il tutto
>> @string, @size, @fmt, @asize
s+=128;
> b, c, r, i, j
D[k]==1!#.xa | stc | #.xb /* CF==1 Errore
.xa: clc;
.xb:
s = k;
> k, k
ret
ret
your file with the language has to end with .m
as6 nome.m risultato.asm
/* start of file rasm.bat */
@echo off
if "%1"=="" goto usage
if "%1"=="?" goto usage
if "%1"=="-h" goto usage
if "%2"=="com" goto pst
if not "%2"=="" goto lkk
:pst2
rem nasmw -f obj file.asm
if not exist %1.m goto pst1_n_as2
as6 %1.m %1.asm
:pst1_n_as2
nasmw -f obj %1.asm
if errorlevel 1 goto errasm
alink -oPE %1.obj
if errorlevel 1 goto erralink
if exist %1.obj del %1.obj
goto TheEnd
:pst
rem nasmw -f bin -o upcase.com upcase.asm
if not exist %1.m goto pstnas1
as6 %1.m %1.asm
:pstnas1
nasmw -f bin -o %1.com %1.asm
if errorlevel 1 goto errasm
goto TheEnd
:lkk
rem nasmw -f obj file.asm
if not exist %1.m goto pst1_n_as3
as6 %1.m %1.asm
:pst1_n_as3
nasmw -f obj %1.asm
if errorlevel 1 goto errasm
brcc32 %2.rc
if errorlevel 1 goto errc
alink -oPE %1.obj %2.res
if errorlevel 1 goto erralink
if exist %1.obj del %1.obj
goto TheEnd
:usage
echo Uso con la shell:
echo ---------------------------------------------------------
echo %0 nome com
echo output nome.com
echo Se esiste nome.m viene chimato {as6 nome.m nome.asm}
echo Viene chiamato nasmw {nasmw -f bin -o nome.com nome.asm}
echo ---------------------------------------------------------
echo %0 nome
echo output nome.exe
echo Se esiste nome.m viene chimato {as6 nome.m nome.asm}
echo Viene chiamato nasmw {nasmw -f obj nome.asm}
echo Viene chiamato su nome.obj alink {alink -oPE nome }
echo ---------------------------------------------------------
echo %0 nome nome1
echo output nome.exe
echo Se esiste nome.m viene chimato {as6 nome.m nome.asm}
echo Viene chiamato nasmw {nasmw -f obj nome.asm}
echo Viene chiamato su nome1.rc brcc32{brcc32 nome1.rc }
echo Viene chiamato su nome.obj alink {alink -oPE nome nome1.res}
echo --------------------------------------------------------
goto TheEnd
:erralink
echo __
echo Linker Error
goto TheEnd
:errasm
echo __
echo Assembly Error
goto TheEnd
:errc
echo __
echo Errore di risorsa
goto TheEnd
:non_esiste
echo __
echo Non esiste %1.[m, asm]
goto TheEnd
:TheEnd
rem aggiungere eventualmente pause
/* Fine rasm.bat */
/* NOME DEL FILE: as6.c */
/*
Questo programma ha un diverso tipo di 'getword'
serve come preprocessore di macro per file .asm
il suo proposito e' *non abolire*
le micro-istruzioni dell'allassembly pur trovando
un modo per *evidenziare* i loop e gli if.
/ e' escape per commenti
{, }, sono sostituite *con niente*
e potrebbero essere usate solo nell'intento di
*evidenziare* i *loop* e gli *if*.
Per permettere a piu' istruzioni di condividere la
stessa linea i separatori ';' e '|' vengono usati
e sostituiti da '\n' nella traduzione.
Le macro sostituzioni sono evidenti nella funzione
install_all() comunque l'assembly dovrebbe essere
un sottoinsieme del linguaggio risultante
Mi sono ispirato al linguaggio C.
Se ci sono linee molto lunghe si puo' andare a capo
utilizzando i caratteri ",\n" (che verranno sostituiti
solo con "," [",\n" -> "," ] )
BUGS
Non sono supportati
1) I calcoli *su numeri* che potrebbe fare
nasm prima della fase di traduzione esempio:
mov eax, 89 & 99
La cosa che si potrebbe fare e'
usare il carattere di escape _ esempio
mov eax, _ (77 ** 8 + 99) || 67 _
Notare come _ e' circodato di spazi
notare come '*' e '|' vengono tradotti da ** e ||
rispettivamente poiche' sono caratteri 'speciali'
Col carattere di escape _ ||==or &==end **=per
^==xor, <<e>>==shift, +, -, non sono sicuro per
%=modulo e /=divisione
2) I commenti su line che iniziano (dopo eventuali
spazi) con %
3) Espressioni come a = b -7 non vengono
correttamente tradotte poiche' il + o il - sono
associati al 7; se si scrive una di queste:
a=b- 7; a= b- 7; a = b - 7; a = b- 7; a=b - 7;
tutto dovrebbe essere ok;
4) Le definizioni di macro con l'opzione -l
(senza tale opzione tutto sembra ok) meglio
definire le macro usando solo l'assembly normale
oppure non usare l'opzione -l nelle macro in
un'altro file, importarlo e usare -l.
5) Non ho fatto molte prove su testi e programmi
ci saranno un sacco di errori.
uso con nasmw:
> as6.exe -l file_in file_out.asm
> nasmw file_out.asm
'-l' serve per visualizzare la linea dell'errore
Senza l'opzione -l allora l'output non usa %line.
e dovrebbe essere piu' sicuro.
Declino ogni responsabilita' per qualsiasi danno
che potrebbe arrecare questo programma e ogni
garanzia che serva a qualche cosa; Il programma si
intende libero per l'uso.
Sono permesse con il seguente codice e io non avro'
nulla a pretendere, le seguenti azioni e/o dati
1) Copia e distribuzione del codice
2) Compilazione di detto codice con un compilatore C
3) Esecuzione di detto codice
4) Input e output dati al programma risultato del codice
5) Macro usate da detto codice per le sostituzioni
nel linguaggio stesso
In poche parole puoi usare liberamente e senza compensi
questo codice sul tuo input (che utilizza le macro di sopra)
ottenendo il tuo output (programma assembly con nasm sintassi).
PS. se qualcuno vede gli errori lo
comunichi, nel NG, Grazie.
*/
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#define R return
#define P printf
#define F for
#define W while
#define UC unsigned char
char *argomento; /* serve per assert_m */
char *nome_file;
char* estrai(char* nome)
{char *a=nome, *b;
char c;
if(nome==0) return 0;
W(1)
{b=a;
W( (c = *a)!=0 && c!='\\' && c!='/' ) ++a;
if(c==0) break;
++a;
}
R b;
}
#define assert_m(x, y) \
if(!(x)) do{ \
fprintf(stderr, "ERRORE %s: %s\n", argomento, y );\
allUscita( 0, 0, 0, 0); \
assert(x); \
}while(0)
void allUscita(int flag, FILE* f_in, FILE* f_out, char** ch);
int catstr(char* a, char* b, int i)
{char *h=a;
int k;
if(i<=0 || a==NULL || b==NULL)
{
i=0;
goto lab;
}
W(*h!='\0') ++h;
k = h-a;
i = i>k ? i-k: 0;
W(i!=0)
{*h++=*b++;
if(*b=='\0') break;
--i;
}
*h='\0';
lab:
assert_m(i!=0, "catstr: Stringa troppo lunga o argomenti nulli");
R h-a;
}
#define HASHSIZE 4019
/*2837*/
struct nlist{
struct nlist* next;
char* name;
char* defn;
};
static struct nlist* hashtab[HASHSIZE];
/*hash: calcola il valore di hashing della stringa s*/
unsigned hash(char* s)
{unsigned hashval;
if(s==NULL) R 0;
F(hashval=0;*s!='\0';++s)
hashval=*s+31*hashval;
R hashval%HASHSIZE;
}
/*lookup: cerca s in hashtab*/
struct nlist* lookup(char* s)
{struct nlist *np;
if(s==NULL) R NULL;
F(np=hashtab[hash(s)];np!=NULL;np=np->next)
if(strcmp(s,np->name)==0)
R np; /* trovata */
R NULL; /*non trovata*/
}
/* dupstr: fa una copia di s */
char* dupstr(char* s)
{char *p;
if(s==NULL) return NULL;
p=malloc(strlen(s)+1); /* +1 per '\0' */
if(p!=NULL)
strcpy( p, s );
return p;
}
void free_node(struct nlist* a)
{if(a==NULL) R;
if(a->name!=NULL) free(a->name);
if(a->defn!=NULL) free(a->defn);
free(a);
}
void free_tab(void)
{unsigned i;
struct nlist *p, *q;
F(i=0;i<HASHSIZE;++i)
F(p=hashtab[i];p!=NULL; p=q)
{q=p->next;
free_node(p);
}
}
/*undef: rimuove un nodo dalla tabella*/
int undef(char* name)
{struct nlist *pp, *p;
unsigned hsv;
if(name==NULL) R -1;
hsv=hash(name);
F(p=hashtab[hsv], pp=NULL;p!=NULL;pp=p, p=p->next)
if(strcmp(name,p->name)==0)
{if(pp==NULL)
hashtab[hsv]=p->next; /*il primo */
else pp->next=p->next;
free_node(p);
R 0;
}
R 1;
}
/*instal: inserisce il nome (name, defn) in hashtab*/
struct nlist* install(char* name, char* defn)
{struct nlist *np;
unsigned hashval;
if((np=lookup(name))==NULL) /*non trovata*/
{np=malloc(sizeof(*np));
if(np==NULL) R NULL;
if((np->name=dupstr(name))==NULL)
{free(np);
R NULL;
}
if((np->defn=dupstr(defn))==NULL)
{free(np->name);
free(np);
R NULL;
}
hashval=hash(name);
np->next=hashtab[hashval];
hashtab[hashval]=np;/*mette il nuovo nodo davanti a tutti*/
}
else
{free(np->defn); /*annulla il precedente defn P*/
np->defn=NULL;
if((np->defn=dupstr(defn))==NULL)
{undef(name);
R NULL;
}
}
return np;
}
void installl(char* name, char* defn)
{struct nlist *np;
assert_m(name!=NULL && defn!=NULL, "di memoria");
np=install(name, defn);
assert_m(np!=NULL, "di memoria");
}
int is_punct(int c)
{
if( c=='<' || c=='>' || c=='+' || c=='-' || c=='&' ||
c=='^' || c=='!' || c=='=' || c=='?' || c=='*' ||
c=='|' || c=='(' ||c==')' || c==',' || c=='!' || c=='#' ) R
1;
R 0;
}
char* gword(char* buf, char** c, int cont)
{char *b=buf, *a;
int ip;
a="gword: Buffers nulli o argomenti errati";
label:
assert_m(buf!=NULL && c!=NULL && cont>0, a);
a=*c;
W( *a!=0 && isspace(*a))
++a;
ip= is_punct(*a) || *a=='[' ? 1: 0;
if(*a && --cont>0)
F(*b++=*a++; --cont>0 && *a!=0; *b++=*a++)
{
if(isspace(*a)) break;
if(*a==':') {*b++=':';
++a; --cont;
if (isspace(*a) )
{W(isspace(*a)) ++a;
--a;
}
break;
}
if( ip && ( !is_punct(*a) || (*a=='|' && !(a[1]=='=' ||
a[1]=='|' || a[-1]=='|')) ) )
break;
if( !ip && !isalnum(*a) && *a!='_' && *a!='@' )
break;
}
if(cont<=0)
{a="gword: Linea troppo lunga"; goto label;}
*b=0; *c=a;
R buf;
}
/* Nota che non ritorna s ma ritorna NULL o un puntatore
all'ultimo carattere
*/
char* fgets_p(char* s, size_t n, FILE* iop)
{int c;
char *cs=s;
int getch(FILE* pnt);
void ungetch(char c);
/*-------------------------------------------------------*/
assert_m( s!=0 && iop!=0 && n>0, "fgets: argomenti errati" );
W( --n>0 && (c=getch(iop)) != EOF )
if( (*cs++=c) == '\n')
{if(cs>s+1 && cs[-2]==',')
{cs[-1]=' '; continue;}
else break;
}
/* P("c==%d cs-s=%d \n", (int) c, (int) (cs-s) ); */
if(c!='\n' && c!=EOF)
{F( --cs; s!=cs && *cs!=';' && !(*cs=='|' && cs[1]!='=')
&& !(*cs=='|' && cs[1]!='|') ; --cs)
ungetch(*cs);
assert_m(cs!=s, "fgets: linea troppo lunga");
/* linea piu' lunga di un token */
++cs;
}
*cs='\0';
return ( c==EOF && cs==s ) ? NULL : --cs;
}
int macro_s(char* bufr, int cont, char* buf, char** t_buf, int
num)
{char *c, *a=buf, *b=bufr, fqt[(sizeof(int)*CHAR_BIT+2)/3+1];
int i=0, led=0, led1=1, k=7;
c="macro_s: Argomenti errati";
label:
assert_m(bufr!=NULL&& buf!=NULL&& t_buf!=NULL&& cont>0&& num>i &&
k>=0, c);
W( *a!=0 && cont>0 )
{W( *a!=0 && isspace(*a) ) ++a;
if(is_punct(*a)) led=1;
W( *a!=0 && cont>0 && is_punct(*a) &&
!( (*a=='+'||*a=='-') && isdigit(a[1]) )
) /* in +8 -3 il + o il - non sono punti */
{--cont; *bufr++ = *a++;
if(led1) {if(a>buf+2 && isspace(a[-2]) )
a[-2]=0;
else a[-1]=0;
led1=0;
}
}
led1=1;
W( *a!=0 && isspace(*a) ) ++a;
if(led==1 && cont>0 )
{--cont; *bufr++=' '; led=0;}
if( *a!=0 && !isspace(*a) && cont>0 &&
( !is_punct(*a) || ( (*a=='+' || *a=='-') &&
isdigit(a[1]) )
)
)
{--cont;
*bufr++ = 'õ';
if( cont>0 )
k=sprintf( fqt, "%u", ++i);
if(k <= 0 || cont<=0) break;
if( k<cont )
{c=fqt;
W(*c!=0 && cont>0 )
{--cont ;
*bufr++ = *c++;
}
}
else {cont=0; break; }
if(i>num) break;
else t_buf[i]=a;
W( (*a!=0 && !is_punct(*a)) || *a=='+' || *a=='-'
)
{if(*a=='\'')
W(*++a!=0 && *a!='\'' );
else if(*a=='\"')
W(*++a!=0 && *a!='\"');
else if(*a=='[' )
W(*a!=0 && *a!=']' ) ++a;
else if(*a=='_' && (a[1]==' ' ||
a[1]=='\t') && isspace(a[-1]) )
{if(a==t_buf[i]) t_buf[i]=++a;
W(*a!=0 && !( *a=='_' &&
(a[1]==' ' || a[1]=='\t' || a[1]==0) ))
++a;
/* P("*a== %c::%d", *a , (int) *a);
*/
if(*a=='_') *a=' ';
}
if( *a=='+' || *a=='-' )
{if( isdigit( a[1] ) )
++a;
else break;
}
if(*a!='\0') ++a;
}
*bufr++=' ';
}
}
if(!(cont>0 && num>i && k>=0))
{ c="macro_s: Troppe parole o linea troppo lunga"; goto label;}
if( bufr>b+1 && isspace(bufr[-1]) ) bufr[-1]='\0';
else *bufr='\0';
t_buf[++i]=NULL;
R bufr-b;
}
/* õ1 + õ2 = õ3 -> õ3 + õ2 = õ1 */
int macro_sinv(char* wor, int dim, char* bufr, char* buf, char**
ch, int num)
{char *a=bufr, *w=wor, *c;
int i=0;
c="macro_sinv: argomenti errati o nulli";
label:
assert_m( wor!=0 && buf!=0 && bufr!=0 && ch!=0 && dim>0, c );
W( dim>0 )
{W(*a!=0 && *a!='õ' && dim>0)
{ *w++=*a++; --dim;} /* õ4 ## #r #EOL */
if( *a=='õ' && dim>0 )
{if( isdigit(a[1]) )
{i=atoi(++a);
W(isdigit(*a)) ++a;
if(i>=num) break;
c=ch[i];
W(*c!=0 && dim>0 )
{*w++=*c++; --dim;}
}
else {*w++=*a++; --dim;}
}
if(*a==0) break;
}
*w=0;
if(i>=num || dim<=0)
{ dim=0; c="Linea troppo lunga o troppe parole"; goto label; }
R w-wor;
}
int get_token(char** org, char** end)
{char *endd, k, led_2=0, led_1=0;
assert_m( end!=NULL, "inserimento di un null come stringa" );
*org = endd = *end;
F( ; (k=*endd)!='\0' ; endd++ )
{
if(k=='\'' && led_2==0 ) led_1= led_1==0 ? 1: 0;
if(k=='\"' && led_1==0 ) led_2= led_2==0 ? 1: 0;
if( k=='\n' )
break;
else if( k==':' && (isspace(endd[1]) || endd[1]=='\0')
&& led_1==0 && led_2==0
) break;
}
if(k==':')
++endd;
if(*endd!='\0')
{*endd='\0'; *end=++endd;}
else *end=endd;
if(k=='\0' && **org!='\0' ) k='\n';
/* P(" *end - *org=%d ", (int) (*end - *org)); */
R (int) k;
}
/* word, buffer, b devono avere dimensione bsize */
int
micro_s(char* b, int bsize, char* word, char** comm, char*
buffer)
{char c, inq=0, *h, m, *a=b, *e, *eh, led, zen=0, zer=0;
struct nlist *np;
e="micro_s: argomenti nulli o errati";
la:
assert_m( b && word && bsize>0, e );
*comm=0; led=1;
F( ; (c=*word)!='\0' && bsize>0; ++word)
{if(isspace(c)) { *b++=c; --bsize; continue; }
else if(c==';' || (c=='|' && !(word[1]=='=' || word[1]=='|'
)))
{h=word; zen=1;
W((m=*h)!='\0')
{if(!(isspace(m) && m!='\n') && m!=';' && m!='|' )
break; /* m=' ' => isspace(' ') && ' '!='\n' VERA
*/
++h;
}
if(*h!='/' || (*h=='%' && !isdigit(h[1])) )
{*b++='\n'; --bsize;}
if (*h=='\0') break ;
else if(*h=='\n' ) word=h ;
else word=--h;
continue;
}
else if(c=='/') /* %, / commenti */
{ *b++='\n'; --bsize; *comm=word; break; }
else if(c=='%' && !isdigit(word[1]))
{ *b++='\n'; --bsize; *comm=word; break; }
else if( led && (c=='s' || c=='S')
&& ( !strncmp(word, "SECTION", 7) || !strncmp(word, "section",
7) )
) { *b++='\n'; --bsize;
*comm=word; break;
}
else if(c=='\'')
{*b++=c; --bsize; ++word;
F(h=word; (m=*h)!='\0' && m!='\'' && bsize>0 ; ++h)
{*b++=*h; --bsize;}
if(m=='\0' || bsize<=0) break;
else {*b++=m; --bsize; word=h; continue; }
}
else if(c=='\"')
{*b++=c; --bsize; ++word;
F(h=word; (m=*h)!='\0' && m!='\"' && bsize>0 ; ++h)
{*b++=*h; --bsize;}
if(m=='\0' || bsize<=0) break;
else {*b++=m; --bsize; word=h; continue; }
} /* "{" e "}" ->"" */
else if(c=='{' || c=='}' /* elimina il carattere */
) continue;
else {
led=0;
if(c=='[') inq=1;
else if(c==']') inq=0;
h=word;
gword(buffer, &h, bsize);
if( !( is_punct(c) && inq==1) &&
(np=lookup(buffer))!=NULL )
{e=np->defn; eh=e; /* trova in lookup(buffer) */
F(; *e && bsize>0 ; )
{*b++=*e++; --bsize;}
if( *eh == '[' ) zer=1;
else if(zer==1)
{if(bsize>0)
{*b++=']'; --bsize;}
zer=0;
}
}
else { /* *non* trova in lookup(buffer) */
F(e=buffer ; *e && bsize>0 ; )
{*b++=*e++; --bsize;}
if(zer==1)
{if(bsize>0)
{*b++=']'; --bsize;}
zer=0;
}
}
if(word!=h) word=--h;
}
}
if(bsize<=0) {e="Linea troppo lunga"; goto la; }
*b='\0';
if(zen==0) *buffer=0; /* salvo il fatto che trovo ; e | */
else {*buffer=1; buffer[1]=0;}
return b-a;
}
void install_all(void)
{
installl( "a" , "eax"); installl( "b" , "ebx"); // 2
installl( "c" , "ecx"); installl( "sj" , "di"); // 4
installl( "i" , "esi"); installl( "j" , "edi"); // 6
installl( "r" , "edx"); installl( "rx" , "dx"); // 8
installl( "rl" , "dl"); installl( "rh" , "dh"); //10
installl( "s" , "esp");
installl( "k" , "ebp"); installl( "kp" , "bp");
/* col carattere di escape _ ||==or &==end **=per etc */
installl( "||" , "|");
installl( "**" , "*");
installl( "*" , "[");
installl( "## õ1" , "jmp õ1");
installl( "# õ1" , "jmp short õ1");
installl( "õ1 = õ2" , "mov õ1, õ2");
installl( "õ1 += õ2", "add õ1, õ2");
installl( "õ1 -= õ2", "sub õ1, õ2");
installl( "õ1 ++= õ2", "adc õ1, õ2");
installl( "õ1 --= õ2", "sbb õ1, õ2");
installl( "õ1 <-> õ2", "xchg õ1, õ2");
installl( "õ1 =^ õ2", "mov õ1, [ esp + õ2 ]");
installl( "õ1 = ^ õ2", "mov õ1, [ esp + õ2 ]");
installl( "^ õ1 = õ2", "mov [ esp + õ1 ], õ2");
installl( "D" , "dword");
installl( "W" , "word" );
installl( "B" , "byte" );
installl( "Q" , "qword");
installl( "T" , "tword");
installl( "õ1 <<= õ2" , "shl õ1, õ2");
installl( "õ1 >>= õ2" , "shr õ1, õ2");
installl( "õ1 <<<= õ2" , "rcl õ1, õ2");
installl( "õ1 >>>= õ2" , "rcr õ1, õ2");
installl( "õ1 & õ2" , "test õ1, õ2");
installl( "õ1 = & õ2" , "lea õ1, õ2");
installl( "õ1 =& õ2" , "lea õ1, õ2");
installl( "õ1 &= õ2" , "and õ1, õ2");
installl( "õ1 |= õ2" , "or õ1, õ2");
installl( "õ1 ^= õ2" , "xor õ1, õ2");
installl( "õ1 =* õ2" , "mov õ1, [õ2]");
installl( "< õ1" , "push õ1");// 36
installl( "> õ1" , "pop õ1");
installl( "õ1 ()" , "call õ1");
installl( "õ1 ( )" , "call õ1");
installl( "õ1 ( õ2 < )" , "call õ1");
installl( "õ1 ( õ2 <)" , "call õ1");
installl( "õ1 = õ2 ( õ3 < )" , "call õ2 \nmov õ1, õ3");
installl( "õ1 = õ2 ( õ3 <)" , "call õ2 \nmov õ1, õ3");
installl( "õ1 ( õ2 < õ3 )" , "push õ3 \ncall õ1");
installl( "õ1 = õ2 ( õ3 < õ4 )" , "push õ4 \ncall õ2\nmov õ1,
õ3");
installl( "õ1 <( õ2 < õ3 )" , "push õ3 \ncall õ1 \nadd esp,
4");
installl( "õ1 = õ2 <( õ3 < õ4 )" , "push õ4 \ncall õ2 \nadd esp,
4 \nmov õ1, õ3");
installl( "õ1 ( õ2 > õ3 , õ4 )" , "õ1 õ4");
installl( "õ1 ( õ2 > õ3 , õ4 , õ5 )" , "õ1 õ5");
installl( "õ1 = õ2 ( õ3 > õ4 , õ5 )" , "õ2 õ5 \nmov õ1,
õ3");
installl( "õ1 = õ2 ( õ3 > õ4 , õ5 , õ6 )" , "õ2 õ6 \nmov õ1,
õ3");
installl( "< õ1 , õ2" , "push õ1 \npush õ2");
installl( "> õ1 , õ2" , "pop õ2 \npop õ1");
installl( "õ1 ( õ2 < õ3 , õ4 )" , "push õ4 \npush õ3 \ncall
õ1");
installl( "õ1 = õ2 ( õ3 < õ4 , õ5 )" , "push õ5 \npush õ4 \ncall
õ2\nmov õ1, õ3");
installl( "õ1 <( õ2 < õ3 , õ4 )" , "push õ4 \npush õ3 \ncall
õ1 \nadd esp, 8");
installl( "õ1 = õ2 <( õ3 < õ4 , õ5 )" , "push õ5 \npush õ4 \ncall
õ2 \nadd esp, 8 \nmov õ1, õ3");
installl( "< õ1 , õ2 , õ3" , "push õ1 \npush õ2 \npush õ3");
installl( "> õ1 , õ2 , õ3" , "pop õ3 \npop õ2 \npop õ1");
installl( "õ1 ( õ2 < õ3 , õ4 , õ5 )" , "push õ5 \npush õ4 \npush
õ3 \ncall õ1");
installl( "õ1 = õ2 ( õ3 < õ4 , õ5 , õ6 )" ,
"push õ6 \npush õ5 \npush õ4 \ncall õ2\nmov õ1, õ3");
installl( "õ1 <( õ2 < õ3 , õ4 , õ5 )" , "push õ5 \npush õ4 \npush
õ3 \ncall õ1 \nadd esp, 12");
installl( "õ1 = õ2 <( õ3 < õ4 , õ5 , õ6 )" ,
"push õ6 \npush õ5 \npush õ4 \ncall õ2 \nadd esp, 12 \nmov
õ1, õ3");
installl( "< õ1 , õ2 , õ3 , õ4", "push õ1 \npush õ2 \npush õ3
\npush õ4");
installl( "> õ1 , õ2 , õ3 , õ4", "pop õ4 \npop õ3 \npop õ2
\npop õ1");
installl( "õ1 ( õ2 < õ3 , õ4 , õ5 , õ6 )" ,
"push õ6 \npush õ5 \npush õ4 \npush õ3 \ncall õ1");
installl( "õ1 = õ2 ( õ3 < õ4 , õ5 , õ6 , õ7 )" ,
"push õ7 \npush õ6 \npush õ5 \npush õ4 \ncall õ2\nmov õ1,
õ3");
installl( "õ1 <( õ2 < õ3 , õ4 , õ5 , õ6 )" ,
"push õ6 \npush õ5 \npush õ4 \npush õ3 \ncall õ1 \nadd
esp, 16");
installl( "õ1 = õ2 <( õ3 < õ4 , õ5 , õ6 , õ7 )" ,
"push õ7 \npush õ6 \npush õ5 \npush õ4 \ncall õ2 \nadd esp,
16 \nmov õ1, õ3");
installl( "< õ1 , õ2 , õ3 , õ4 , õ5" ,
"push õ1 \npush õ2 \npush õ3 \npush õ4 \npush õ5");
installl( "> õ1 , õ2 , õ3 , õ4 , õ5" ,
"pop õ5 \npop õ4 \npop õ3 \npop õ2 \npop õ1");
installl( "õ1 ( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 )" ,
"push õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3
\ncall õ1");
installl( "õ1 = õ2 ( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 )" ,
"push õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \ncall
õ2\nmov õ1, õ3");
installl( "õ1 <( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 )" ,
"push õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3
\ncall õ1 \nadd esp, 20");
installl( "õ1 = õ2 <( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 )" ,
"push õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \ncall õ2
\nadd esp, 20 \nmov õ1, õ3");
installl( "< õ1 , õ2 , õ3 , õ4 , õ5 , õ6" ,
"push õ1 \npush õ2 \npush õ3 \npush õ4 \npush õ5 \npush
õ6");
installl( "> õ1 , õ2 , õ3 , õ4 , õ5 , õ6" ,
"pop õ6 \npop õ5 \npop õ4 \npop õ3 \npop õ2 \npop
õ1");
installl( "õ1 ( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 , õ8 )" ,
"push õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3
\ncall õ1");
installl( "õ1 = õ2 ( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 , õ9 )" ,
"push õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4
\ncall õ2\nmov õ1, õ3");
installl( "õ1 <( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 , õ8 )" ,
"push õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3
\ncall õ1 \nadd esp, 24");
installl( "õ1 = õ2 <( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 , õ9 )" ,
"push õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4
\ncall õ2 \nadd esp, 24 \nmov õ1, õ3");
installl( "< õ1 , õ2 , õ3 , õ4 , õ5 , õ6 , õ7" ,
"push õ1 \npush õ2 \npush õ3 \npush õ4 \npush õ5 \npush õ6
\npush õ7");
installl( "> õ1 , õ2 , õ3 , õ4 , õ5 , õ6 , õ7" ,
"pop õ7 \npop õ6 \npop õ5 \npop õ4 \npop õ3 \npop õ2
\npop õ1");
installl( "õ1 ( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 )" ,
"push õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4
\npush õ3 \ncall õ1");
installl( "õ1 = õ2 ( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 )" ,
"push õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5
\npush õ4 \ncall õ2\nmov õ1, õ3");
installl( "õ1 <( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 )" ,
"push õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4
\npush õ3 \ncall õ1 \nadd esp, 28");
installl( "õ1 = õ2 <( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 )" ,
"push õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5
\npush õ4 \ncall õ2\nadd esp, 28 \nmov õ1, õ3");
installl( "õ1 ( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 )" ,
"push õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5
\npush õ4 \npush õ3 \ncall õ1");
installl( "õ1 = õ2 ( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 )"
,
"push õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6
\npush õ5 \npush õ4 \ncall õ2\nmov õ1, õ3");
installl( "õ1 <( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 )" ,
"push õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5
\npush õ4 \npush õ3 \ncall õ1 \nadd esp, 32");
installl( "õ1 = õ2 <( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 )"
,
"push õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6
\npush õ5 \npush õ4 \ncall õ2\nadd esp, 32 \nmov õ1, õ3");
installl( "õ1 ( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 )"
,
"push õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6
\npush õ5 \npush õ4 \npush õ3 \ncall õ1");
installl( "õ1 = õ2 ( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 )" ,
"push õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7
\npush õ6 \npush õ5 \npush õ4 \ncall õ2\nmov õ1, õ3");
installl( "õ1 <( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 )"
,
"push õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6
\npush õ5 \npush õ4 \npush õ3 \ncall õ1 \nadd esp, 36");
installl( "õ1 = õ2 <( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 )" ,
"push õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7
\npush õ6 \npush õ5 \npush õ4 \ncall õ2\nadd esp, 36 \nmov
õ1, õ3");
installl( "õ1 ( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 )" ,
"push õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7
\npush õ6 \npush õ5 \npush õ4 \npush õ3 \ncall õ1");
installl( "õ1 = õ2 ( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 , õ13 )" ,
"push õ13 \npush õ12 \npush õ11 \npush õ10 \npush õ9 \npush
õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \ncall õ2\nmov õ1,
õ3");
installl( "õ1 <( õ2 < õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 )" ,
"push õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7
\npush õ6 \npush õ5 \npush õ4 \npush õ3 \ncall õ1 \nadd esp,
40");
installl( "õ1 = õ2 <( õ3 < õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 )" ,
"push õ13 \npush õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8
\npush õ7 \npush õ6 \npush õ5 \npush õ4 \ncall õ2\nadd esp, 40
\nmov õ1, õ3");
/*------------------------------------------*/
installl( "õ1 = õ2 ( )" , "call õ2 \nmov õ1, eax");
installl( "õ1 = õ2 ()" , "call õ2 \nmov õ1, eax");
installl( "õ1 ( õ2 )" , "push õ2 \ncall õ1");
installl( "õ1 = õ2 ( õ3 )" , "push õ3 \ncall õ2 \nmov õ1, eax");
installl( "õ1 <( õ2 )" , "push õ2 \ncall õ1\nadd esp, 4");
installl( "õ1 = õ2 <( õ3 )" , "push õ3 \ncall õ2\nadd esp,
4\nmov õ1, eax");
installl( "õ1 ( õ2 , õ3 )" , "push õ3 \npush õ2 \ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 )" , "push õ4 \npush õ3 \ncall
õ2\nmov õ1, eax");
installl( "õ1 <( õ2 , õ3 )" , "push õ3 \npush õ2 \ncall
õ1\nadd esp, 8");
installl( "õ1 = õ2 <( õ3 , õ4 )" , "push õ4 \npush õ3 \ncall
õ2\nadd esp, 8\nmov õ1, eax");
installl( "õ1 ( õ2 , õ3 , õ4 )" , "push õ4 \npush õ3 \npush
õ2 \ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 , õ5 )" , "push õ5 \npush õ4 \npush
õ3 \ncall õ2\nmov õ1, eax");
installl( "õ1 <( õ2 , õ3 , õ4 )" , "push õ4 \npush õ3 \npush
õ2 \ncall õ1\nadd esp, 12");
installl( "õ1 = õ2 <( õ3 , õ4 , õ5 )" , "push õ5 \npush õ4 \npush
õ3 \ncall õ2\nadd esp, 12\nmov õ1, eax");
installl( "õ1 ( õ2 , õ3 , õ4 , õ5 )" ,
"push õ5 \npush õ4 \npush õ3 \npush õ2 \ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 , õ5 , õ6 )" ,
"push õ6 \npush õ5 \npush õ4 \npush õ3 \ncall õ2\nmov õ1,
eax");
installl( "õ1 <( õ2 , õ3 , õ4 , õ5 )" ,
"push õ5 \npush õ4 \npush õ3 \npush õ2 \ncall õ1 \nadd
esp, 16");
installl( "õ1 = õ2 <( õ3 , õ4 , õ5 , õ6 )" ,
"push õ6 \npush õ5 \npush õ4 \npush õ3 \ncall õ2 \nadd esp,
16 \nmov õ1, eax");
installl( "õ1 ( õ2 , õ3 , õ4 , õ5 , õ6 )" ,
"push õ6 \npush õ5 \npush õ4 \npush õ3 \npush õ2
\ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 , õ5 , õ6 , õ7 )" ,
"push õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3 \ncall
õ2\nmov õ1, eax");
installl( "õ1 <( õ2 , õ3 , õ4 , õ5 , õ6 )" ,
"push õ6 \npush õ5 \npush õ4 \npush õ3 \npush õ2
\ncall õ1 \nadd esp, 20");
installl( "õ1 = õ2 <( õ3 , õ4 , õ5 , õ6 , õ7 )" ,
"push õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3 \ncall õ2
\nadd esp, 20 \nmov õ1, eax");
installl( "õ1 ( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 )" ,
"push õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3 \npush õ2
\ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 )" ,
"push õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3
\ncall õ2\nmov õ1, eax");
installl( "õ1 <( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 )" ,
"push õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3 \npush õ2
\ncall õ1 \nadd esp, 24");
installl( "õ1 = õ2 <( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 )" ,
"push õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3
\ncall õ2 \nadd esp, 24 \nmov õ1, eax");
installl( "õ1 ( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 )" ,
"push õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3
\npush õ2 \ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 )" ,
"push õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4
\npush õ3 \ncall õ2\nmov õ1, eax");
installl( "õ1 <( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 )" ,
"push õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3
\npush õ2 \ncall õ1 \nadd esp, 28");
installl( "õ1 = õ2 <( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 )" ,
"push õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4
\npush õ3 \ncall õ2\nadd esp, 28 \nmov õ1, eax");
installl( "õ1 ( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 )" ,
"push õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4
\npush õ3 \npush õ2 \ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 )" ,
"push õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5
\npush õ4 \npush õ3 \ncall õ2\nmov õ1, eax");
installl( "õ1 <( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 )" ,
"push õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4
\npush õ3 \npush õ2 \ncall õ1 \nadd esp, 32");
installl( "õ1 = õ2 <( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 )" ,
"push õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5
\npush õ4 \npush õ3 \ncall õ2\nadd esp, 32 \nmov õ1, eax");
installl( "õ1 ( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 )" ,
"push õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5
\npush õ4 \npush õ3 \npush õ2 \ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 )"
,
"push õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6
\npush õ5 \npush õ4 \npush õ3 \ncall õ2\nmov õ1, eax");
installl( "õ1 <( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 )" ,
"push õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5
\npush õ4 \npush õ3 \npush õ2 \ncall õ1 \nadd esp, 36");
installl( "õ1 = õ2 <( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 )"
,
"push õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6
\npush õ5 \npush õ4 \npush õ3 \ncall õ2\nadd esp, 36 \nmov
õ1, eax");
installl( "õ1 ( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 )"
,
"push õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6
\npush õ5 \npush õ4 \npush õ3 \npush õ2 \ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 )" ,
"push õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7
\npush õ6 \npush õ5 \npush õ4 \npush õ3 \ncall õ2\nmov õ1,
eax");
installl( "õ1 <( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 )"
,
"push õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7 \npush õ6
\npush õ5 \npush õ4 \npush õ3 \npush õ2 \ncall õ1 \nadd esp,
40");
installl( "õ1 = õ2 <( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 )" ,
"push õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7
\npush õ6 \npush õ5 \npush õ4 \npush õ3 \ncall õ2\nadd esp, 40
\nmov õ1, eax");
installl( "õ1 ( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 )" ,
"push õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7
\npush õ6 \npush õ5 \npush õ4 \npush õ3 \npush õ2 \ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 , õ13 )" ,
"push õ13 \npush õ12 \npush õ11 \npush õ10 \npush õ9 \npush
õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3 \ncall
õ2\nmov õ1, eax");
installl( "õ1 <( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 )" ,
"push õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8 \npush õ7
\npush õ6 \npush õ5 \npush õ4 \npush õ3 \npush õ2 \ncall õ1
\nadd esp, 44");
installl( "õ1 = õ2 <( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 , õ13 )" ,
"push õ13 \npush õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8
\npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3 \ncall õ2\nadd
esp, 44 \nmov õ1, eax");
installl( "õ1 ( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 , õ13 )" ,
"push õ13 \npush õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8
\npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3 \npush õ2
\ncall õ1");
installl( "õ1 = õ2 ( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 , õ13 , õ14 )" ,
"push õ14 \npush õ13 \npush õ12 \npush õ11 \npush õ10 \npush
õ9 \npush õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3
\ncall õ2\nmov õ1, eax");
installl( "õ1 <( õ2 , õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 , õ13 )" ,
"push õ13 \npush õ12 \npush õ11 \npush õ10 \npush õ9 \npush õ8
\npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3 \npush õ2
\ncall õ1 \nadd esp, 48");
installl( "õ1 = õ2 <( õ3 , õ4 , õ5 , õ6 , õ7 , õ8 , õ9 , õ10 , õ11 ,
õ12 , õ13 , õ14 )" ,
"push õ14 \npush õ13 \npush õ12 \npush õ11 \npush õ10 \npush õ9
\npush õ8 \npush õ7 \npush õ6 \npush õ5 \npush õ4 \npush õ3
\ncall õ2\nadd esp, 48 \nmov õ1, eax");
/*------------------------------------------*/
installl( "++ õ1" , "inc õ1 ");
installl( "-- õ1" , "dec õ1 "); /* --[a+si]*/
installl( "++ õ1 , õ2" , "inc õ1 \ninc õ2 ");
installl( "-- õ1 , õ2" , "dec õ1 \ndec õ2 ");
installl( "++ õ1 , õ2 , õ3" , "inc õ1 \ninc õ2 \ninc õ3 ");
installl( "-- õ1 , õ2 , õ3" , "dec õ1 \ndec õ2 \ndec õ3 ");
installl( "++ õ1 , õ2 , õ3 , õ4" ,
"inc õ1 \ninc õ2 \ninc õ3 \ninc õ4 ");
installl( "-- õ1 , õ2 , õ3 , õ4" ,
"dec õ1 \ndec õ2 \ndec õ3 \ndec õ4 ");
installl( "-- õ1 # õ2" , "dec õ1 \njnz õ2 ");
installl( "-- õ1 !# õ2" , "dec õ1 \njz õ2 ");
installl( "õ1 <> õ2", "cmp õ1, õ2 ");
installl( "õ1 # õ2" , "cmp õ1, 0 \njne õ2");
installl( "õ1 !# õ2" , "cmp õ1, 0 \nje õ2");
installl( "õ1 < õ2 # õ3" , "cmp õ1, õ2 \njb õ3 "); /* numeri
senza segno */
installl( "õ1 & õ2 # õ3" , "test õ1, õ2 \njnz õ3 ");
installl( "õ1 > õ2 # õ3" , "cmp õ1, õ2 \nja õ3 ");
installl( "õ1 <= õ2 # õ3", "cmp õ1, õ2 \njbe õ3 ");
installl( "õ1 >= õ2 # õ3", "cmp õ1, õ2 \njae õ3 ");
installl( "õ1 == õ2 # õ3", "cmp õ1, õ2 \nje õ3 ");
installl( "õ1 != õ2 # õ3", "cmp õ1, õ2 \njne õ3 ");
installl( "õ1 >= õ2 !# õ3" , "cmp õ1, õ2 \njb õ3 ");
installl( "õ1 <= õ2 !# õ3" , "cmp õ1, õ2 \nja õ3 ");
installl( "õ1 > õ2 !# õ3" , "cmp õ1, õ2 \njbe õ3 ");
installl( "õ1 & õ2 !# õ3" , "test õ1, õ2 \njz õ3 ");
installl( "õ1 < õ2 !# õ3" , "cmp õ1, õ2 \njae õ3 ");
installl( "õ1 != õ2 !# õ3" , "cmp õ1, õ2 \nje õ3 ");
installl( "õ1 == õ2 !# õ3" , "cmp õ1, õ2 \njne õ3 ");
installl( "õ1 < õ2 ?# õ3" , "cmp õ1, õ2 \njl õ3 "); /* numeri
col segno */
installl( "õ1 > õ2 ?# õ3" , "cmp õ1, õ2 \njg õ3 ");
installl( "õ1 <= õ2 ?# õ3", "cmp õ1, õ2 \njle õ3 ");
installl( "õ1 >= õ2 ?# õ3", "cmp õ1, õ2 \njge õ3 ");
installl( "õ1 == õ2 ?# õ3", "cmp õ1, õ2 \nje õ3 ");
installl( "õ1 != õ2 ?# õ3", "cmp õ1, õ2 \njne õ3 ");
installl( "õ1 >= õ2 ?!# õ3" , "cmp õ1, õ2 \njl õ3 ");
installl( "õ1 <= õ2 ?!# õ3" , "cmp õ1, õ2 \njg õ3 ");
installl( "õ1 > õ2 ?!# õ3" , "cmp õ1, õ2 \njle õ3 ");
installl( "õ1 < õ2 ?!# õ3" , "cmp õ1, õ2 \njge õ3 ");
installl( "õ1 != õ2 ?!# õ3" , "cmp õ1, õ2 \nje õ3 ");
installl( "õ1 == õ2 ?!# õ3" , "cmp õ1, õ2 \njne õ3 ");
installl( "õ1 = õ2 + õ3", "mov õ1, õ2 \nadd õ1, õ3 ");
installl( "õ1 = õ2 - õ3", "mov õ1, õ2 \nsub õ1, õ3 "); /* 143
*/
/* label: istruzione = istruzione \0 commento
*/
installl( "=# õ1" , "je õ1 "); /* numeri senza segno */
installl( "<# õ1" , "jb õ1 ");
installl( "># õ1" , "ja õ1 ");
installl( "<=# õ1", "jbe õ1 ");
installl( ">=# õ1", "jae õ1 ");
installl( "=?# õ1" , "je õ1 ");
installl( "<?# õ1" , "jl õ1 "); /* numeri con segno */
installl( ">?# õ1" , "jg õ1 ");
installl( "<=?# õ1", "jle õ1 ");
installl( ">=?# õ1", "jge õ1 "); /* 155 */
installl( "!=# õ1" , "jne õ1 ");
installl( "!<# õ1" , "jae õ1 "); /* numeri senza segno */
installl( "!># õ1" , "jbe õ1 ");
installl( "!<=# õ1", "ja õ1 ");
installl( "!>=# õ1", "jb õ1 ");
installl( "!=?# õ1" , "jne õ1 ");
installl( "!<?# õ1" , "jge õ1 "); /* numeri con segno */
installl( "!>?# õ1" , "jle õ1 ");
installl( "!<=?# õ1", "jg õ1 ");
installl( "!>=?# õ1", "jl õ1 "); /* 165 */
installl( "( õ1 , õ2 ) <<= õ3", "shld õ1, õ2, õ3 ");
installl( "( õ1 , õ2 ) >>= õ3", "shrd õ1, õ2, õ3 ");
installl( "( õ1 , õ2 )<<= õ3", "shld õ1, õ2, õ3 ");
installl( "( õ1 , õ2 )>>= õ3", "shrd õ1, õ2, õ3 ");
installl( "<< õ1 = õ2", "%define õ1 õ2");
installl( ">> õ1" , "%undef õ1" );
installl( "<< õ1 = õ2 , õ3 = õ4", "%define õ1 õ2 \n%define õ3 õ4
");
installl( ">> õ1 , õ2", "%undef õ1 \n%undef õ2 " );
installl( "<< õ1 = õ2 , õ3 = õ4 , õ5 = õ6",
"%define õ1 õ2 \n%define õ3 õ4 \n%define õ5 õ6 ");
installl( ">> õ1 , õ2 , õ3", "%undef õ1 \n%undef õ2 \n%undef õ3 "
);
installl( "<< õ1 = õ2 , õ3 = õ4 , õ5 = õ6 , õ7 = õ8",
"%define õ1 õ2 \n%define õ3 õ4 \n%define õ5 õ6 \n%define õ7
õ8");
installl( ">> õ1 , õ2 , õ3 , õ4",
"%undef õ1 \n%undef õ2 \n%undef õ3 \n%undef õ4 " );
installl( "<< õ1 = õ2 , õ3 = õ4 , õ5 = õ6 , õ7 = õ8 , õ9 = õ10",
"%define õ1 õ2 \n%define õ3 õ4 \n%define õ5 õ6 \n%define õ7 õ8
\n%define õ9 õ10");
installl( ">> õ1 , õ2 , õ3 , õ4 , õ5",
"%undef õ1 \n%undef õ2 \n%undef õ3 \n%undef õ4 \n%undef õ5 ");
installl( "<< õ1 = õ2 , õ3 = õ4 , õ5 = õ6 , õ7 = õ8 , õ9 = õ10 , õ11
= õ12",
"%define õ1 õ2 \n%define õ3 õ4 \n%define õ5 õ6 \n%define õ7 õ8
\n%define õ9 õ10 \n%define õ11 õ12 ");
installl( ">> õ1 , õ2 , õ3 , õ4 , õ5 , õ6",
"%undef õ1 \n%undef õ2 \n%undef õ3 \n%undef õ4 \n%undef õ5
\n%undef õ6 ");
installl( "<< õ1 = õ2 , õ3 = õ4 , õ5 = õ6 , õ7 = õ8 , õ9 = õ10 , õ11
= õ12 , õ13 = õ14",
"%define õ1 õ2 \n%define õ3 õ4 \n%define õ5 õ6 \n%define õ7 õ8
\n%define õ9 õ10 \n%define õ11 õ12 \n%define õ13 õ14 ");
installl( ">> õ1 , õ2 , õ3 , õ4 , õ5 , õ6 , õ7",
"%undef õ1 \n%undef õ2 \n%undef õ3 \n%undef õ4 \n%undef õ5
\n%undef õ6 \n%undef õ7 ");
installl("== õ1 == õ2", "extern õ1 \nimport õ1 õ2 ");
installl("== õ1 , õ2 == õ3",
"extern õ1, õ2 \nimport õ1 õ3 \nimport õ2 õ3 ");
installl("== õ1 , õ2 , õ3 == õ4",
"extern õ1, õ2, õ3 \nimport õ1 õ4 \nimport õ2 õ4 \nimport õ3
õ4 ");
installl("== õ1 , õ2 , õ3 , õ4 == õ5",
"extern õ1, õ2, õ3, õ4 \nimport õ1 õ5 \nimport õ2 õ5 \nimport
õ3 õ5 \nimport õ4 õ5 ");
installl("== õ1 , õ2 , õ3 , õ4 , õ5 == õ6",
"extern õ1, õ2, õ3, õ4, õ5 \nimport õ1 õ6 \nimport õ2 õ6
\nimport õ3 õ6 \nimport õ4 õ6 \nimport õ5 õ6 ");
installl( "õ1 , õ2 = õ3" , "[section .data] \nõ2 õ1 õ3 , 0
\n__SECT__ ");
installl( "õ1 , õ2 = õ3 , õ4 = õ5" , "[section .data] \nõ2 õ1 õ3 ,
0 \nõ4 õ1 õ5 , 0 \n__SECT__ ");
installl( "õ1 , õ2 = õ3 , õ4 = õ5 , õ6 = õ7" ,
"[section .data] \nõ2 õ1 õ3 , 0 \nõ4 õ1 õ5 , 0 \nõ6 õ1 õ7
, 0 \n__SECT__ ");
installl( "õ1 , õ2 = õ3 , õ4 = õ5 , õ6 = õ7 , õ8 = õ9" ,
"[section .data] \nõ2 õ1 õ3 , 0 \nõ4 õ1 õ5 , 0 \nõ6 õ1 õ7 , 0
\nõ8 õ1 õ9 , 0 \n__SECT__ ");
installl( "õ1 , õ2 = õ3 , õ4 = õ5 , õ6 = õ7 , õ8 = õ9 , õ10 = õ11" ,
"[section .data] \nõ2 õ1 õ3 , 0 \nõ4 õ1 õ5 , 0 \nõ6 õ1 õ7 , 0
\nõ8 õ1 õ9 , 0 \nõ10 õ1 õ11 , 0 \n__SECT__ ");
installl( "õ1 , õ2 = õ3 , õ4 = õ5 , õ6 = õ7 , õ8 = õ9 , õ10 = õ11 ,
õ12 = õ13" ,
"[section .data] \nõ2 õ1 õ3 ,0 \nõ4 õ1 õ5 ,0 \nõ6 õ1 õ7 ,0 \nõ8 õ1 õ9
,0 \nõ10 õ1 õ11 ,0 \nõ12 õ1 õ13 ,0 \n__SECT__ ");
}
#define MAXW 2048 /* Massima lunghezza linea trattabile */
#define MAXP 512 /* Massimo numero di parole per linea */
int main(int x, char** a)
{int linea, led;
char word[MAXW], **ch, *in, *out, *nl;
struct nlist *np;
FILE *f_in, *f_out;
if(x!=0 && a!=0 && a[0]!=0) argomento=a[0]; /* per assert_m */
else argomento="prog";
if( !(x==3) && !( x==4 && a[1][0]=='-' && a[1][1]=='l' ) )
{P("USO:\n>nome_prog [-l] nome_file_in nome_file_out\n"); R
0;}
if(x==4) { in=a[2]; out=a[3]; led=1; }
else { in=a[1]; out=a[2]; led=0; }
nome_file=estrai(in);
if( (ch=malloc(MAXP * sizeof *ch) )== NULL)
{ P("Scarsa memoria! Esco\n"); R 1; }
if(strcmp(in, "stdin")!=0)
{if((f_in=fopen(in,"r"))==NULL)
{printf("\n ERRORE, impossibile leggere il file %s\n", a[1]);
free(ch);
return 1;
}
}
else f_in=stdin;
if(strcmp(out, "stdout")!=0)
{if((f_out=fopen(out,"w"))==NULL)
{printf("\n ERRORE, impossibile scrivere il file %s\n", a[2]);
fclose(f_in); free(ch);
return 1;
}
}
else f_out=stdout;
allUscita(1, f_in, f_out, ch); install_all();
linea=1;
while( (nl=fgets_p(word, sizeof word, f_in)) != NULL )
{char buf[MAXW], bufr[MAXW], word1[MAXW], *b, *bf, *comm, *u, *v,
*h, za;
int i, j, t, alias_nl;
char fmt[7+11+32+10+10], ne[32+10]="", *pointer;
micro_s(buf, MAXW, word, &comm, bufr);
alias_nl= *bufr; t=0;
if(led && linea<10000000 )
{t = sprintf(fmt, "%%line %u %.30s\n", linea-1, nome_file);
}
else if(led && linea>=10000000)
{ assert_m(linea>=10000000, "File troppo lungo" ); }
/* Per la macro assert_m gli if *non* sono sicuri */
else *fmt='\0';
*ne='\0';
b=buf; bf=NULL; j=0;
W( ( i=get_token(&bf, &b) ) != '\0')
{char inizio_linea;
macro_s(bufr, sizeof bufr, bf, ch, MAXP);
if((np=lookup(bufr))!=NULL)
strncpy(bufr, np->defn, MAXW);
if( np!=0 || alias_nl!=0 ) pointer = fmt;
else pointer = ne;
inizio_linea=*bufr;
/* j==0 && qui sotto */
if( j==0 && i!=':' && ( comm==NULL || inizio_linea!='\0') )
{t += catstr(pointer, " ", MAXW-t); }
label:
if(t>=MAXW) P("Lunghezza linea attuale> t = %d\n", t );
assert_m(MAXW>t, "Linea troppo lunga");
macro_sinv(word1, (sizeof word1)-t, bufr, bf, ch, MAXP);
v=word1; h=bufr;
W(1)
{u = pointer;
W( ++t<MAXW && (*h++=*u++) );
--h; --t;
W( ++t<MAXW && ( za=(*h++=*v++) ) && za!='\n');
if( za!='\n' || t>=MAXW )
{--h; *h++='\n'; *h='\0'; break;}
}
if(t>= MAXW) goto label;
if( !(j==0 && comm!=NULL) )
fputs(bufr, f_out);
else /* commenti /, %, section */
{--h; --t;
u = *comm=='/' && inizio_linea!=0 ? " ;" : /*
commento dopo un comando */
*comm=='/' && inizio_linea==0 ? ";" : /*
commento in inizio linea */
*comm=='%' ? "%" : ""; /* % o
altrimenti */
W( ++t<MAXW && (*h++=*u++) );
--h; /* se t<MAXW --h->'\0' */
u= *comm=='%'||(*comm=='/' && comm[1]!='*') ? comm+1 :
*comm=='/' && comm[1]=='*' ? comm+2 :
comm;
W( ++t<MAXW && (*h++=*u++) );
if(t>= MAXW) goto label;
fputs(bufr, f_out);
}
++j; /* j=0 allora metto il commento altrimenti niente */
}
if( *nl=='\n' ) ++linea;
}
fclose(f_in);
fclose(f_out);
free_tab();
free(ch);
R 0;
}
void allUscita(int flag, FILE* f_in, FILE* f_out, char** ch)
{static FILE *f_inn=0, *f_outt=0;
static char **chh=0;
if(flag==1) /* Aggiorna */
{f_inn=f_in; f_outt=f_out; chh=ch;}
else {free(chh);
if(f_inn!=0 ) fclose(f_inn);
if(f_outt!=0) fclose(f_outt);
free_tab();
}
}
#define BUFSIZE 256
char buf[BUFSIZE];
int bufp= 0;
int getch(FILE* pnt)
{static int led = EOF+1;
R (bufp>0) ? buf[--bufp] :
led!=EOF ? led=fgetc(pnt) : EOF;
}
void ungetch(char c)
{assert_m(bufp<BUFSIZE, "ungetch: troppi caratteri");
buf[bufp++]=c;
}
- Next message: Betov: "Re: a 'turbo' assembly language"
- Previous message: Phil Carmody: "Re: [ Attn: Randy ] Ad-hoc Parsing?"
- Next in thread: Betov: "Re: a 'turbo' assembly language"
- Reply: Betov: "Re: a 'turbo' assembly language"
- Reply: Randall Hyde: "Re: a 'turbo' assembly language"
- Reply: C: "Re: a 'turbo' assembly language"
- Maybe reply: Betov: "Re: a 'turbo' assembly language"
- Maybe reply: Betov: "Re: a 'turbo' assembly language"
- Maybe reply: Betov: "Re: a 'turbo' assembly language"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|