s502 assembler
A very simple assembler for the 6502 line of processors written in C
|
This program can handle many errors:
The handled errors do not cause the program to crash, instead, it prints where it encountered the problem, tells details and then de-allocates all used resources before quitting.
Error signaling is based on return values, usually negative return values indicating error. Most functions also print FAIL messages when one of their sub-tasks quitted with an error, thus giving us a partial traceback.
Bellow is a list of all possible errors, and one (or many) ways to reproduce them.
This list can be used to check if no error ever leaks memory or crashes the program. (which I did by hand)
Please note that the described ways are only examples on how to trigger these errors, and might NOT cover all cases for all errors, but all currently reproducible errors have at least one example.
Reproduce:
.define
.define A
.define A B C
(any number of arguments other than 2)
Reproduce:
.define A &nondef
Reproduce:
.define veeeeery_loooooong_coooonstant_naaame 5
(actual max value is set in map.h)
Reproduce:
.ifbeq
.ifbeq A
.ifbeq A B C
(any number of arguments other than 2)
Reproduce:
.ifbeq &A &B
Triggers on any undefined label
Reproduce:
.print
Reproduce:
.printc
.printc A B
(any number of arguments other than 1)
Reproduce:
.include
.include A B
(any number of arguments other than 1)
Reproduce:
.ifdef
.ifndef
.ifdef A B
.ifndef A B
(any number of arguments other than 2)
Reproduce:
.org
.org A B
(any number of arguments other than 1)
Reproduce:
.org &nondefined
Reproduce:
.pad
.pad A B C
(any number of arguments other than 1 or 2)
Reproduce:
.pad ABC
Triggers on any non-defined labels/constants or on number parsing errors Reproduce:
.org $500
.pad $400
Reproduce:
.whatisthis
Reproduce:
.data w:&nondefinded
.data &nondefined
(same message for both words and bytes, but with two different ERROR lines)
Also triggers "Invalid byte/word in .data" message
Reproduce:
.data $error
Might also trigger "Can not interpret number" or "Label is not defined"
Reproduce:
.data "abc
Reproduce:
.data $5 256
.data $5 $error
Might also trigger "Can not interpret number" or "Label is not defined"
Reproduce:
.pad $100
.pad $error
Triggers if pad byte is >255 or does not have a value (undefined label/constant, number parsing error)
Might also trigger ""Can not interpret number
Reproduce:
Reproduce:
No known ways to reproduce any memory allocation errors
Reproduce:
some terribly (and also unnecessarily) long line that should never exist in an assembly source file, not even in .data directives bc it's unreadable
Please note that comments and whitespaces does NOT count here
Reproduce:
.data THIS_IS_NOT_A_NUMBER
Can trigger anywhere where a number was expected but could not be parsed.
Might also have other error messages.
Reproduce:
.endif
Reproduce:
this_label_is_so_long_it_will_genererate_an_error:
Limit is set in map.h
Reproduce:
my_label:
my_label:
Reproduce:
lda &undef_label
Can only happen in instructions
Reproduce:
asm.exe -l
asm.exe -d
asm.exe -d A
asm.exe -o
Reproduce:
asm.exe -o very/long/file/path/that/wont/fit/in/my/small/buffer
Maximum can be set in state.h
Reproduce:
asm.exe -o -argument2
Reproduce:
asm.exe -l ABCD
Reproduce:
asm.exe -d A ABCD
Reproduce:
asm.exe -d very_long_constant_name_that_will_cause_an_error 2
Reproduce:
asm.exe very_very_VERY_long_input_file_name_or_path
Maximum can be set in state.h
Reproduce:
asm.exe -not_an_input_file
Reproduce:
asm.exe
Reproduce:
wtf #$5
Reproduce:
lda *#(5),Z
Reproduce:
lda ($1234)
Reproduce:
la:
.ab
.label:
No known ways to reproduce
Reproduce:
.org 0
beq $8000
Max relative jump distance is 8 bit signed ((-128)-127)