Skip to content

Commit 7e4b789

Browse files
committed
Fix several issues with project assembly
Version 2.0.0 RC1
1 parent 4bd7c8d commit 7e4b789

File tree

9 files changed

+133
-32
lines changed

9 files changed

+133
-32
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ignore build artifacts
22
*.o
33
laser
4-
laser.exe
4+
laser-*
55

66
# ignore test files
77
*.txt

README.md

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,33 @@ and LC3Edit through new pseudoops, along with a project assembly mode.
88

99
## Installing
1010

11-
For now, the only way to get Laser is to build from source. See
11+
Under the releases tab, there are pre-compiled binaries for Windows, Mac, and
12+
Linux. In addition, it is highly recommended that you use this program with an
13+
extensible editor like VSCode or Notepad++, and to add Laser as a shortcut in
14+
your editor. If all this installation stuff is not up your alley or you'd like
15+
to learn more about how Laser was created, take a loot at
1216
[BUILDING.md](BUILDING.md) for instructions on how to build Laser from source.
1317

14-
### Linux
18+
### Linux/Mac OS X
1519

16-
Coming soon!
20+
Once you've downloaded the precompiled binary (building from source is actually
21+
recommended on Linux due to all the different distrubutions and their
22+
differences, but Laser has practically 0 dependencies so it should be fine),
23+
copy the file to either `/usr/bin` or `/usr/local/bin` and make it executable.
24+
Alternatively, put it wherever and add it to your PATH environment variable.
1725

1826
### Windows
1927

20-
Coming soon!
28+
Download the `laser-x-x-x.exe` from the releases tab and place it somewhere
29+
permanent (I.E. not your Downloads folder), and add it to your Windows PATH.
2130

22-
### Mac OSX
23-
24-
Coming soon!
31+
To add the program to your PATH, open the file explorer, right click on This PC,
32+
and select 'properties'. Then, click on 'advanced system settings' and click on
33+
the 'environment variables' button. In the window that pops up, highlight the
34+
'Path' variable and select 'edit'. From there, click 'new' and input the file
35+
path of where you placed the downloaded laser executable. Afterwards, click
36+
'ok' and then 'apply'. You should then be able to invoke laser from the command
37+
line.
2538

2639
## Usage
2740

@@ -31,4 +44,25 @@ See [USAGE.md](USAGE.md)
3144

3245
see [BUILDING.md](BUILDING.md)
3346

34-
## Copyright
47+
## Copyright
48+
49+
Laser- a command line utility to assemble LC3 assembly code
50+
51+
Copyright Notice:
52+
53+
Copyright 2018, 2019 Zhiyuan Fan
54+
55+
License Notice:
56+
57+
Laser is free software: you can redistribute it and/or modify
58+
it under the terms of the GNU General Public License as published by
59+
the Free Software Foundation, either version 3 of the License, or
60+
(at your option) any later version.
61+
62+
Laser is distributed in the hope that it will be useful,
63+
but WITHOUT ANY WARRANTY; without even the implied warranty of
64+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65+
GNU General Public License for more details.
66+
67+
You should have received a copy of the GNU General Public License
68+
along with Laser. If not, see <https://www.gnu.org/licenses/>.

USAGE.md

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Laser Usage Guide
22

3-
After installing Laser on your system, invoke Laser by opening a terminal and
4-
typing in 'laser' and hit enter. This will print an 'About' message. Typing in
3+
After installing Laser on your system using the instructions on the
4+
[README.md](README.md), invoke Laser by opening a terminal and typing in
5+
'laser' and hit enter. This will print an 'About' message. Typing in
56
'laser -h' will display the following help message:
67

78
```
@@ -15,4 +16,55 @@ Usage:
1516
-p: 'laser -p <file1> <file2>' assembles the specified files as a project
1617
'laser -p *.asm' assembles all files in current directory as a project
1718
-c: 'laser -c <file>' removes all files generated during assembly
18-
```
19+
```
20+
---
21+
## Editors
22+
23+
It is a very good idea to find a code editor that you enjoy using- it will make
24+
you much more efficient and may even lessen the pain of editing. Below are some
25+
recommended editors along with instructions on how to set them up.
26+
27+
### VS Code
28+
29+
This is my current recommendation; it is what I used to develop Laser and it is
30+
what I will be using for the forseeable future. It's a competent text editor,
31+
but it stands out in its extensibility and hackability. I have written and
32+
published an LC3 Extension that should be all you need to get up and running,
33+
including syntax highlighting, tab completion, snippets, and build tasks.
34+
35+
You can download VS Code [here](https://code.visualstudio.com/) and my LC3
36+
Extension [here](https://marketplace.visualstudio.com/items?itemName=PaperFanz.lc3-assembly).
37+
Both are available for free on Windows, Linux, and Mac OS.
38+
39+
### Notepad++
40+
41+
*TODO, contributions appreciated*
42+
43+
<!-- Notepad++ is another very good editor, and is a huge improvement over the
44+
default Notepad in Windows. However, the downside is that it is only available
45+
for the Windows operating system and requires a bit of configuration to get to
46+
the level of productivity that VS Code affords. However, this is the editor
47+
that Professor Yeraballi uses, and he has syntax highlighting packs and build
48+
tasks available to copy and use for free. -->
49+
50+
Notepad++ can be found for free [here](https://notepad-plus-plus.org/).
51+
52+
### Atom
53+
54+
Atom is very similar to VS Code, and is built on the same underlying
55+
technologies. However, at this time there is no extension pack for the LC3 as
56+
there is on VS Code, so you will have to manually set things up if you prefer
57+
Atom. If you really love Atom, you can consider authoring your own extension
58+
pack.
59+
60+
Atom can be found for free [here](https://atom.io/) for Windows, Linux, and Mac
61+
OS.
62+
63+
### Sublime Text
64+
65+
Sublime Text is also very similar to VS Code, but like Atom lacks an LC3
66+
extension. Much like Atom, there are extensive APIs for you to author your own
67+
extension if you so wish.
68+
69+
Sublime Text is avalable on Windows, Linux, and Mac OS for free on their
70+
[website](https://www.sublimetext.com/).

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ IDIR = ../include
44
ODIR = obj
55

66
CC = gcc
7-
CFLAGS = -I $(IDIR) -g
7+
CFLAGS = -I $(IDIR)
88

99
_DEPS = laser.h token.h
1010
DEPS = $(patsubst %, $(IDIR)/%,$(_DEPS))

src/alias.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ void freealiasarr (aliasarr_t *a)
7575

7676
free (a->arr);
7777
free (a);
78-
}
78+
}

src/assemble.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ uint8_t passone (uint32_t ln, uint16_t *addr, TokenBuffer *buf, arrs_t *arrs)
226226
}
227227
}
228228

229-
if (opcount > opnum) {
229+
if (opnum == -1) {
230+
231+
} else if (opcount > opnum) {
230232
warning (ln, "'%s' expects %d operands", tok, opnum);
231233
} else if (opcount < opnum) {
232234
error (ln, "'%s' expects %d operands", tok, opnum);
@@ -521,7 +523,7 @@ uint8_t passtwo (uint32_t tbufind, uint16_t *addr, arrs_t *arrs)
521523
}
522524

523525
} else {
524-
error (ln, "Unrecognized token '%s'", token[0]);
526+
error (ln, "Unrecognized token '%s'", token[0]->str);
525527
}
526528

527529
if (end) return 1;

src/offset.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ int16_t hextodec (char hex[])
5454
int16_t hexoffset (char *offset)
5555
{
5656
int16_t offval = 0;
57-
char *hex = strchr (offset, 'x');
57+
char *hex = strchr (offset, 'x'); // for normal people who use 0x00
58+
if (!hex) hex = strchr (offset, 'X'); // for the heathens that use 0X00
5859
hex++;
5960
if (hex[0] == '-') {
6061
hex++;
@@ -95,7 +96,9 @@ int16_t binoffset (char *offset)
9596
int8_t neg = 0;
9697
int16_t offval = 0;
9798
// move pointer past leading characters
98-
char *bin = strchr (offset, 'b');
99+
char *bin = strchr (offset, 'b'); // for normal people who use 0b00
100+
if (!bin) bin = strchr (offset, 'B'); // for the heathens that use 0B00
101+
99102
bin++;
100103
if (bin[0] == '-') {
101104
bin++;
@@ -157,14 +160,14 @@ uint8_t offtype (Token *tok)
157160
char *token = tok->str;
158161
char *tmp;
159162
char c;
160-
if ((tmp = strchr (token, 'x')) != NULL) {
163+
if ((tmp = strchr (token, 'x')) || (tmp = strchr (token, 'X'))) {
161164
tmp++;
162165
if (*tmp == '-') tmp++;
163166
for (uint16_t i = 0; (c = tmp[i]); i++) {
164167
if (!isxdigit (c)) return INVALID_OFF;
165168
}
166169
return HEX;
167-
} else if ((tmp = strchr (token, 'b')) != NULL) {
170+
} else if ((tmp = strchr (token, 'b')) || (tmp = strchr (token, 'B'))) {
168171
tmp++;
169172
if (*tmp == '-') tmp++;
170173
for (uint16_t i = 0; (c = tmp[i]); i++) {

src/operand.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ int8_t arrcmp (char *str, const char *arr[][2], uint8_t size)
3333
return -1;
3434
}
3535

36+
int8_t brrcmp (char *str, const char *arr[][3], uint8_t size)
37+
{
38+
for (uint8_t i = 0; i < size; i++) {
39+
if (strcmp (str, arr[i][0]) == 0 ||
40+
strcmp (str, arr[i][1]) == 0 ||
41+
strcmp (str, arr[i][2]) == 0) return i;
42+
}
43+
return -1;
44+
}
45+
3646
int8_t isregister (Token *token)
3747
{
3848
const char *regs[][2] = {
@@ -51,18 +61,18 @@ int8_t isregister (Token *token)
5161

5262
int8_t isbranch (Token *token)
5363
{
54-
const char *brs[][2] = {
55-
{"BR", "br"},
56-
{"BRp", "brp"},
57-
{"BRz", "brz"},
58-
{"BRzp", "brzp"},
59-
{"BRn", "brn"},
60-
{"BRnp", "brnp"},
61-
{"BRnz", "brnz"},
62-
{"BRnzp", "brnzp"}
64+
const char *brs[][3] = {
65+
{"BR", "BR", "br"},
66+
{"BRP", "BRp", "brp"},
67+
{"BRZ", "BRz", "brz"},
68+
{"BRZP", "BRzp", "brzp"},
69+
{"BRN", "BRn", "brn"},
70+
{"BRNP", "BRnp", "brnp"},
71+
{"BRNZ", "BRnz", "brnz"},
72+
{"BRNZP", "BRnzp", "brnzp"}
6373
};
6474

65-
int8_t tmp = arrcmp (token->str, brs, 8);
75+
int8_t tmp = brrcmp (token->str, brs, 8);
6676
tmp = (tmp == 0) ? 7 : tmp;
6777
return tmp;
6878
}

src/token.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ Token* putstr (char *line, uint16_t *lineptr)
7979
int8_t iseow (char c)
8080
{
8181
int8_t eow = 0;
82-
const char eowchars[] = {0, 32, 44, 9, 10, 13};
82+
const char eowchars[] = {0, 13, '\t', '\n', ' ', ',', ';'};
8383

84-
for (uint8_t i = 0; i < 6; i++) {
84+
for (uint8_t i = 0; i < 7; i++) {
8585
if (c == eowchars[i]) eow++;
8686
}
8787

0 commit comments

Comments
 (0)