From cbc3654fbb3e22bed10349c7e3f9d63823f11573 Mon Sep 17 00:00:00 2001 From: codecyang Date: Wed, 8 Jul 2020 21:54:07 +0800 Subject: [PATCH] Build the first stage of the Hack Assembler which assemble symbol-less version of .asm program. --- assembler/src/java/Assembler.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/assembler/src/java/Assembler.java b/assembler/src/java/Assembler.java index 099e864..ed0c1e0 100644 --- a/assembler/src/java/Assembler.java +++ b/assembler/src/java/Assembler.java @@ -29,9 +29,10 @@ public static void main(String[] args) throws IOException{ String line = ""; parser.advance(); if(parser.commandType() == Parser.CommandType.A_COMMAND - || parser.commandType() == Parser.CommandType.L_COMMAND) - line = parser.symbol(); - else if(parser.commandType() == Parser.CommandType.C_COMMAND){ + || parser.commandType() == Parser.CommandType.L_COMMAND){ + int i = Integer.valueOf(parser.symbol()) & 0xffff; + line = "0" + String.format("%15s", Integer.toBinaryString(i)).replaceAll("\\s", "0"); + }else if(parser.commandType() == Parser.CommandType.C_COMMAND){ String c = parser.comp(); String d = parser.dest(); String j = parser.jump();