}
linenosym: directive EOL {
- if (p3) out(op, $1);
+ if (p3) out(op, $1);
$$ = $1;
}
| instruction EOL {
$$ = 0;
}
| bitsymbol BITDEF expr {
- if (p1) {
+ if (p1) {
build_sym_list(symbol_name);
mk_bit(symbol_name);
}
/* ignore global symbol declaration */
$$ = 0;
}
+ | '.' GLOBL bit {
+ /* ignore bit symbol declaration */
+ $$ = 0;
+ }
| '.' DS expr {
/* todo: if CSEG, emit some filler bytes */
$$ = $3;
#else
if (p->issfr) {
fprintf (sym_fp, "%-5s", "SFR");
- } else if (p->isbit) {
- fprintf (sym_fp, "%-5s", "BIT");
+ } else if (p->isbit && !p->area) {
+ fprintf (sym_fp, "%-5s", "SBIT");
} else {
fprintf (sym_fp, "%-5s", areaToString(p->area));
}
if (num > 0) fprintf(list_fp, "%06X: ", MEM_POS);
else fprintf(list_fp, "\t");
- for (i=0; i<num; i++) {
- hexout(byte_list[i], MEM_POS + i, 0);
- if (!first && (i % 4) == 0) fprintf(list_fp, "\t");
- fprintf(list_fp, "%02X", byte_list[i]);
- if ((i+1) % 4 == 0) {
- if (first) fprintf(list_fp, "\t%s\n", last_line_text);
- else fprintf(list_fp, "\n");
- first = 0;
- } else {
- if (i<num-1) fprintf(list_fp, " ");
- }
+ if (current_area==AREA_CSEG || current_area==AREA_XINIT) {
+ for (i=0; i<num; i++) {
+ hexout(byte_list[i], MEM_POS + i, 0);
+ if (!first && (i % 4) == 0) fprintf(list_fp, "\t");
+ fprintf(list_fp, "%02X", byte_list[i]);
+ if ((i+1) % 4 == 0) {
+ if (first) fprintf(list_fp, "\t%s\n", last_line_text);
+ else fprintf(list_fp, "\n");
+ first = 0;
+ } else {
+ if (i<num-1) fprintf(list_fp, " ");
+ }
+ }
}
if (first) {
if (num < 3) fprintf(list_fp, "\t");
CC = sdcc
-#CFLAGS=
-#MFLAGS=
+CFLAGS= -Wa-s -V
+MFLAGS= -mxa51
#LFLAGS=
all: hello.hex
hello.hex: hello.c
- $(CC) -mxa51 hello.c
+ $(CC) $(CFLAGS) $(MFLAGS) hello.c
clean:
rm -f core *~ \#* *.asm *.cdb *.rel *.hex *.ihx *.lst *.map \
- *.xa *.rst *.sym *.lnk *.lib *.bin *.dump*
+ *.xa *.rst *.sym *.lnk *.lib *.bin *.dump* *.log
+++ /dev/null
-enable_51 = yes
-enable_avr = yes
-enable_z80 = yes
-enable_xa = yes
-
-ifeq ($(enable_51),yes)
-S51 = s51.src
-else
-S51 =
-endif
-
-ifeq ($(enable_avr),yes)
-SAVR = avr.src
-else
-SAVR =
-endif
-
-ifeq ($(enable_z80),yes)
-SZ80 = z80.src
-else
-SZ80 =
-endif
-
-ifeq ($(enable_xa),yes)
-XA = xa.src
-else
-XA =
-endif
-
-PKGS = cmd.src sim.src gui.src $(S51) $(SAVR) $(SZ80) $(XA) doc
"CALL",
"RET",
"Bcc",
+"BEQ",
"JB",
"JNB",
"CJNE",
{0xff00,0xffff,' ',1,NOP, NO_OPERANDS }, // BRPT 1 1 1 1 1 1 1 1
{0x0840,0xfffc,' ',3,ANL, C_BIT }, // ANL C, bit 0 0 0 0 1 0 0 0 0 1 0 0 0 0 b b
- {0x0850,0xfffc,' ',3,ANL, NOTC_BIT }, // ANL C, /bit 0 0 0 0 1 0 0 0 0 1 0 1 0 0 b b
+ {0x0850,0xfffc,' ',3,ANL, C_NOTBIT }, // ANL C, /bit 0 0 0 0 1 0 0 0 0 1 0 1 0 0 b b
{0x0850,0xfffc,' ',3,ASL, REG_REG }, // ASL Rd, Rs 1 1 0 0 S S 0 1 d d d d s s s s
{0x900c,0xf70f,' ',2,CPL, REG_ALONE }, // CPL Rd 1 0 0 1 S 0 0 0 d d d d 1 0 1 0
{0xe708,0xff00,' ',2,DIV_w, REG_REG }, // DIV.w Rd, Rs 1 1 1 0 0 1 1 1 d d d d s s s s
{0x9607,0xff8f,' ',4,XOR, DIRECT_DATA8 }, // XOR direct, #data8 1 0 0 1 0 1 1 0 0 b b b 0 1 1 1
{0x9e07,0xff8f,' ',5,XOR, DIRECT_DATA16 }, // XOR direct, #data16 1 0 0 1 0 1 1 0 0 b b b 0 1 1 1
- { 0x0000, 0x00, 0, 1, BAD_OPCODE, REG_REG}
+ {0xc500,0xff00,' ',3,CALL, REL16 }, // CALL rel16 1 1 0 0 0 1 0 1 rel16
+ {0xc600,0xfff8,' ',2,CALL, IREG_ALONE }, // CALL [Rs] 1 1 0 0 0 1 1 0 0 0 0 0 0 s s s
+
+ {0xf300,0xff00,' ',2,BEQ, REL8 }, // BEQ rel8 1 1 1 1 0 0 1 1 rel8
+
+ {0x0000,0x0000, 0,1,BAD_OPCODE, REG_REG}
};
CALL,
RET,
Bcc,
+BEQ,
JB,
JNB,
CJNE,
// odd-ball ones
NO_OPERANDS, // for NOP
C_BIT,
- NOTC_BIT,
+ C_NOTBIT,
REG_DATA4,
IREG_DATA4,
IREGINC_DATA4,
DIRECT_DATA4,
REG_ALONE,
+ IREG_ALONE,
ADDR24,
REG_REL8,
- DIRECT_REL8
+ DIRECT_REL8,
+
+ REL8,
+ REL16,
};
// table of dissassembled instructions
{
int operands = code >> 16; // kludgy, param info
+#undef FUNC1
#define FUNC1 add1
+#undef FUNC2
#define FUNC2 add2
#include "inst_gen.cc"
{
int operands = code >> 16; // kludgy, param info
+#undef FUNC1
#define FUNC1 addc1
+#undef FUNC2
#define FUNC2 addc2
#include "inst_gen.cc"
immed_offset += 4;
break;
case DIRECT_DATA8 :
- sprintf(parm_str, "#%04d 0x%02x",
- ((code & 0x3) << 8) | get_mem(MEM_ROM, addr+immed_offset),
- get_mem(MEM_ROM, addr+immed_offset+1) );
+ sprintf(parm_str, "0x%03x,#0x%02x",
+ ((code & 0x0070) << 4) | get_mem(MEM_ROM, addr+immed_offset),
+ get_mem(MEM_ROM, addr+immed_offset+1));
immed_offset += 3;
break;
case DIRECT_DATA16 :
- sprintf(parm_str, "#%04d 0x%04x",
- ((code & 0x3) << 8) | get_mem(MEM_ROM, addr+immed_offset),
- (short)((get_mem(MEM_ROM, addr+immed_offset+2)) |
- (get_mem(MEM_ROM, addr+immed_offset+1)<<8)) );
+ sprintf(parm_str, "%0x03x,#0x%04x",
+ ((code & 0x0070) << 4) | get_mem(MEM_ROM, addr+immed_offset),
+ get_mem(MEM_ROM, addr+immed_offset+2) +
+ (get_mem(MEM_ROM, addr+immed_offset+1)<<8));
immed_offset += 3;
break;
sprintf(parm_str, "%s",
reg_strs[((code >> 4) & 0xf)] );
break;
+ case IREG_ALONE :
+ sprintf(parm_str, "[%s]",
+ reg_strs[((code >> 4) & 0xf)] );
+ break;
case ADDR24 :
strcpy(parm_str, "ADDR24");
break;
case DIRECT_REL8 :
strcpy(parm_str, "DIRECT_REL8");
break;
+
+ case REL8 :
+ //strcpy(parm_str, "REL8");
+ sprintf(parm_str, "0x%04x",
+ (get_mem(MEM_ROM, addr+1)*2+addr+len)&0xfffe);
+ break;
+ case REL16 :
+ //strcpy(parm_str, "REL16");
+ sprintf(parm_str, "0x%04x",
+ (((get_mem(MEM_ROM, addr+1)<<8) |
+ get_mem(MEM_ROM, addr+2))*2+addr+len)&0xfffe);
+ break;
+
default:
strcpy(parm_str, "???");
break;
}
}
-char *opRegName(operand *op, int offset, char *opName) {
+char *opRegName(operand *op, int offset, char *opName, bool decorate) {
if (IS_SYMOP(op)) {
if (OP_SYMBOL(op)->onStack) {
}
// fall through
case V_CHAR:
- sprintf (opName, "#0x%02x", SPEC_CVAL(OP_VALUE(op)->type).v_int);
+ sprintf (opName, "#%s0x%02x", decorate?"(char)":"",
+ SPEC_CVAL(OP_VALUE(op)->type).v_int);
break;
case V_INT:
if (SPEC_LONG(OP_VALUE(op)->type)) {
- sprintf (opName, "#0x%02lx", SPEC_CVAL(OP_VALUE(op)->type).v_long);
+ sprintf (opName, "#%s0x%02lx", decorate?"(long)":"",
+ SPEC_CVAL(OP_VALUE(op)->type).v_long);
} else {
- sprintf (opName, "#0x%02x", SPEC_CVAL(OP_VALUE(op)->type).v_int);
+ sprintf (opName, "#%s0x%02x", decorate?"(int)":"",
+ SPEC_CVAL(OP_VALUE(op)->type).v_int);
}
break;
case V_FLOAT:
- sprintf (opName, "#%f", SPEC_CVAL(OP_VALUE(op)->type).v_float);
+ sprintf (opName, "#%s%f", decorate?"(float)":"",
+ SPEC_CVAL(OP_VALUE(op)->type).v_float);
break;
default:
bailOut("opRegName: unexpected noun");
strcat (line, "unknown");
return line;
} else if (IS_VALOP(op)) {
- opRegName(op, 0, line);
+ opRegName(op, 0, line, 1);
} else if (IS_TYPOP(op)) {
sprintf (line, "[");
if (isPtr) {
}
/*-----------------------------------------------------------------*/
-/* genIpush - genrate code for pushing this gets a little complex */
+/* genIpush - generate code for pushing */
/*-----------------------------------------------------------------*/
static void genIpush (iCode * ic) {
+ operand *left=IC_LEFT(ic);
+
printIc ("genIpush", ic, 0,1,0);
+ aopOp(left,FALSE,FALSE);
+ if (AOP_TYPE(left)==AOP_LIT) {
+ switch (AOP_SIZE(left))
+ {
+ case 1:
+ emitcode ("mov", "r1l,%s", AOP_NAME(left)[0]);
+ emitcode ("push", "r1l");
+ return;
+ case 2:
+ emitcode ("mov", "r1,%s", AOP_NAME(left)[0]);
+ emitcode ("push", "r1");
+ return;
+ case 3:
+ emitcode ("mov", "r1l,%s", AOP_NAME(left)[1]);
+ emitcode ("push", "r1l");
+ emitcode ("mov", "r1,%s", AOP_NAME(left)[0]);
+ emitcode ("push", "r1");
+ return;
+ case 4:
+ emitcode ("mov", "r1,%s", AOP_NAME(left)[1]);
+ emitcode ("push", "r1");
+ emitcode ("mov", "r1,%s", AOP_NAME(left)[0]);
+ emitcode ("push", "r1");
+ return;
+ }
+ } else {
+ if (AOP_SIZE(left)>2) {
+ emitcode ("push", "%s", AOP_NAME(left)[1]);
+ }
+ emitcode ("push", "%s", AOP_NAME(left)[0]);
+ }
}
/*-----------------------------------------------------------------*/
/* genCall - generates a call statement */
/*-----------------------------------------------------------------*/
static void genCall (iCode * ic) {
- emitcode (";", "genCall %s result=%s", OP_SYMBOL(IC_LEFT(ic))->name,
+ operand *result=IC_RESULT(ic);
+
+ emitcode (";", "genCall(%d) %s result=%s", ic->lineno,
+ OP_SYMBOL(IC_LEFT(ic))->name,
printOp (IC_RESULT(ic)));
+ emitcode ("call", "%s", OP_SYMBOL(IC_LEFT(ic))->rname);
+
+ /* if we need to assign a result value */
+ if (IS_ITEMP (IC_RESULT(ic)) &&
+ OP_SYMBOL (IC_RESULT (ic))->nRegs) {
+ aopOp(result,FALSE,FALSE);
+ switch (AOP_SIZE(result))
+ {
+ case 1:
+ emitcode ("mov", "%s,r0l", AOP_NAME(result)[0]);
+ return;
+ case 2:
+ emitcode ("mov", "%s,r0", AOP_NAME(result)[0]);
+ return;
+ case 3:
+ // generic pointer
+ emitcode ("mov", "%s,r1l", AOP_NAME(result)[1]);
+ emitcode ("mov", "%s,r0", AOP_NAME(result)[0]);
+ return;
+ case 4:
+ emitcode ("mov", "%s,r1", AOP_NAME(result)[1]);
+ emitcode ("mov", "%s,r0", AOP_NAME(result)[0]);
+ return;
+ }
+ bailOut("genCall");
+ }
}
/*-----------------------------------------------------------------*/
while (lic) {
/* if operand of the form op = op + <sizeof *op> */
if (lic->op == '+') {
- fprintf (stderr, "isOperandEqual(IC_LEFT(lic),op):%d\n",
- isOperandEqual(IC_LEFT(lic),op));
- fprintf (stderr, "isOperandEqual(IC_RESULT(lic),op):%d\n",
- isOperandEqual(IC_RESULT(lic),op));
- fprintf (stderr, "isOperandLiteral(IC_RIGHT(lic)):%d\n",
- isOperandLiteral(IC_RIGHT(lic)));
- fprintf (stderr, "operandLitValue(IC_RIGHT(lic)) %f %d\n",
- operandLitValue(IC_RIGHT(lic)), isize);
if (isOperandEqual(IC_LEFT(lic),op) &&
//isOperandEqual(IC_RESULT(lic),op) &&
isOperandLiteral(IC_RIGHT(lic)) &&
static void
_xa51_genAssemblerPreamble (FILE * of)
{
+ symbol *mainExists=newSymbol("main", 0);
+ mainExists->block=0;
+
fprintf (of, "_errno\tsfr\t0x00; to keep the fp-lib's happy for now\n\n");
- fprintf (of, "\t.area CSEG\t(CODE)\n");
- fprintf (of, "__interrupt_vect:\n");
- fprintf (of, "\t.dw\t0x8f00\n");
- fprintf (of, "\t.dw\t__sdcc_gsinit_startup\n");
- fprintf (of, "\n");
- fprintf (of, "__sdcc_gsinit_startup:\n");
- fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc);
- fprintf (of, "\tcall\t_external_startup\n");
- _xa51_genXINIT(of);
- fprintf (of, "\tcall\t_main\n");
- fprintf (of, "\treset\t;main should not return\n");
+
+ if ((mainExists=findSymWithLevel(SymbolTab, mainExists))) {
+ fprintf (of, "\t.area CSEG\t(CODE)\n");
+ fprintf (of, "__interrupt_vect:\n");
+ fprintf (of, "\t.dw\t0x8f00\n");
+ fprintf (of, "\t.dw\t__sdcc_gsinit_startup\n");
+ fprintf (of, "\n");
+ fprintf (of, "__sdcc_gsinit_startup:\n");
+ fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc);
+ fprintf (of, "\tcall\t_external_startup\n");
+ _xa51_genXINIT(of);
+ fprintf (of, "\tcall\t_main\n");
+ fprintf (of, "\treset\t;main should not return\n");
+ }
}
/* dummy linker for now */