Skip to content

Commit d64aafb

Browse files
committed
Adding other example
1 parent e714721 commit d64aafb

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

a.bin

-42 Bytes
Binary file not shown.

b.bin

Whitespace-only changes.

simpleTest

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//Simple program that adds 1 and then 2 to the register 0x00
2+
ADD 0xFF01 0xFF00 0x0000
3+
PRNT 0x0000 0x0000 0x0000
4+
ADD 0xFF01 0x0000 0x0000
5+
PRNT 0x0000 0x0000 0x0000

src/main/java/org/example/Main.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ public static byte[] compilar(String arquivo){
4545

4646
String[] linhas = arquivo.split("\n");
4747
for(String linha : linhas){
48+
49+
if(linha.contains("//"))
50+
continue;
51+
4852
System.out.println("Linha sendo processada: "+linha);
49-
String[] elementos = linha.split(" ");
53+
String[] elementos = linha.split("\\s+");
5054
if(elementos.length != 4)
5155
return null;
5256
String opcodeString = elementos[0];
@@ -108,7 +112,9 @@ public static void main(String[] args) {
108112

109113
String arquivo = lerArquivo(nomeArquivo);
110114
try (FileOutputStream f = new FileOutputStream("a.bin")){
111-
f.write(compilar(arquivo));
115+
byte[] bytesToWrite = compilar(arquivo);
116+
if(bytesToWrite != null)
117+
f.write(bytesToWrite);
112118
} catch (IOException e) {
113119
throw new RuntimeException(e);
114120
}

0 commit comments

Comments
 (0)