shithub: scc

Download patch

ref: c35217a1a61f795d312eede2f84faf59c7c06a3c
parent: dfa4c3e0944308b56ba4c3590c13a5060c56e759
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Dec 16 14:47:21 EST 2017

[as] Add string pseudo instruction

This pseudo instruction adds to the binary a character string
with a 0 at the end.

--- a/as/ins.c
+++ b/as/ins.c
@@ -1,5 +1,7 @@
 static char sccsid[] = "@(#) ./as/ins.c";
 
+#include <string.h>
+
 #include "../inc/scc.h"
 #include "as.h"
 
@@ -9,6 +11,8 @@
 	EQU,
 	COMMON,
 	SIZE,
+	XSTRING,
+	ASCII,
 };
 
 char *
@@ -35,12 +39,39 @@
 	emit(op->bytes, op->size);
 }
 
+static void
+xstring(int which, Node **args)
+{
+	Node *np;
+	char *s;
+	size_t len;
+
+	while (np = *args++) {
+		s = np->sym->name.buf;
+		len = strlen(s);
+		len += which == XSTRING;
+		emit(s, len);
+	}
+}
+
 void
+string(Op *op, Node **args)
+{
+	xstring(STRING, args);
+}
+
+void
+ascii(Op *op, Node **args)
+{
+	xstring(STRING, args);
+}
+
+void
 def(Node **args, int siz)
 {
 	Node *np;
 
-	for ( ; np = *args; ++args) {
+	while (np = *args++) {
 		Symbol *sym = np->sym;
 
 		if (sym->flags & FRELOC)
--- a/as/target/x80/x80.dat
+++ b/as/target/x80/x80.dat
@@ -26,6 +26,8 @@
 .COMM	imm16	0	none	common	Z80,R800,GB80
 .GLOBL	sym+	0	none	global	Z80,R800,GB80
 .EXTERN	sym+	0	none	extrn	Z80,R800,GB80
+.STRING	string+	0	none	string	Z80,R800,GB80
+.ASCII	string+	0	none	ascii	Z80,R800,GB80
 
 NOP	none	1	0x00	noargs	Z80,R800,GB80
 EI	none	1	0xfb	noargs	Z80,R800,GB80