Gerador de assembly para o cpu Z01 feito em Elementos de Sistemas.
nasmSim_GUI - É o código para o simulador de assembly.
This repository contains a Python script for translating a custom high-level programming language into the assembly language used by the Z01 CPU, developed in Elementos de Sistemas course. This README will guide you through understanding the structure of the translator, how to use it, and how to write code in the custom language that can be compiled into assembly.
The custom language supports variable assignment, arithmetic operations, logical operations, control flow (if statements, while loops), and functions. Here's a guide on how to write code in this language.
Variables are assigned using the = operator:
A = 5
B = A
You can perform basic arithmetic operations:
- Addition:
+ - Subtraction:
-
C = A + B
D = A - 3
You can use logical operations for conditional checks:
- AND:
& - OR:
|
E = A & B
F = A | B
If statements check a condition and execute a function if the condition is true:
if A > B: someFunction
Supported comparison operators:
- Equal:
== - Not equal:
!= - Greater than:
> - Less than:
< - Greater than or equal:
>= - Less than or equal:
<=
While loops repeatedly execute a block of code as long as the condition is true:
while A > 0 {
A = A - 1
}
Define functions using the def keyword. Functions must have a unique name and be enclosed in curly braces {}:
def myFunction {
// Function code here
}
Call a function using its name followed by ():
myFunction()
A = 5
C = A - 1
def fact {
while C > 1 {
B = C
Copia = A
multi()
C = C - 1
}
}
def multi {
while B > 1 {
A = A + Copia
B = B - 1
}
}
fact()
A = 10
B = 2
resultado = 0
def sub1 {
resultado = resultado - 1
}
def divisao {
while A > 0 {
A = A - B
resultado = resultado + 1
if A < 0: sub1
}
}
divisao()