scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit f930047fb00b66be7171661d6ddb12415e82b31a
parent bb08aef03af276b006584ce2f26cc2de6391b8e4
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 16 Dec 2017 19:47:21 +0100

[as] Add string pseudo instruction

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

Diffstat:
Mas/ins.c | 33++++++++++++++++++++++++++++++++-
Mas/target/x80/x80.dat | 2++
2 files changed, 34 insertions(+), 1 deletion(-)

diff --git 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 @@ enum { EQU, COMMON, SIZE, + XSTRING, + ASCII, }; char * @@ -35,12 +39,39 @@ noargs(Op *op, Node **args) 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) diff --git 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