Académique Documents
Professionnel Documents
Culture Documents
Main(){
X = a*2+ (b-5)/3 ;
write(x)
Aphons
CMOVE(pile, SP)
BR(début)
(Date)
Début(Code)
CALL(main) HALT()
Instruction :
LD(a,RO) met en sommet de pile la valeur de a dans RO puis PUSH(RO) a dans la Stack
CMOVE(2,RO) PUSH(R0) 2
LD(b,R0) PUSH(R0) b
CMOVE(5,R0) PUSH(R0) 5
DIV(R1,R2,R3) PUSH(R3) -
POP(R0) ST(RO,x) = *
If (a>b){
X= 1000 ;
{else }
x=2000 ;
Input arbre
compare:
LD(a,R0)
PUSH(R0)
LD(b,R0)
PUSH(R0)
POP(R2)
POP(R1)
CMPLT(R2,R1,R3)
PUSH(R3)
else:
LD(2000,x)
LD(x,r0)
PUSH(R0)
POP(r0)
fsi:
LD(1000,x)
LD(x,r0)
POP(r0)
int x;
void f(){
x = 15;
void main(){
f();
x=x+1
debut: |Exercice 5
x : LONG(15)
function:
LD(x,R0)
ADD(x,15,R0)
PUSH(R0)
POP(R0)
void_main:
CALL(function)
LD(x,1,x)
max = 0;
p = first;
start: ADDC(r31,0,max) | Exercice 7 Maximum dans un tableau
ADDC(r31,first,p)
ADDC(r31,n,i)
loop: BEQ(i,done,r31)
LD(p,0,value)
CMPLT(max,value,r0)
BEQ(r0,endif,r31)
ADDC(value,0,max)
endif: ADDC(p, 4, p)
SUBC(i,1,i)
BEQ(r31,loop,r31)
Done:
int x;
void f(){
x = 15;
void main(){
f();
x=x+1
debut: |Exercice 5
x : LONG(15)
function:
LD(x,R0)
ADD(x,15,R0)
PUSH(R0)
POP(R0)
void_main:
CALL(function)
LD(x,1,x)
max = 0;
p = first;
ADDC(r31,first,p)
ADDC(r31,n,i)
loop: BEQ(i,done,r31)
LD(p,0,value)
CMPLT(max,value,r0)
BEQ(r0,endif,r31)
ADDC(value,0,max)
endif: ADDC(p, 4, p)
SUBC(i,1,i)
BEQ(r31,loop,r31)
Done
Algo : générer-prog Intput= arbre tds= table des symboles → output=code Assembleur
pour chaque fils(a) for res +←generat-fonction(f) finPour res +←PILE Fin
Algo : genereate-data prog Intput tds= table des symboles → output res =code Assembleur
Début pour each item de tds faire si item cat = global alors res +←item : LONG(item.val) fin
res +← Generate-expression (FilsDroit(a))
res +← POP (R0) ST(R0) FilsGauche(a).val.idf avec idf qui se trouve dans data variable globale
début cas1…….cas 7 Appel RDINT(lit un entier) stocker dans R0 et le lire dans la pile PUSH(R0)
void main{
a=f(1,2) ;
Int x;
x= i+j ;
return (x+10),