Skip to content

Commit

Permalink
Add more instructions to the assembler
Browse files Browse the repository at this point in the history
Includes:
 - JMP
 - RET
 - JSR
 - JSRR
 - LDI
 - LEA
 - ST
 - STR
 - STI

Includes some more bug fixes and error handling:

 - return SymbolError from SymbolTable.Offset so it can be unwrapped.
 - code docs updated
 - types cleanup

Squashed commit of 7d10b6b..8c5cca9
  • Loading branch information
smoynes committed Oct 9, 2023
1 parent b0a2dcb commit 116dbf4
Show file tree
Hide file tree
Showing 9 changed files with 1,305 additions and 110 deletions.
51 changes: 27 additions & 24 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
# TODO #

- [ ] DOCS:
- [ ] tutorial
- [ ] design
- [.] ASM:
- [.] code generation: ~7/16
- [.] directives
- ASM:
- [.] document grammar more completely
- directives remaining:
- [ ] .END
- [ ] .EXTERNAL
- [x] .STRINGZ: strangz
- [x] .BLKW: block words
- [x] .DW: define word
- [x] .FILL: fill word
- [x] .ORIG: origin
- [x] cli command
- [.] document grammar more completely
- [x] memory layout
- [x] cleaner error handling
- [x] simple parser: regexp
- [x] symbol table
- [ ] LOAD: object loader
- DOCS:
- [ ] tutorial
- [ ] design
- [ ] MONITOR: trap, exception, and interrupt routines
- [ ] LINK: code linker
- [ ] DUMP: hex encoder
- [ ] CLI: sub commands for vm, tools, terminal, shell
- [ ] LOG: program output to STDOUT, logging output to STDERR (unless in
demo)
- [ ] TERM: finish the terminal I/O
- [ ] MONITOR: trap, exception, and interrupt routines
- [ ] REPL: step debugger shell
- [ ] TIMER: simple timer device
- [ ] NEWLANG: interpreted language; threaded compiler
Expand All @@ -35,9 +24,23 @@

## DID ##

- [x] instruction loop
- [x] instructions
- [x] service exceptions
- [x] service traps
- [x] memory mapped I/O
- [x] hardware interrupts
- ASM:
- [x] code generation
- [x] completed directives:
- [x] .STRINGZ: strangz
- [x] .BLKW: block words
- [x] .DW: define word
- [x] .FILL: fill word
- [x] .ORIG: origin
- [x] cli command
- [x] memory layout
- [x] cleaner error handling
- [x] simple parser: regexp
- [x] symbol table
- VM:
- [x] instruction loop
- [x] instructions
- [x] service exceptions
- [x] service traps
- [x] memory mapped I/O
- [x] hardware interrupts
10 changes: 9 additions & 1 deletion internal/asm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s SymbolTable) Add(sym string, loc uint16) {
func (s SymbolTable) Offset(sym string, pc uint16, n int) (uint16, error) {
loc, ok := s[sym]
if !ok {
return 0xffff, fmt.Errorf("%s: symbol not found", sym)
return 0xffff, &SymbolError{Symbol: sym, Loc: pc}
}

delta := int16(loc - pc)
Expand Down Expand Up @@ -155,6 +155,14 @@ func (se *SymbolError) Error() string {
return fmt.Sprintf("symbol error: %q", se.Symbol)
}

func (se *SymbolError) Is(err error) bool {
if _, ok := err.(*SymbolError); ok {
return true
}

return false
}

// SyntaxTable is holds the parsed code and data indexed by its location counter.
type SyntaxTable []Operation

Expand Down
Loading

0 comments on commit 116dbf4

Please sign in to comment.