Skip to content

Commit

Permalink
add logical and relational operators to expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNisbet committed Dec 2, 2023
1 parent d01c8f9 commit fe5c0e6
Show file tree
Hide file tree
Showing 12 changed files with 875 additions and 86 deletions.
2 changes: 2 additions & 0 deletions examples/errors.asm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mov h,l ; *ERR: instruction can't start in column zero
MVI B,A ; ERR: second arg should be expression
JMP SP ; ERR: first arg should be expression
JZ ; ERR: missing arg
MVI b,1+2+ ; *ERR: extra chars in expression

; RST instructions
RST 0 ; OK
Expand All @@ -44,6 +45,7 @@ RNUM equ 1
RST 1+1 ; ERR: expression not allowed
RST 7 ; OK
RST 9 ; ERR: RST number must be 0..7

; characters in expressions
mvi b,'P' ; single char is a byte
lxi d,'QR' ; two chars is a sixteen bit value
Expand Down
59 changes: 59 additions & 0 deletions examples/reference/errors.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
; Test and demonstrate assembly errors
; lines marked with ERR are detected by the assenbler
; lines marked as *ERR should be detected, but are currently not

; constants
symd1 equ 55 ; decimal constant
symd2 equ 5X5 ; *ERR: bad decimal constant
symh1 equ 5A5h ; hex constant
symh2 equ 5A5 ; ERR: missing H for hex constant
symh3 equ ffffH ; ERR: hex must start with numeric
symh4 equ 0ffffH ; Hex with leading zero
symb1 equ 01100110b ; Binary constant
symb2 equ 01101210b ; ERR: bad binary constant

bah equ 77h
bad: db "where is the end ; ERR: unterminated string
special:db "\t\n\r",bah,beh, bad ; ERR: undefined symbol

; column zero
LABEL1: ; label can start in column 0
LABEL2: MOV C,A ; label with instruction also OK
NAME1 EQU 7 ; name can start in column zero
123 ; ERR: not name or label
"abc" ; ERR: not name or label
+ ; ERR: not name or label
mov h,l ; *ERR: instruction can't start in column zero

; extra information on line and extra/incorrect arguments
nop SP ; ERR: extra register argument
nop d,e ; ERR: multiple extra registers
nop str ; ERR: extra expression argument
nop 12XX ; ERR: extra characters
MOV A ; ERR: missing second register
MOV A,4 ; ERR: missing second register
MVI B,A ; ERR: second arg should be expression
JMP SP ; ERR: first arg should be expression
JZ ; ERR: missing arg
MVI b,1+2+ ; *ERR: extra chars in expression

; RST instructions
RST 0 ; OK
RST A ; ERR: must be number
RNUM equ 1
RST RNUM ; ERR: expression not allowed
RST 1+1 ; ERR: expression not allowed
RST 7 ; OK
RST 9 ; ERR: RST number must be 0..7

; characters in expressions
mvi b,'P' ; single char is a byte
lxi d,'QR' ; two chars is a sixteen bit value
mvi e,'abc' ; ERR: Can't use string in expression
lxi b,'a'*'B' ; weird, but legal


; math
var1 equ 23 / 0 ; ERR: divide by zero
var2 dw 255 + 10; OK as a 16 bit value
var3 db 255 + 10; *ERR: 8 bit constant overflow
2 changes: 1 addition & 1 deletion examples/reference/errors.hex
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
:19000000090A0D774F000006C3CAC7CFFF06501152511E01021909010982
:1A000000090A0D774F000006C3CA06C7CFFF06501152511E0102190901097B
:00000001FF
54 changes: 29 additions & 25 deletions examples/reference/errors.lst
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,44 @@ ERROR - Label not found: SP
0009 ca 37: JZ ; ERR: missing arg
ERROR - Expected label or numeric constant, found:: ;

38:
39: ; RST instructions
000a c7 40: RST 0 ; OK
41: RST A ; ERR: must be number
000a 06 38: MVI b,1+2+ ; *ERR: extra chars in expression
ERROR - Expected label or numeric constant, found:: ;

39:
40: ; RST instructions
000b c7 41: RST 0 ; OK
42: RST A ; ERR: must be number
ERROR - RST instruction argument must be 0-7: A

(0001) 42: RNUM equ 1
43: RST RNUM ; ERR: expression not allowed
(0001) 43: RNUM equ 1
44: RST RNUM ; ERR: expression not allowed
ERROR - RST instruction argument must be 0-7: RNUM

000b cf 44: RST 1+1 ; ERR: expression not allowed
000c cf 45: RST 1+1 ; ERR: expression not allowed
ERROR - Found extra arguments after RST instruction:: +

000c ff 45: RST 7 ; OK
46: RST 9 ; ERR: RST number must be 0..7
000d ff 46: RST 7 ; OK
47: RST 9 ; ERR: RST number must be 0..7
ERROR - RST instruction argument must be 0-7: 9

47: ; characters in expressions
000d 06 50 48: mvi b,'P' ; single char is a byte
000f 11 52 51 49: lxi d,'QR' ; two chars is a sixteen bit value
0012 1e 50: mvi e,'abc' ; ERR: Can't use string in expression
48:
49: ; characters in expressions
000e 06 50 50: mvi b,'P' ; single char is a byte
0010 11 52 51 51: lxi d,'QR' ; two chars is a sixteen bit value
0013 1e 52: mvi e,'abc' ; ERR: Can't use string in expression
ERROR - Multi-character string not allowed in expression.

0013 01 02 19 51: lxi b,'a'*'B' ; weird, but legal
52:
53:
54: ; math
55: var1 equ 23 / 0 ; ERR: divide by zero
0014 01 02 19 53: lxi b,'a'*'B' ; weird, but legal
54:
55:
56: ; math
57: var1 equ 23 / 0 ; ERR: divide by zero
ERROR - Divide by zero

0016 09 01 56: var2 dw 255 + 10; OK as a 16 bit value
0018 09 57: var3 db 255 + 10; *ERR: 8 bit constant overflow
0017 09 01 58: var2 dw 255 + 10; OK as a 16 bit value
0019 09 59: var3 db 255 + 10; *ERR: 8 bit constant overflow

57 lines, 23 errors, 0 warnings
59 lines, 24 errors, 0 warnings


SYMBOL TABLE:
Expand All @@ -125,9 +129,9 @@ LABEL2 : 0006 (6)
NAME1 : 0007 (7)
mov : 0007 (7)
RNUM : 0001 (1)
var1 : 001b (27)
var2 : 001b (27)
var3 : 001d (29)
var1 : 001c (28)
var2 : 001c (28)
var3 : 001e (30)


Total memory is 25 bytes
Total memory is 26 bytes
Loading

0 comments on commit fe5c0e6

Please sign in to comment.