OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [asmdata.cpp] - Diff between revs 126 and 143

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 126 Rev 143
Line 38... Line 38...
 
 
#include <stdlib.h>
#include <stdlib.h>
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
#include "asmdata.h"
#include "asmdata.h"
 
#include "twoc.h"
 
 
extern  void    yyerror(const char *str);
extern  void    yyerror(const char *str);
 
 
unsigned int    ILINE::eval(const int lno) {
unsigned int    ILINE::eval(const int lno) {
        return (lno==0)?m_in:DEFAULT_LINE;
        return (lno==0)?m_in:DEFAULT_LINE;
Line 274... Line 275...
                                fprintf(stderr, "m_imm = %d\n", imm);
                                fprintf(stderr, "m_imm = %d\n", imm);
                        } else if (!fitsin(imm, 13))
                        } else if (!fitsin(imm, 13))
                                yyerror("Immediate overflow on move");
                                yyerror("Immediate overflow on move");
                        in = zp.op_mov(m_cond, imm, m_opb, m_opa);
                        in = zp.op_mov(m_cond, imm, m_opb, m_opa);
                        break;
                        break;
 
#ifdef  LONG_MPY
 
                case OP_MPY:
 
                        BLD_DUALOP(op_mpy);
 
                        break;
 
#else
                case OP_LDIHI:
                case OP_LDIHI:
                        if ((imm & (-1<<16))!=0)
                        if ((imm & (-1<<16))!=0)
                                yyerror("16-bit Immediate out of range");
                                yyerror("16-bit Immediate out of range");
                        if (m_opb != zp.ZIP_Rnone)
                        if (m_opb != zp.ZIP_Rnone)
                                yyerror("LDIHI cannot accept OP-B registers");
                                yyerror("LDIHI cannot accept OP-B registers");
                        if (m_opa == zp.ZIP_Rnone)
                        if (m_opa == zp.ZIP_Rnone)
                                yyerror("LDIHI needs a register result");
                                yyerror("LDIHI needs a register result");
                        in = zp.op_ldihi(m_cond, imm, m_opa);
                        in = zp.op_ldihi(m_cond, imm, m_opa);
                        break;
                        break;
 
#endif
                case OP_LDILO:
                case OP_LDILO:
                        if ((imm & (-1<<16))!=0)
                        if ((imm & (-1<<16))!=0)
                                yyerror("16-bit Immediate out of range");
                                yyerror("16-bit Immediate out of range");
                        if (m_opb != zp.ZIP_Rnone)
                        if (m_opb != zp.ZIP_Rnone)
                                yyerror("LDIHI cannot accept OP-B registers");
                                yyerror("LDIHI cannot accept OP-B registers");
Line 294... Line 301...
                                yyerror("LDIHI needs a register result");
                                yyerror("LDIHI needs a register result");
                        if ((imm & (-1<<16))!=0)
                        if ((imm & (-1<<16))!=0)
                                yyerror("16-bit Immediate out of range");
                                yyerror("16-bit Immediate out of range");
                        in = zp.op_ldilo(m_cond, imm, m_opa);
                        in = zp.op_ldilo(m_cond, imm, m_opa);
                        break;
                        break;
 
#ifdef  LONG_MPY
 
                case OP_MPYUHI:
 
                        BLD_DUALOP(op_mpyuhi);
 
                        break;
 
                case OP_MPYSHI:
 
                        BLD_DUALOP(op_mpyshi);
 
                        break;
 
#else
                case OP_MPYU:
                case OP_MPYU:
                        if ((m_opb == zp.ZIP_PC)||(m_opb == zp.ZIP_CC)
                        if ((m_opb == zp.ZIP_PC)||(m_opb == zp.ZIP_CC)
                                ||(m_opa == zp.ZIP_PC)||(m_opa == zp.ZIP_CC))
                                ||(m_opa == zp.ZIP_PC)||(m_opa == zp.ZIP_CC))
                                yyerror("MPYU does not support PC or CC register operands or results");
                                yyerror("MPYU does not support PC or CC register operands or results");
                        else if (m_opb == zp.ZIP_Rnone)
                        else if (m_opb == zp.ZIP_Rnone)
Line 312... Line 327...
                        else if (m_opb == zp.ZIP_Rnone)
                        else if (m_opb == zp.ZIP_Rnone)
                                in = zp.op_mpys(m_cond, imm, m_opa);
                                in = zp.op_mpys(m_cond, imm, m_opa);
                        else
                        else
                                in = zp.op_mpys(m_cond, imm, m_opb, m_opa);
                                in = zp.op_mpys(m_cond, imm, m_opb, m_opa);
                        break;
                        break;
 
#endif
                case OP_ROL:
                case OP_ROL:
                        if (m_opa == zp.ZIP_Rnone)
                        if (m_opa == zp.ZIP_Rnone)
                                yyerror("ROL needs a register result");
                                yyerror("ROL needs a register result");
                        if (m_opb != zp.ZIP_Rnone)
                        if (m_opb != zp.ZIP_Rnone)
                                in = zp.op_rol(m_cond, imm, m_opb, m_opa);
                                in = zp.op_rol(m_cond, imm, m_opb, m_opa);
Line 363... Line 379...
                        break;
                        break;
                case OP_POPC:
                case OP_POPC:
                        BLD_DUALOP(op_popc);
                        BLD_DUALOP(op_popc);
                        break;
                        break;
                case OP_LDI:
                case OP_LDI:
                        if ((!fitsin(imm, 23))||(m_cond != zp.ZIPC_ALWAYS)) {
                        if (fitsin(zp.brev(imm),18)) {
 
                                imm = zp.brev(imm);
 
                                BLD_DUALOP(op_brev);
 
                        } else if ((!fitsin(imm, 23))||(m_cond != zp.ZIPC_ALWAYS)) {
                                if (m_opa == zp.ZIP_PC)
                                if (m_opa == zp.ZIP_PC)
                                        yyerror("Cannot LDI 32-bit addresses into PC register!");
                                        yyerror("Cannot LDI 32-bit addresses into PC register!");
                                LLINE *lln = new LLINE;
                                LLINE *lln = new LLINE;
 
#ifdef  LONG_MPY
 
                                lln->addline(new ILINE(zp.op_brev(m_cond, sbits(zp.brev(imm),18), m_opa)));
 
#else
                                lln->addline(new ILINE(zp.op_ldihi(m_cond, (imm>>16)&0x0ffff, m_opa)));
                                lln->addline(new ILINE(zp.op_ldihi(m_cond, (imm>>16)&0x0ffff, m_opa)));
 
#endif
                                lln->addline(new ILINE(zp.op_ldilo(m_cond, imm&0x0ffff, m_opa)));
                                lln->addline(new ILINE(zp.op_ldilo(m_cond, imm&0x0ffff, m_opa)));
                                lln->m_lineno = m_lineno;
                                lln->m_lineno = m_lineno;
                                return lln;
                                return lln;
                        } else
                        } else
                                in = zp.op_ldi(imm, m_opa);
                                in = zp.op_ldi(imm, m_opa);
Line 459... Line 482...
                        break;
                        break;
                case OP_RETN:   // yywarn("RETN opcode is deprecated");
                case OP_RETN:   // yywarn("RETN opcode is deprecated");
                                in = zp.op_lod(m_cond, imm, m_opb, m_opa);
                                in = zp.op_lod(m_cond, imm, m_opb, m_opa);
                                in = zp.op_lod(m_cond, -1, zp.ZIP_SP, zp.ZIP_PC);
                                in = zp.op_lod(m_cond, -1, zp.ZIP_SP, zp.ZIP_PC);
                        break;
                        break;
                case OP_MPY:
 
                        if ((m_opb == zp.ZIP_PC)||(m_opb == zp.ZIP_CC)
 
                                ||(m_opa == zp.ZIP_PC)||(m_opa == zp.ZIP_CC))
 
                                yyerror("MPY does not support PC or CC register operands or results");
 
                        else if (m_opb == zp.ZIP_Rnone)
 
                                in = zp.op_mpy(m_cond, imm, m_opa);
 
                        else
 
                                in = zp.op_mpy(m_cond, imm, m_opb, m_opa);
 
                        break;
 
                case OP_MPYUHI:
 
                        if ((m_opb == zp.ZIP_PC)||(m_opb == zp.ZIP_CC)
 
                                ||(m_opa == zp.ZIP_PC)||(m_opa == zp.ZIP_CC))
 
                                yyerror("MPY does not support PC or CC register operands or results");
 
                        else if (m_opb == zp.ZIP_Rnone)
 
                                in = zp.op_mpyuhi(m_cond, imm, m_opa);
 
                        else
 
                                in = zp.op_mpyuhi(m_cond, imm, m_opb, m_opa);
 
                        break;
 
                case OP_MPYSHI:
 
                        if ((m_opb == zp.ZIP_PC)||(m_opb == zp.ZIP_CC)
 
                                ||(m_opa == zp.ZIP_PC)||(m_opa == zp.ZIP_CC))
 
                                yyerror("MPY does not support PC or CC register operands or results");
 
                        else if (m_opb == zp.ZIP_Rnone)
 
                                in = zp.op_mpyshi(m_cond, imm, m_opa);
 
                        else
 
                                in = zp.op_mpyshi(m_cond, imm, m_opb, m_opa);
 
                        break;
 
                case OP_HALT:   in = zp.op_halt(m_cond); break;
                case OP_HALT:   in = zp.op_halt(m_cond); break;
                case OP_RTU:    in = zp.op_rtu(m_cond); break;
                case OP_RTU:    in = zp.op_rtu(m_cond); break;
                case OP_BUSY:   in = zp.op_busy(m_cond); break;
                case OP_BUSY:   in = zp.op_busy(m_cond); break;
                case OP_NOOP:   in = zp.op_noop(); break;
                case OP_NOOP:   in = zp.op_noop(); break;
                case OP_BREAK:  in = zp.op_break(); break;
                case OP_BREAK:  in = zp.op_break(); break;
Line 537... Line 533...
                        break;
                        break;
                case OP_TST: fprintf(fp, "\tTLINE OP   = TST\n");
                case OP_TST: fprintf(fp, "\tTLINE OP   = TST\n");
                        break;
                        break;
                case OP_MOV: fprintf(fp, "\tTLINE OP   = MOV\n");
                case OP_MOV: fprintf(fp, "\tTLINE OP   = MOV\n");
                        break;
                        break;
 
#ifdef  LONG_MPY
 
                case OP_MPY: fprintf(fp,"\tTLINE OP   = MPY\n");
 
                        break;
 
#else
                case OP_LDIHI:fprintf(fp,"\tTLINE OP   = LDIHI\n");
                case OP_LDIHI:fprintf(fp,"\tTLINE OP   = LDIHI\n");
                        break;
                        break;
 
#endif
                case OP_LDILO:fprintf(fp,"\tTLINE OP   = LDILO\n");
                case OP_LDILO:fprintf(fp,"\tTLINE OP   = LDILO\n");
                        break;
                        break;
 
#ifdef  LONG_MPY
 
                case OP_MPYUHI: fprintf(fp,"\tTLINE OP   = MPYUHI\n");
 
                        break;
 
                case OP_MPYSHI: fprintf(fp,"\tTLINE OP   = MPYSHI\n");
 
                        break;
 
#else
                case OP_MPYU: fprintf(fp,"\tTLINE OP   = MPYU\n");
                case OP_MPYU: fprintf(fp,"\tTLINE OP   = MPYU\n");
                        break;
                        break;
                case OP_MPYS: fprintf(fp,"\tTLINE OP   = MPYS\n");
                case OP_MPYS: fprintf(fp,"\tTLINE OP   = MPYS\n");
                        break;
                        break;
 
#endif
                case OP_ROL: fprintf(fp, "\tTLINE OP   = ROL\n");
                case OP_ROL: fprintf(fp, "\tTLINE OP   = ROL\n");
                        break;
                        break;
                case OP_SUB: fprintf(fp, "\tTLINE OP   = SUB\n");
                case OP_SUB: fprintf(fp, "\tTLINE OP   = SUB\n");
                        break;
                        break;
                case OP_AND: fprintf(fp, "\tTLINE OP   = AND\n");
                case OP_AND: fprintf(fp, "\tTLINE OP   = AND\n");

powered by: WebSVN 2.1.0

© copyright 1999-2022 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.