commit 8574d62a611f38179d3e9d95f2f96ec084e5997d
parent cda02143cdd067d8847391ae53dfc1bf0c0c0e7a
Author: neauoire <aliceffekt@gmail.com>
Date: Sat, 13 Feb 2021 08:38:23 -0800
Minor changes to the asm syntax
Diffstat:
13 files changed, 116 insertions(+), 116 deletions(-)
diff --git a/README.md b/README.md
@@ -42,12 +42,12 @@ evaluxn(u, u->vframe); /* Each frame
- `( comment )`, toggle parsing on/off.
- `|0010`, move to position in the program.
- `"hello`, push literal bytes for word "hello".
-- `#04`, a zero-page address, equivalent to `,0004`.
### Operator modes
-- `,1234 ,0001 ADD^`, 16-bits operators have the short flag `^`.
+- `,1234 ,0001 ADD2`, 16-bits operators have the short flag `2`.
- `,12 ,11 GTH JMP?`, conditional operators have the cond flag `?`.
+- `+21 -03 MULS`, signed operators have the cond flag `S`.
```
( hello world )
diff --git a/assembler.c b/assembler.c
@@ -101,8 +101,8 @@ findoperator(char *s)
if(o[0] != s[0] || o[1] != s[1] || o[2] != s[2])
continue;
while(s[3 + m]) {
- if(s[3 + m] == '^') i |= (1 << 5); /* mode: 16 bits */
- if(s[3 + m] == '!') i |= (1 << 6); /* mode: signed */
+ if(s[3 + m] == '2') i |= (1 << 5); /* mode: short */
+ if(s[3 + m] == 'S') i |= (1 << 6); /* mode: signed */
if(s[3 + m] == '?') i |= (1 << 7); /* mode: conditional */
m++;
}
@@ -128,6 +128,8 @@ makelabel(char *name, Uint16 addr)
return error("Label duplicate", name);
if(sihx(name))
return error("Label name is hex number", name);
+ if(findoperator(name))
+ return error("Label name is invalid", name);
l = &labels[labelslen++];
l->addr = addr;
scpy(name, l->name, 64);
@@ -178,7 +180,6 @@ pass1(FILE *f)
switch(w[0]) {
case '|': addr = shex(w + 1); break;
case '"': addr += slen(w + 1) + 2; break;
- case '#': addr += 4; break;
case '.': addr += 2; break;
case '+': /* signed positive */
case '-': /* signed negative */
@@ -213,7 +214,6 @@ pass2(FILE *f)
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 2) pushbyte((Sint8)(shex(w + 1) * -1), 1);
else if(w[0] == '-' && sihx(w + 1) && slen(w + 1) == 4) pushshort((Sint16)(shex(w + 1) * -1), 1);
else if(w[0] == '"') pushtext(w + 1);
- else if(w[0] == '#') pushshort(shex(w + 1) & 0xff, 1);
else if((l = findlabel(w + 1))) pushshort(l->addr, w[0] == ',');
else if((op = findoperator(w)) || scmp(w, "BRK")) pushbyte(op, 0);
else if(sihx(w + 1) && slen(w + 1) == 2) pushbyte(shex(w + 1), w[0] == ',');
diff --git a/examples/benchmark.usm b/examples/benchmark.usm
@@ -13,25 +13,25 @@
,12 ,13 LTH #07 STR
( arithmetic 16-bit )
-,1234 ,2345 ADD^ ,3579 EQU^ #08 STR
-,1234 ,0123 SUB^ ,1111 EQU^ #09 STR
-,1234 ,0102 MUL^ ,5868 EQU^ #0a STR
-,5678 ,0100 DIV^ ,0056 EQU^ #0b STR
-,1234 ,1234 EQU^ #0c STR
-,1234 ,0123 NEQ^ #0d STR
-,1234 ,1233 GTH^ #0e STR
-,1234 ,1235 LTH^ #0f STR
+,1234 ,2345 ADD2 ,3579 EQU2 #08 STR
+,1234 ,0123 SUB2 ,1111 EQU2 #09 STR
+,1234 ,0102 MUL2 ,5868 EQU2 #0a STR
+,5678 ,0100 DIV2 ,0056 EQU2 #0b STR
+,1234 ,1234 EQU2 #0c STR
+,1234 ,0123 NEQ2 #0d STR
+,1234 ,1233 GTH2 #0e STR
+,1234 ,1235 LTH2 #0f STR
BRK
@diff8 ( result of abs sub )
- OVR OVR GTH ,diff8sub ROT JMP? POP^
+ OVR OVR GTH ,diff8sub ROT JMP? POP2
SWP @diff8sub SUB
RTS
@diff16 ( result of abs sub16 )
- OVR^ OVR^ GTH^ ,diff16sub ROT JMP? POP^
- SWP^ @diff16sub SUB^
+ OVR2 OVR2 GTH2 ,diff16sub ROT JMP? POP2
+ SWP2 @diff16sub SUB2
RTS
|c000 @FRAME BRK
diff --git a/examples/condjump.usm b/examples/condjump.usm
@@ -2,7 +2,7 @@
|0100 @RESET
-,06 ,05 GTH ,there ROT JMP? POP^
+,06 ,05 GTH ,there ROT JMP? POP2
@here ( when lesser or equal )
,ee
diff --git a/examples/draw.usm b/examples/draw.usm
@@ -42,18 +42,18 @@
( positive )
,01 ,color STR
- +0030 ,x0 STR^ +0040 ,y0 STR^
- +0100 ,x1 STR^ +0060 ,y1 STR^
+ +0030 ,x0 STR2 +0040 ,y0 STR2
+ +0100 ,x1 STR2 +0060 ,y1 STR2
,line JSR
,02 ,color STR
- +0020 ,x0 STR^ +0010 ,y0 STR^
- +0090 ,x1 STR^ +0070 ,y1 STR^
+ +0020 ,x0 STR2 +0010 ,y0 STR2
+ +0090 ,x1 STR2 +0070 ,y1 STR2
,line JSR
,03 ,color STR
- +0010 ,x0 STR^ +0040 ,y0 STR^
- +0070 ,x1 STR^ +0060 ,y1 STR^
+ +0010 ,x0 STR2 +0040 ,y0 STR2
+ +0070 ,x1 STR2 +0060 ,y1 STR2
,line JSR
,redraw JSR
@@ -61,68 +61,68 @@
BRK
@fillrect
- ,h STR^ ,w STR^ ,y STR^ ,x STR^
- ,x LDR^ ,x_ STR^ ,y LDR^ ,y_ STR^
+ ,h STR2 ,w STR2 ,y STR2 ,x STR2
+ ,x LDR2 ,x_ STR2 ,y LDR2 ,y_ STR2
@fillrectrow
- ,x LDR^ ,x_ STR^
+ ,x LDR2 ,x_ STR2
@fillrectcol
- ( draw ) ,x_ LDR^ ,y_ LDR^ ,putpixel JSR
- ,x_ LDR^ ,0001 ADD^ ,x_ STR^
- ,x_ LDR^ ,w LDR^ ,x LDR^ ADD^ LTH^ ,fillrectcol ROT JMP? POP^
- ,y_ LDR^ ,0001 ADD^ ,y_ STR^
- ,y_ LDR^ ,h LDR^ ,y LDR^ ADD^ LTH^ ,fillrectrow ROT JMP? POP^
+ ( draw ) ,x_ LDR2 ,y_ LDR2 ,putpixel JSR
+ ,x_ LDR2 ,0001 ADD2 ,x_ STR2
+ ,x_ LDR2 ,w LDR2 ,x LDR2 ADD2 LTH2 ,fillrectcol ROT JMP? POP2
+ ,y_ LDR2 ,0001 ADD2 ,y_ STR2
+ ,y_ LDR2 ,h LDR2 ,y LDR2 ADD2 LTH2 ,fillrectrow ROT JMP? POP2
RTS
@linerect
- ,h STR^ ,w STR^ ,y STR^ ,x STR^
- ,x LDR^ ,x_ STR^ ,y LDR^ ,y_ STR^
+ ,h STR2 ,w STR2 ,y STR2 ,x STR2
+ ,x LDR2 ,x_ STR2 ,y LDR2 ,y_ STR2
@linerectcol
- ( draw ) ,x LDR^ ,y_ LDR^ ,putpixel JSR
- ( draw ) ,x LDR^ ,w LDR^ ADD^ ,y_ LDR^ ,putpixel JSR
- ,y_ LDR^ ,0001 ADD^ ,y_ STR^
- ,y_ LDR^ ,h LDR^ ,y LDR^ ADD^ LTH^ ,linerectcol ROT JMP? POP^
+ ( draw ) ,x LDR2 ,y_ LDR2 ,putpixel JSR
+ ( draw ) ,x LDR2 ,w LDR2 ADD2 ,y_ LDR2 ,putpixel JSR
+ ,y_ LDR2 ,0001 ADD2 ,y_ STR2
+ ,y_ LDR2 ,h LDR2 ,y LDR2 ADD2 LTH2 ,linerectcol ROT JMP? POP2
@linerectrow
- ( draw ) ,x_ LDR^ ,y LDR^ ,putpixel JSR
- ( draw ) ,x_ LDR^ ,y LDR^ ,h LDR^ ADD^ ,putpixel JSR
- ,x_ LDR^ ,0001 ADD^ ,x_ STR^
- ,x_ LDR^ ,w LDR^ ,x LDR^ ADD^ ,0001 ADD^ LTH^ ,linerectrow ROT JMP? POP^
+ ( draw ) ,x_ LDR2 ,y LDR2 ,putpixel JSR
+ ( draw ) ,x_ LDR2 ,y LDR2 ,h LDR2 ADD2 ,putpixel JSR
+ ,x_ LDR2 ,0001 ADD2 ,x_ STR2
+ ,x_ LDR2 ,w LDR2 ,x LDR2 ADD2 ,0001 ADD2 LTH2 ,linerectrow ROT JMP? POP2
RTS
@line
- ,x0 LDR^ ,x_ STR^ ,y0 LDR^ ,y_ STR^ ( start at x0,y0 )
- ,x1 LDR^ ,x0 LDR^ ,diff16sub JSR ,dx STR^ ( int dx = abs[x1 - x0] )
- ,y1 LDR^ ,y0 LDR^ ,diff16sub JSR -0001 MUL!^ ,dy STR^ ( int dy = -abs[y1 - y0] )
- ,dx LDR^ ,dy LDR^ ADD!^ ,err1 STR^ ( int err1 = dx + dy, e2; )
+ ,x0 LDR2 ,x_ STR2 ,y0 LDR2 ,y_ STR2 ( start at x0,y0 )
+ ,x1 LDR2 ,x0 LDR2 ,diff16sub JSR ,dx STR2 ( int dx = abs[x1 - x0] )
+ ,y1 LDR2 ,y0 LDR2 ,diff16sub JSR -0001 MULS2 ,dy STR2 ( int dy = -abs[y1 - y0] )
+ ,dx LDR2 ,dy LDR2 ADDS2 ,err1 STR2 ( int err1 = dx + dy, e2; )
@lineloop
- ,x_ LDR^ ,y_ LDR^ ,putpixel JSR ( draw )
+ ,x_ LDR2 ,y_ LDR2 ,putpixel JSR ( draw )
@line-x
- ,err1 LDR^ +0002 MUL!^ ,err2 STR^ ( e2 = 2 * err; )
- ,err2 LDR^ ,dy LDR^ LTH!^ ,line-y ROT JMP? POP^ ( e2 >= dy )
- ,err1 LDR^ ,dy LDR^ ADD!^ ,err1 STR^ ( err1 += dy; )
- ,x_ LDR^ +0001 ADD!^ ,x_ STR^ ( y0 += y0 < y1 ? 1 : -1; )
+ ,err1 LDR2 +0002 MULS2 ,err2 STR2 ( e2 = 2 * err; )
+ ,err2 LDR2 ,dy LDR2 LTHS2 ,line-y ROT JMP? POP2 ( e2 >= dy )
+ ,err1 LDR2 ,dy LDR2 ADDS2 ,err1 STR2 ( err1 += dy; )
+ ,x_ LDR2 +0001 ADDS2 ,x_ STR2 ( y0 += y0 < y1 ? 1 : -1; )
@line-y
- ,err2 LDR^ ,dx LDR^ GTH!^ ,line-end ROT JMP? POP^ ( e2 <= dx )
- ,err1 LDR^ ,dx LDR^ ADD!^ ,err1 STR^ ( err1 += dx; )
- ,y_ LDR^ +0001 ADD!^ ,y_ STR^ ( y0 += y0 < y1 ? 1 : -1; )
+ ,err2 LDR2 ,dx LDR2 GTHS2 ,line-end ROT JMP? POP2 ( e2 <= dx )
+ ,err1 LDR2 ,dx LDR2 ADDS2 ,err1 STR2 ( err1 += dx; )
+ ,y_ LDR2 +0001 ADDS2 ,y_ STR2 ( y0 += y0 < y1 ? 1 : -1; )
@line-end
- ,x_ LDR^ ,x1 LDR^ NEQ!^ ,lineloop ROT JMP? POP^ ( loop )
+ ,x_ LDR2 ,x1 LDR2 NEQS2 ,lineloop ROT JMP? POP2 ( loop )
RTS
@diff16
- OVR^ OVR^ GTH^ ,diff16sub ROT JMP? POP^
- SWP^ @diff16sub SUB^
+ OVR2 OVR2 GTH2 ,diff16sub ROT JMP? POP2
+ SWP2 @diff16sub SUB2
RTS
@redraw
- ,0000 IOW^
- ,0000 IOW^
+ ,0000 IOW2
+ ,0000 IOW2
,00 IOW
,01 IOW
RTS
@putpixel
- IOW^ ( y short )
- IOW^ ( x short )
+ IOW2 ( y short )
+ IOW2 ( x short )
,color LDR IOW ( color byte )
,00 IOW ( redraw byte )
RTS
diff --git a/examples/hello.usm b/examples/hello.usm
@@ -18,7 +18,7 @@
BRK
-@strlen ,0001 ADD^ LDR RTS
+@strlen ,0001 ADD2 LDR RTS
@incr ,i LDR ,01 ADD ,i STR RTS
|c000 @FRAME BRK
diff --git a/examples/line.usm b/examples/line.usm
@@ -13,66 +13,66 @@
( positive )
,01 ,color STR
- +0030 ,x0 STR^ +0040 ,y0 STR^
- +0100 ,x1 STR^ +0060 ,y1 STR^
+ +0030 ,x0 STR2 +0040 ,y0 STR2
+ +0100 ,x1 STR2 +0060 ,y1 STR2
,line JSR
,02 ,color STR
- +0020 ,x0 STR^ +0010 ,y0 STR^
- +0090 ,x1 STR^ +0070 ,y1 STR^
+ +0020 ,x0 STR2 +0010 ,y0 STR2
+ +0090 ,x1 STR2 +0070 ,y1 STR2
,line JSR
,03 ,color STR
- +0010 ,x0 STR^ +0040 ,y0 STR^
- +0070 ,x1 STR^ +0060 ,y1 STR^
+ +0010 ,x0 STR2 +0040 ,y0 STR2
+ +0070 ,x1 STR2 +0060 ,y1 STR2
,line JSR
( draw control points )
,02 ,color STR
- ,x0 LDR^ ,y0 LDR^ ,putpixel JSR
- ,x1 LDR^ ,y1 LDR^ ,putpixel JSR
+ ,x0 LDR2 ,y0 LDR2 ,putpixel JSR
+ ,x1 LDR2 ,y1 LDR2 ,putpixel JSR
,redraw JSR
BRK
@line
- ,x0 LDR^ ,x_ STR^ ,y0 LDR^ ,y_ STR^ ( start at x0,y0 )
- ,x1 LDR^ ,x0 LDR^ ,diff16sub JSR ,dx STR^ ( int dx = abs[x1 - x0] )
- ,y1 LDR^ ,y0 LDR^ ,diff16sub JSR -0001 MUL!^ ,dy STR^ ( int dy = -abs[y1 - y0] )
- ,dx LDR^ ,dy LDR^ ADD!^ ,err1 STR^ ( int err1 = dx + dy, e2; )
+ ,x0 LDR2 ,x_ STR2 ,y0 LDR2 ,y_ STR2 ( start at x0,y0 )
+ ,x1 LDR2 ,x0 LDR2 ,diff16sub JSR ,dx STR2 ( int dx = abs[x1 - x0] )
+ ,y1 LDR2 ,y0 LDR2 ,diff16sub JSR -0001 MULS2 ,dy STR2 ( int dy = -abs[y1 - y0] )
+ ,dx LDR2 ,dy LDR2 ADDS2 ,err1 STR2 ( int err1 = dx + dy, e2; )
@lineloop
- ,x_ LDR^ ,y_ LDR^ ,putpixel JSR ( draw )
+ ,x_ LDR2 ,y_ LDR2 ,putpixel JSR ( draw )
@line-x
- ,err1 LDR^ +0002 MUL!^ ,err2 STR^ ( e2 = 2 * err; )
- ,err2 LDR^ ,dy LDR^ LTH!^ ,line-y ROT JMP? POP^ ( e2 >= dy )
- ,err1 LDR^ ,dy LDR^ ADD!^ ,err1 STR^ ( err1 += dy; )
- ,x_ LDR^ +0001 ADD!^ ,x_ STR^ ( y0 += y0 < y1 ? 1 : -1; )
+ ,err1 LDR2 +0002 MULS2 ,err2 STR2 ( e2 = 2 * err; )
+ ,err2 LDR2 ,dy LDR2 LTHS2 ,line-y ROT JMP? POP2 ( e2 >= dy )
+ ,err1 LDR2 ,dy LDR2 ADDS2 ,err1 STR2 ( err1 += dy; )
+ ,x_ LDR2 +0001 ADDS2 ,x_ STR2 ( y0 += y0 < y1 ? 1 : -1; )
@line-y
- ,err2 LDR^ ,dx LDR^ GTH!^ ,line-end ROT JMP? POP^ ( e2 <= dx )
- ,err1 LDR^ ,dx LDR^ ADD!^ ,err1 STR^ ( err1 += dx; )
- ,y_ LDR^ +0001 ADD!^ ,y_ STR^ ( y0 += y0 < y1 ? 1 : -1; )
+ ,err2 LDR2 ,dx LDR2 GTHS2 ,line-end ROT JMP? POP2 ( e2 <= dx )
+ ,err1 LDR2 ,dx LDR2 ADDS2 ,err1 STR2 ( err1 += dx; )
+ ,y_ LDR2 +0001 ADDS2 ,y_ STR2 ( y0 += y0 < y1 ? 1 : -1; )
@line-end
- ,x_ LDR^ ,x1 LDR^ NEQ!^ ,lineloop ROT JMP? POP^ ( loop )
+ ,x_ LDR2 ,x1 LDR2 NEQS2 ,lineloop ROT JMP? POP2 ( loop )
RTS
@redraw
- ,0000 IOW^
- ,0000 IOW^
+ ,0000 IOW2
+ ,0000 IOW2
,00 IOW
,01 IOW
RTS
@putpixel
- IOW^ ( y short )
- IOW^ ( x short )
+ IOW2 ( y short )
+ IOW2 ( x short )
,color LDR IOW ( color byte )
,00 IOW ( redraw byte )
RTS
@diff16
- OVR^ OVR^ GTH^ ,diff16sub ROT JMP? POP^
- SWP^ @diff16sub SUB^
+ OVR2 OVR2 GTH2 ,diff16sub ROT JMP? POP2
+ SWP2 @diff16sub SUB2
RTS
|c000 @FRAME BRK
diff --git a/examples/loop.usm b/examples/loop.usm
@@ -8,14 +8,14 @@
@loop1
,01 ADD DUP
- ,ff NEQ ,loop1 ROT JMP? POP^
+ ,ff NEQ ,loop1 ROT JMP? POP2
( increment value in memory )
@loop2
#00 LDR ,01 ADD #00 STR
#00 LDR
- ,ff NEQ ,loop2 ROT JMP? POP^
+ ,ff NEQ ,loop2 ROT JMP? POP2
BRK
diff --git a/examples/mouse.usm b/examples/mouse.usm
@@ -25,13 +25,13 @@ BRK
BRK
@getmouse
- ,00 IOR^ ( get mouse x )
- ,02 IOR^ ( get mouse y )
+ ,00 IOR2 ( get mouse x )
+ ,02 IOR2 ( get mouse y )
RTS
@putpixel
- IOW^ ( y short )
- IOW^ ( x short )
+ IOW2 ( y short )
+ IOW2 ( x short )
IOW ( color byte )
IOW ( redraw byte )
RTS
diff --git a/examples/pixel.usm b/examples/pixel.usm
@@ -10,13 +10,13 @@
,01 ,dev/w STR
- ,0020 ,x STR^ ( set x-pos )
- ,0030 ,y STR^ ( set y-pos )
+ ,0020 ,x STR2 ( set x-pos )
+ ,0030 ,y STR2 ( set y-pos )
( IOW will now send to screen )
- ,y LDR^ IOW^ ( y-pos )
- ,x LDR^ IOW^ ( x-pos )
+ ,y LDR2 IOW2 ( y-pos )
+ ,x LDR2 IOW2 ( x-pos )
,02 IOW ( color )
,01 IOW ( redraw )
diff --git a/examples/pixels.usm b/examples/pixels.usm
@@ -9,8 +9,8 @@
,01 ,dev/w STR ( set dev/write to screen )
,01 ,color STR ( set color )
- ,0020 ,x STR^ ( set x-pos )
- ,0030 ,y STR^ ( set y-pos )
+ ,0020 ,x STR2 ( set x-pos )
+ ,0030 ,y STR2 ( set y-pos )
,01 ,alive STR ( set alive = true )
BRK
@@ -18,25 +18,25 @@ BRK
|c000 @FRAME
,alive LDR ,00 EQU BRK?
- ,01 ,color LDR ,x LDR^ ,y LDR^ ,putpixel JSR
+ ,01 ,color LDR ,x LDR2 ,y LDR2 ,putpixel JSR
,move JSR
BRK
@move
- ,x LDR^ ,0001 ADD^ ,x STR^ ( incr x )
- ,x LDR^ ,0040 LTH^ RTS? ( if x > 60 )
- ,0020 ,x STR^ ( x = 0x0020 )
- ,y LDR^ ,0001 ADD^ ,y STR^ ( incr y )
+ ,x LDR2 ,0001 ADD2 ,x STR2 ( incr x )
+ ,x LDR2 ,0040 LTH2 RTS? ( if x > 60 )
+ ,0020 ,x STR2 ( x = 0x0020 )
+ ,y LDR2 ,0001 ADD2 ,y STR2 ( incr y )
- ,y LDR^ ,0050 LTH^ RTS? ( y > 50 )
+ ,y LDR2 ,0050 LTH2 RTS? ( y > 50 )
,00 ,alive STR ( alive = 0 )
RTS
@putpixel
- IOW^ ( y short )
- IOW^ ( x short )
+ IOW2 ( y short )
+ IOW2 ( x short )
IOW ( color byte )
IOW ( redraw byte )
RTS
diff --git a/examples/screen.usm b/examples/screen.usm
@@ -11,14 +11,14 @@
,01 DUP ,dev/r STR ,dev/w STR
( load screen size )
- ,00 IOR^ ,width STR^
- ,02 IOR^ ,height STR^
+ ,00 IOR2 ,width STR2
+ ,02 IOR2 ,height STR2
( draw pixel at screen center )
,0101
- ,width LDR^ ,0002 DIV^
- ,height LDR^ ,0002 DIV^
+ ,width LDR2 ,0002 DIV2
+ ,height LDR2 ,0002 DIV2
,putpixel JSR
BRK
@@ -26,8 +26,8 @@ BRK
|c000 @FRAME BRK
@putpixel
- IOW^ ( y short )
- IOW^ ( x short )
+ IOW2 ( y short )
+ IOW2 ( x short )
IOW ( color byte )
IOW ( redraw byte )
RTS
diff --git a/examples/test.usm b/examples/test.usm
@@ -9,7 +9,7 @@
,00 ,dev/w STR ( set dev/write to console )
- +1234 -0012 ADD^!
+ +1234 -0012 ADDS2
BRK