From 34645bfe141650f123e63cc860b0ce1896840a24 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 22 Jun 2020 17:09:01 +0200 Subject: [PATCH] Add comments --- parser/program_parser.go | 3 +++ programs/storage.hal | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/parser/program_parser.go b/parser/program_parser.go index 846f89f..c4a9594 100644 --- a/parser/program_parser.go +++ b/parser/program_parser.go @@ -34,6 +34,9 @@ func ParseFile(filepath string) (hal.Program, error) { func ParseProgram(input []string) (hal.Program, error) { program := make(hal.Program) for index, line := range input { + if len(line) == 0 || line[0] == '#' { + continue + } args := strings.Split(line, " ") if len(args) <= 1 { continue diff --git a/programs/storage.hal b/programs/storage.hal index 569b7a0..3b046b0 100644 --- a/programs/storage.hal +++ b/programs/storage.hal @@ -1,16 +1,22 @@ 0001 START -# Init counter -0002 LOADIND 1 -0003 DIVNUM 2 -0004 STOREIND +# Counter +0002 LOADNUM 0 +0003 STORE 1 -# counter++ -0009 LOAD 1 +# Max +0004 LOADNUM 65536 +0005 STORE 2 + +# Loop +0006 LOAD 1 +0007 DIVNUM 2 +0008 STOREIND 1 +0009 MULNUM 2 0010 ADDNUM 1 0011 STORE 1 -# loop -0011 JUMP 0002 +0012 SUB 2 +0013 JUMPNEG 0006 1000 DUMPREG 1010 DUMPPROG