Skip to content

Commit 18c8f42

Browse files
authored
Merge pull request #8 from IagoMendes/v3.0
V3.0.1
2 parents 50dee7e + 8aff3a3 commit 18c8f42

File tree

8 files changed

+449
-121
lines changed

8 files changed

+449
-121
lines changed

Diff for: Classes/compiler.py

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
class Compiler():
2+
string = """SYS_EXIT equ 1
3+
SYS_READ equ 3
4+
SYS_WRITE equ 4
5+
STDIN equ 0
6+
STDOUT equ 1
7+
True equ 1
8+
False equ 0
9+
10+
segment .data
11+
12+
segment .bss
13+
res RESB 1
14+
15+
section .text
16+
global _start
17+
18+
print : ; subrotina print
19+
PUSH EBP ; guarda o base pointer
20+
MOV EBP, ESP ; estabelece um novo base pointer
21+
MOV EAX, [EBP+8] ; 1 argumento antes do RET e EBP
22+
XOR ESI , ESI
23+
24+
print_dec : ; empilha todos os digitos
25+
MOV EDX, 0
26+
MOV EBX, 0x000A
27+
DIV EBX
28+
ADD EDX, '0 '
29+
PUSH EDX
30+
INC ESI ; contador de digitos
31+
CMP EAX, 0
32+
JZ print_next ; quando acabar pula
33+
JMP print_dec
34+
35+
print_next :
36+
CMP ESI , 0
37+
JZ print_exit ; quando acabar de imprimir
38+
DEC ESI
39+
MOV EAX, SYS_WRITE
40+
MOV EBX, STDOUT
41+
POP ECX
42+
MOV [res] , ECX
43+
MOV ECX, res
44+
MOV EDX, 1
45+
INT 0x80
46+
JMP print_next
47+
48+
print_exit :
49+
POP EBP
50+
RET
51+
52+
; subrotinas if / while
53+
binop_je :
54+
JE binop_true
55+
JMP binop_false
56+
57+
binop_jg :
58+
JG binop_true
59+
JMP binop_false
60+
61+
binop_jl :
62+
JL binop_true
63+
JMP binop_false
64+
65+
binop_false :
66+
MOV EBX, False
67+
JMP binop_exit
68+
69+
binop_true :
70+
MOV EBX, True
71+
72+
binop_exit :
73+
RET
74+
75+
_start :
76+
PUSH EBP ; guarda o base pointer
77+
MOV EBP, ESP ; estabelece um novo base pointer
78+
79+
"""
80+
81+
@staticmethod
82+
def newInstruction(new):
83+
Compiler.string += new + '\n'
84+
85+
@staticmethod
86+
def writeFile():
87+
Compiler.newInstruction("""; interrupcao de saida
88+
POP EBP
89+
MOV EAX, 1
90+
INT 0x80""")
91+
92+
with open("julia.asm", "w") as file:
93+
file.write(Compiler.string)

0 commit comments

Comments
 (0)