-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomp.py
48 lines (39 loc) · 952 Bytes
/
comp.py
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
42
43
44
45
46
47
48
from assembly import assembly
source=""
def compile(code):
global source
source = code
z = assembly(code.upper().split('\n'))
print(code)
print("[",z,"]")
return z.encode()
def stub():
code = f"""
; Initialisation des registres
MOV R0, #0 ; Initialisation de R0 à 0
MOV R1, #1 ; Initialisation de R1 à 1
MOV R2, #0 ; Initialisation de R2 à 0
MOV R3, #0 ; Initialisation de R3 à 0
MOV R4, #1 ; Initialisation de R4 à 1
; Si n est égal à 0, on retourne 0
CMP R5, R0
JZA END
; Si n est égal à 1, on retourne 1
CMP R5, R1
MOV R0, #1
JZA END
FIB_LOOP:
ADD R0, R1, R2 ; R0 = R1 + R2 F(n) = F(n-1) + F(n-2)
MOV R1, R2 ; R2 = R1 F(n-2)=F(n-1)
MOV R2, R0 ; R1 = R0 F(n-1)=F(n)
ADD R3, R3, R4 ; Incrémentation du compteur
CMP R3, R5
JZA END
CMP R0,R0
JA FIB_LOOP ; le compteur est < à n, on continue la boucle
; Fin du programme
END:
STP
"""
return compile(code)
stub()