void JitArm64::mcrxr(UGeckoInstruction inst)
{
  INSTRUCTION_START
  JITDISABLE(bJITSystemRegistersOff);

  ARM64Reg WA = gpr.GetReg();
  ARM64Reg XA = EncodeRegTo64(WA);
  ARM64Reg WB = gpr.GetReg();
  ARM64Reg XB = EncodeRegTo64(WB);

  // Copy XER[0-3] into CR[inst.CRFD]
  LDRB(INDEX_UNSIGNED, WA, PPC_REG, PPCSTATE_OFF(xer_ca));
  LDRB(INDEX_UNSIGNED, WB, PPC_REG, PPCSTATE_OFF(xer_so_ov));

  // [0 SO OV CA]
  ADD(WA, WA, WB, ArithOption(WB, ST_LSL, 2));
  // [SO OV CA 0] << 3
  LSL(WA, WA, 4);

  MOVP2R(XB, m_crTable);
  LDR(XB, XB, XA);
  STR(INDEX_UNSIGNED, XB, PPC_REG, PPCSTATE_OFF(cr_val[inst.CRFD]));

  // Clear XER[0-3]
  STRB(INDEX_UNSIGNED, WZR, PPC_REG, PPCSTATE_OFF(xer_ca));
  STRB(INDEX_UNSIGNED, WZR, PPC_REG, PPCSTATE_OFF(xer_so_ov));

  gpr.Unlock(WA, WB);
}
Exemple #2
0
void GGLAssembler::build_fog(
                        component_t& temp,      // incomming fragment / output
                        int component,
                        Scratch& regs)
{
   if (mInfo[component].fog) {
        Scratch scratches(registerFile());
        comment("fog");

        integer_t fragment(temp.reg, temp.h, temp.flags);
        if (!(temp.flags & CORRUPTIBLE)) {
            temp.reg = regs.obtain();
            temp.flags |= CORRUPTIBLE;
        }

        integer_t fogColor(scratches.obtain(), 8, CORRUPTIBLE); 
        LDRB(AL, fogColor.reg, mBuilderContext.Rctx,
                immed12_pre(GGL_OFFSETOF(state.fog.color[component])));

        integer_t factor(scratches.obtain(), 16, CORRUPTIBLE);
        CONTEXT_LOAD(factor.reg, generated_vars.f);

        // clamp fog factor (TODO: see if there is a way to guarantee
        // we won't overflow, when setting the iterators)
        BIC(AL, 0, factor.reg, factor.reg, reg_imm(factor.reg, ASR, 31));
        CMP(AL, factor.reg, imm( 0x10000 ));
        MOV(HS, 0, factor.reg, imm( 0x10000 ));

        build_blendFOneMinusF(temp, factor, fragment, fogColor);
    }
}
void JitArm::UnsafeLoadToReg(ARMReg dest, ARMReg addr, int accessSize, s32 offsetReg, s32 offset)
{
	ARMReg rA = gpr.GetReg();
	if (offsetReg == -1)
	{
		MOVI2R(rA, offset, false); // -3
		ADD(addr, addr, rA); // - 1
	}
	else
	{
		NOP(2); // -3, -2
		// offsetReg is preloaded here
		ADD(addr, addr, gpr.R(offsetReg)); // -1
	}

	// All this gets replaced on backpatch
	Operand2 mask(2, 1); // ~(Memory::MEMVIEW32_MASK)
	BIC(addr, addr, mask); // 1
	MOVI2R(rA, (u32)Memory::base, false); // 2-3
	ADD(addr, addr, rA); // 4
	switch (accessSize)
	{
		case 32:
			LDR(dest, addr); // 5
		break;
		case 16:
			LDRH(dest, addr);
		break;
		case 8:
			LDRB(dest, addr);
		break;
	}
	switch (accessSize)
	{
		case 32:
			REV(dest, dest); // 6
		break;
		case 16:
			REV16(dest, dest);
		break;
		case 8:
			NOP(1);
		break;

	}
	NOP(2); // 7-8
	gpr.Unlock(rA);
}
void GGLAssembler::load(const pointer_t& addr, const pixel_t& s, uint32_t flags)
{    
    Scratch scratches(registerFile());    
    int s0;

    const int bits = addr.size;
    const int inc = (flags & WRITE_BACK)?1:0;
    switch (bits) {
    case 32:
        if (inc)    LDR(AL, s.reg, addr.reg, immed12_post(4));
        else        LDR(AL, s.reg, addr.reg);
        break;
    case 24:
        // 24 bits formats are a little special and used only for RGB
        // R,G,B is packed as 0x00BBGGRR 
        s0 = scratches.obtain();
        if (s.reg != addr.reg) {
            LDRB(AL, s.reg, addr.reg, immed12_pre(0));      // R
            LDRB(AL, s0, addr.reg, immed12_pre(1));         // G
            ORR(AL, 0, s.reg, s.reg, reg_imm(s0, LSL, 8));
            LDRB(AL, s0, addr.reg, immed12_pre(2));         // B
            ORR(AL, 0, s.reg, s.reg, reg_imm(s0, LSL, 16));
        } else {
            int s1 = scratches.obtain();
            LDRB(AL, s1, addr.reg, immed12_pre(0));         // R
            LDRB(AL, s0, addr.reg, immed12_pre(1));         // G
            ORR(AL, 0, s1, s1, reg_imm(s0, LSL, 8));
            LDRB(AL, s0, addr.reg, immed12_pre(2));         // B
            ORR(AL, 0, s.reg, s1, reg_imm(s0, LSL, 16));
        }
        if (inc)
            ADD(AL, 0, addr.reg, addr.reg, imm(3));
        break;        
    case 16:
        if (inc)    LDRH(AL, s.reg, addr.reg, immed8_post(2));
        else        LDRH(AL, s.reg, addr.reg);
        break;
    case  8:
        if (inc)    LDRB(AL, s.reg, addr.reg, immed12_post(1));
        else        LDRB(AL, s.reg, addr.reg);
        break;
    }
}
void JitArm64::mfspr(UGeckoInstruction inst)
{
	INSTRUCTION_START
	JITDISABLE(bJITSystemRegistersOff);

	u32 iIndex = (inst.SPRU << 5) | (inst.SPRL & 0x1F);
	int d = inst.RD;
	switch (iIndex)
	{
	case SPR_TL:
	case SPR_TU:
	{
		ARM64Reg WA = gpr.GetReg();
		ARM64Reg WB = gpr.GetReg();
		ARM64Reg XA = EncodeRegTo64(WA);
		ARM64Reg XB = EncodeRegTo64(WB);

		// An inline implementation of CoreTiming::GetFakeTimeBase, since in timer-heavy games the
		// cost of calling out to C for this is actually significant.
		MOVI2R(XA, (u64)&CoreTiming::globalTimer);
		LDR(INDEX_UNSIGNED, XA, XA, 0);
		MOVI2R(XB, (u64)&CoreTiming::fakeTBStartTicks);
		LDR(INDEX_UNSIGNED, XB, XB, 0);
		SUB(XA, XA, XB);

		// It might seem convenient to correct the timer for the block position here for even more accurate
		// timing, but as of currently, this can break games. If we end up reading a time *after* the time
		// at which an interrupt was supposed to occur, e.g. because we're 100 cycles into a block with only
		// 50 downcount remaining, some games don't function correctly, such as Karaoke Party Revolution,
		// which won't get past the loading screen.
		// a / 12 = (a * 0xAAAAAAAAAAAAAAAB) >> 67
		ORR(XB, SP, 1, 60);
		ADD(XB, XB, 1);
		UMULH(XA, XA, XB);

		MOVI2R(XB, (u64)&CoreTiming::fakeTBStartValue);
		LDR(INDEX_UNSIGNED, XB, XB, 0);
		ADD(XA, XB, XA, ArithOption(XA, ST_LSR, 3));
		STR(INDEX_UNSIGNED, XA, X29, PPCSTATE_OFF(spr[SPR_TL]));

		if (MergeAllowedNextInstructions(1))
		{
			const UGeckoInstruction& next = js.op[1].inst;
			// Two calls of TU/TL next to each other are extremely common in typical usage, so merge them
			// if we can.
			u32 nextIndex = (next.SPRU << 5) | (next.SPRL & 0x1F);
			// Be careful; the actual opcode is for mftb (371), not mfspr (339)
			int n = next.RD;
			if (next.OPCD == 31 && next.SUBOP10 == 371 && (nextIndex == SPR_TU || nextIndex == SPR_TL) && n != d)
			{
				js.downcountAmount++;
				js.skipInstructions = 1;
				gpr.BindToRegister(d, false);
				gpr.BindToRegister(n, false);
				if (iIndex == SPR_TL)
					MOV(gpr.R(d), WA);
				else
					ORR(EncodeRegTo64(gpr.R(d)), SP, XA, ArithOption(XA, ST_LSR, 32));

				if (nextIndex == SPR_TL)
					MOV(gpr.R(n), WA);
				else
					ORR(EncodeRegTo64(gpr.R(n)), SP, XA, ArithOption(XA, ST_LSR, 32));

				gpr.Unlock(WA, WB);
				break;
			}
		}
		gpr.BindToRegister(d, false);
		if (iIndex == SPR_TU)
			ORR(EncodeRegTo64(gpr.R(d)), SP, XA, ArithOption(XA, ST_LSR, 32));
		else
			MOV(gpr.R(d), WA);
		gpr.Unlock(WA, WB);
	}
	break;
	case SPR_XER:
	{
		gpr.BindToRegister(d, false);
		ARM64Reg RD = gpr.R(d);
		ARM64Reg WA = gpr.GetReg();
		LDRH(INDEX_UNSIGNED, RD, X29, PPCSTATE_OFF(xer_stringctrl));
		LDRB(INDEX_UNSIGNED, WA, X29, PPCSTATE_OFF(xer_ca));
		ORR(RD, RD, WA, ArithOption(WA, ST_LSL, XER_CA_SHIFT));
		LDRB(INDEX_UNSIGNED, WA, X29, PPCSTATE_OFF(xer_so_ov));
		ORR(RD, RD, WA, ArithOption(WA, ST_LSL, XER_OV_SHIFT));
		gpr.Unlock(WA);
	}
	break;
	case SPR_WPAR:
	case SPR_DEC:
		FALLBACK_IF(true);
	default:
		gpr.BindToRegister(d, false);
		ARM64Reg RD = gpr.R(d);
		LDR(INDEX_UNSIGNED, RD, X29, PPCSTATE_OFF(spr) + iIndex * 4);
		break;
	}
}
int GGLAssembler::scanline_core(const needs_t& needs, context_t const* c)
{
    int64_t duration = ggl_system_time();

    mBlendFactorCached = 0;
    mBlending = 0;
    mMasking = 0;
    mAA        = GGL_READ_NEEDS(P_AA, needs.p);
    mDithering = GGL_READ_NEEDS(P_DITHER, needs.p);
    mAlphaTest = GGL_READ_NEEDS(P_ALPHA_TEST, needs.p) + GGL_NEVER;
    mDepthTest = GGL_READ_NEEDS(P_DEPTH_TEST, needs.p) + GGL_NEVER;
    mFog       = GGL_READ_NEEDS(P_FOG, needs.p) != 0;
    mSmooth    = GGL_READ_NEEDS(SHADE, needs.n) != 0;
    mBuilderContext.needs = needs;
    mBuilderContext.c = c;
    mBuilderContext.Rctx = reserveReg(R0); // context always in R0
    mCbFormat = c->formats[ GGL_READ_NEEDS(CB_FORMAT, needs.n) ];

    // ------------------------------------------------------------------------

    decodeLogicOpNeeds(needs);

    decodeTMUNeeds(needs, c);

    mBlendSrc  = ggl_needs_to_blendfactor(GGL_READ_NEEDS(BLEND_SRC, needs.n));
    mBlendDst  = ggl_needs_to_blendfactor(GGL_READ_NEEDS(BLEND_DST, needs.n));
    mBlendSrcA = ggl_needs_to_blendfactor(GGL_READ_NEEDS(BLEND_SRCA, needs.n));
    mBlendDstA = ggl_needs_to_blendfactor(GGL_READ_NEEDS(BLEND_DSTA, needs.n));

    if (!mCbFormat.c[GGLFormat::ALPHA].h) {
        if ((mBlendSrc == GGL_ONE_MINUS_DST_ALPHA) ||
            (mBlendSrc == GGL_DST_ALPHA)) {
            mBlendSrc = GGL_ONE;
        }
        if ((mBlendSrcA == GGL_ONE_MINUS_DST_ALPHA) ||
            (mBlendSrcA == GGL_DST_ALPHA)) {
            mBlendSrcA = GGL_ONE;
        }
        if ((mBlendDst == GGL_ONE_MINUS_DST_ALPHA) ||
            (mBlendDst == GGL_DST_ALPHA)) {
            mBlendDst = GGL_ONE;
        }
        if ((mBlendDstA == GGL_ONE_MINUS_DST_ALPHA) ||
            (mBlendDstA == GGL_DST_ALPHA)) {
            mBlendDstA = GGL_ONE;
        }
    }

    // if we need the framebuffer, read it now
    const int blending =    blending_codes(mBlendSrc, mBlendDst) |
                            blending_codes(mBlendSrcA, mBlendDstA);

    // XXX: handle special cases, destination not modified...
    if ((mBlendSrc==GGL_ZERO) && (mBlendSrcA==GGL_ZERO) &&
        (mBlendDst==GGL_ONE) && (mBlendDstA==GGL_ONE)) {
        // Destination unmodified (beware of logic ops)
    } else if ((mBlendSrc==GGL_ZERO) && (mBlendSrcA==GGL_ZERO) &&
        (mBlendDst==GGL_ZERO) && (mBlendDstA==GGL_ZERO)) {
        // Destination is zero (beware of logic ops)
    }
    
    int fbComponents = 0;
    const int masking = GGL_READ_NEEDS(MASK_ARGB, needs.n);
    for (int i=0 ; i<4 ; i++) {
        const int mask = 1<<i;
        component_info_t& info = mInfo[i];
        int fs = i==GGLFormat::ALPHA ? mBlendSrcA : mBlendSrc;
        int fd = i==GGLFormat::ALPHA ? mBlendDstA : mBlendDst;
        if (fs==GGL_SRC_ALPHA_SATURATE && i==GGLFormat::ALPHA)
            fs = GGL_ONE;
        info.masked =   !!(masking & mask);
        info.inDest =   !info.masked && mCbFormat.c[i].h && 
                        ((mLogicOp & LOGIC_OP_SRC) || (!mLogicOp));
        if (mCbFormat.components >= GGL_LUMINANCE &&
                (i==GGLFormat::GREEN || i==GGLFormat::BLUE)) {
            info.inDest = false;
        }
        info.needed =   (i==GGLFormat::ALPHA) && 
                        (isAlphaSourceNeeded() || mAlphaTest != GGL_ALWAYS);
        info.replaced = !!(mTextureMachine.replaced & mask);
        info.iterated = (!info.replaced && (info.inDest || info.needed)); 
        info.smooth =   mSmooth && info.iterated;
        info.fog =      mFog && info.inDest && (i != GGLFormat::ALPHA);
        info.blend =    (fs != int(GGL_ONE)) || (fd > int(GGL_ZERO));

        mBlending |= (info.blend ? mask : 0);
        mMasking |= (mCbFormat.c[i].h && info.masked) ? mask : 0;
        fbComponents |= mCbFormat.c[i].h ? mask : 0;
    }

    mAllMasked = (mMasking == fbComponents);
    if (mAllMasked) {
        mDithering = 0;
    }
    
    fragment_parts_t parts;

    // ------------------------------------------------------------------------
    prolog();
    // ------------------------------------------------------------------------

    build_scanline_prolog(parts, needs);

    if (registerFile().status())
        return registerFile().status();

    // ------------------------------------------------------------------------
    label("fragment_loop");
    // ------------------------------------------------------------------------
    {
        Scratch regs(registerFile());

        if (mDithering) {
            // update the dither index.
            MOV(AL, 0, parts.count.reg,
                    reg_imm(parts.count.reg, ROR, GGL_DITHER_ORDER_SHIFT));
            ADD(AL, 0, parts.count.reg, parts.count.reg,
                    imm( 1 << (32 - GGL_DITHER_ORDER_SHIFT)));
            MOV(AL, 0, parts.count.reg,
                    reg_imm(parts.count.reg, ROR, 32 - GGL_DITHER_ORDER_SHIFT));
        }

        // XXX: could we do an early alpha-test here in some cases?
        // It would probaly be used only with smooth-alpha and no texture
        // (or no alpha component in the texture).

        // Early z-test
        if (mAlphaTest==GGL_ALWAYS) {
            build_depth_test(parts, Z_TEST|Z_WRITE);
        } else {
            // we cannot do the z-write here, because
            // it might be killed by the alpha-test later
            build_depth_test(parts, Z_TEST);
        }

        { // texture coordinates
            Scratch scratches(registerFile());

            // texel generation
            build_textures(parts, regs);
            if (registerFile().status())
                return registerFile().status();
        }

        if ((blending & (FACTOR_DST|BLEND_DST)) || 
                (mMasking && !mAllMasked) ||
                (mLogicOp & LOGIC_OP_DST)) 
        {
            // blending / logic_op / masking need the framebuffer
            mDstPixel.setTo(regs.obtain(), &mCbFormat);

            // load the framebuffer pixel
            comment("fetch color-buffer");
            load(parts.cbPtr, mDstPixel);
        }

        if (registerFile().status())
            return registerFile().status();

        pixel_t pixel;
        int directTex = mTextureMachine.directTexture;
        if (directTex | parts.packed) {
            // note: we can't have both here
            // iterated color or direct texture
            pixel = directTex ? parts.texel[directTex-1] : parts.iterated;
            pixel.flags &= ~CORRUPTIBLE;
        } else {
            if (mDithering) {
                const int ctxtReg = mBuilderContext.Rctx;
                const int mask = GGL_DITHER_SIZE-1;
                parts.dither = reg_t(regs.obtain());
                AND(AL, 0, parts.dither.reg, parts.count.reg, imm(mask));
                ADDR_ADD(AL, 0, parts.dither.reg, ctxtReg, parts.dither.reg);
                LDRB(AL, parts.dither.reg, parts.dither.reg,
                        immed12_pre(GGL_OFFSETOF(ditherMatrix)));
            }
        
            // allocate a register for the resulting pixel
            pixel.setTo(regs.obtain(), &mCbFormat, FIRST);

            build_component(pixel, parts, GGLFormat::ALPHA,    regs);

            if (mAlphaTest!=GGL_ALWAYS) {
                // only handle the z-write part here. We know z-test
                // was successful, as well as alpha-test.
                build_depth_test(parts, Z_WRITE);
            }

            build_component(pixel, parts, GGLFormat::RED,      regs);
            build_component(pixel, parts, GGLFormat::GREEN,    regs);
            build_component(pixel, parts, GGLFormat::BLUE,     regs);

            pixel.flags |= CORRUPTIBLE;
        }

        if (registerFile().status())
            return registerFile().status();
        
        if (pixel.reg == -1) {
            // be defensive here. if we're here it's probably
            // that this whole fragment is a no-op.
            pixel = mDstPixel;
        }
        
        if (!mAllMasked) {
            // logic operation
            build_logic_op(pixel, regs);
    
            // masking
            build_masking(pixel, regs); 
    
            comment("store");
            store(parts.cbPtr, pixel, WRITE_BACK);
        }
    }

    if (registerFile().status())
        return registerFile().status();

    // update the iterated color...
    if (parts.reload != 3) {
        build_smooth_shade(parts);
    }

    // update iterated z
    build_iterate_z(parts);

    // update iterated fog
    build_iterate_f(parts);

    SUB(AL, S, parts.count.reg, parts.count.reg, imm(1<<16));
    B(PL, "fragment_loop");
    label("epilog");
    epilog(registerFile().touched());

    if ((mAlphaTest!=GGL_ALWAYS) || (mDepthTest!=GGL_ALWAYS)) {
        if (mDepthTest!=GGL_ALWAYS) {
            label("discard_before_textures");
            build_iterate_texture_coordinates(parts);
        }
        label("discard_after_textures");
        build_smooth_shade(parts);
        build_iterate_z(parts);
        build_iterate_f(parts);
        if (!mAllMasked) {
            ADDR_ADD(AL, 0, parts.cbPtr.reg, parts.cbPtr.reg, imm(parts.cbPtr.size>>3));
        }
        SUB(AL, S, parts.count.reg, parts.count.reg, imm(1<<16));
        B(PL, "fragment_loop");
        epilog(registerFile().touched());
    }
Exemple #7
0
void decodeInstruction(instruction_t instruction,uint32_t *registro,flags_t *bandera, uint8_t *SRAM, uint16_t *codificacion, char **Flash)
{
    int i;
    *codificacion=0;    // valor incial
	//	comparar el mnemonic con el nombre de cada una de las funciones, y asi ejecutar la adecuada
	if( strcmp(instruction.mnemonic,"LDR") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
        {
            *codificacion=(13<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            instruction.op3_value<<=2;
            if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000))
            {
                LDR(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,SRAM);
            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000)
            {
                //IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Read);
            }
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='S') && (instruction.op3_type=='#'))
        {
            *codificacion=(19<<11)+(instruction.op1_value<<8)+instruction.op3_value;
            instruction.op3_value<<=2;
            if(((*(registro+13)+instruction.op3_value)>=0x20000000)&&((*(registro+13)+instruction.op3_value)<0x40000000))
            {
                LDR(registro+instruction.op1_value,*(registro+13),instruction.op3_value,SRAM);
            }
            if((*(registro+13)+instruction.op3_value)<0x20000000)
            {

            }
            if((*(registro+13)+instruction.op3_value)>=0x40000000)
            {
                //IOAccess((*(registro+13)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Read);
            }
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='P') && (instruction.op3_type=='#')) // label
        {
            *codificacion=(9<<11)+(instruction.op1_value<<8)+instruction.op3_value;
            instruction.op3_value<<=2;
            if(((*(registro+15)+instruction.op3_value)>=0x20000000)&&((*(registro+15)+instruction.op3_value)<0x40000000))
            {
                LDR(registro+instruction.op1_value,*(registro+15),instruction.op3_value,SRAM);
            }
            if((*(registro+15)+instruction.op3_value)<0x20000000)
            {

            }
            if((*(registro+15)+instruction.op3_value)>=0x40000000)
            {
                //IOAccess((*(registro+15)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Read);
            }
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R'))
        {
            *codificacion=(11<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000))
            {
                LDR(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM);
            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000)
            {
                //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Read);
            }
        }
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"LDRB") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
        {
            *codificacion=(15<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000))
            {
                LDRB(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,SRAM);
            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000)
            {
                uint8_t data;
                IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,&data,Read);
                *(registro+instruction.op1_value)= (uint32_t)data;
            }

        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R'))
        {
            *codificacion=(1<<14)+(7<<10)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000))
            {
                LDRB(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM);
            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000)
            {
                uint8_t data;
                IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,&data,Read);
                *(registro+instruction.op1_value)=(uint32_t) data;
            }
        }
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"LDRH") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
        {
            *codificacion=(1<<15)+(1<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            instruction.op3_value<<=1;
            if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000))
            {
                LDRH(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,SRAM);
            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000)
            {
                //IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Read);
            }
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R'))
        {
            *codificacion=(5<<12)+(5<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000))
            {
                LDRH(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM);
            }
            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000)
            {
                //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Read);
            }
            registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"LDRSB") ==0)
    {
        *codificacion=(5<<12)+(3<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000))
        {
            LDRSB(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM);
        }
        if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000)
        {

        }
        if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000)
        {
            //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Read);
        }
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"LDRSH") ==0)
    {
        *codificacion=(5<<12)+(7<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000))
        {
            LDRSH(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM);
        }
        if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000)
        {

        }
        if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000)
        {
            //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Read);
        }
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"STR") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
        {
            *codificacion=(3<<13)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            instruction.op3_value<<=2;
            if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000))
            {
                STR(*(registro+instruction.op1_value),*(registro+instruction.op2_value),instruction.op3_value,SRAM);
            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000)
            {
                //IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Write);
            }
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='S') && (instruction.op3_type=='#'))
        {
            *codificacion=(9<<12)+(instruction.op1_value<<8)+instruction.op3_type;
            instruction.op3_value<<=2;
            if(((*(registro+13)+instruction.op3_value)>=0x20000000)&&((*(registro+13)+instruction.op3_value)<0x40000000))
            {
                STR(*(registro+instruction.op1_value),*(registro+13),instruction.op3_value,SRAM);
            }
            if((*(registro+13)+instruction.op3_value)<0x20000000)
            {

            }
            if((*(registro+13)+instruction.op3_value)>=0x40000000)
            {
                //IOAccess((*(registro+13)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Write);
            }
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R'))
        {
            *codificacion=(5<<12)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000))
            {
                STR(*(registro+instruction.op1_value),*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM);
            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000)
            {
                //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Write);
            }
        }
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"STRB") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
        {
            *codificacion=(7<<12)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000))
            {
                STRB(*(registro+instruction.op1_value),*(registro+instruction.op2_value),instruction.op3_value,SRAM);
            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000)
            {
                uint8_t data;
                data=(uint8_t)(*(registro+instruction.op1_value));
                IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,&data,Write);
            }
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R'))
        {
            *codificacion=(21<<10)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000))
            {
                STRB(*(registro+instruction.op1_value),*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM);
            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000)
            {
                uint8_t data;
                data=(uint8_t)(*(registro+instruction.op1_value));
                IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,&data,Write);
            }
        }
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"STRH") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
        {
            *codificacion=(1<<15)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            instruction.op3_value<<=1;
            if(((*(registro+instruction.op2_value)+instruction.op3_value)>=0x20000000)&&((*(registro+instruction.op2_value)+instruction.op3_value)<0x40000000))
            {
                STRH(*(registro+instruction.op1_value),*(registro+instruction.op2_value),instruction.op3_value,SRAM);
            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+instruction.op3_value)>=0x40000000)
            {
                //IOAccess((*(registro+instruction.op2_value)+instruction.op3_value)&0xFF,registro+instruction.op1_value,Write);
            }
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R'))
        {
            *codificacion=(5<<12)+(1<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
            if(((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x20000000)&&((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x40000000))
            {
                STRH(*(registro+instruction.op1_value),*(registro+instruction.op2_value),*(registro+instruction.op3_value),SRAM);
            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))<0x20000000)
            {

            }
            if((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))>=0x40000000)
            {
                //IOAccess((*(registro+instruction.op2_value)+*(registro+instruction.op3_value))&0xFF,registro+instruction.op1_value,Write);
            }
        }
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"PUSH") ==0)
    {
        for(i=0;i<8;i++)
        {
            *codificacion+=(instruction.registers_list[i]<<i);
        }
        *codificacion+=(11<<12)+(1<<10)+(instruction.registers_list[14]<<8);
        PUSH(registro,SRAM,&instruction.registers_list[0]);
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"POP") ==0)
    {
        for(i=0;i<8;i++)
        {
            *codificacion+=(instruction.registers_list[i]<<i);
        }
        *codificacion=(11<<12)+(3<<10)+(instruction.registers_list[15]<<8);
        POP(registro,SRAM,&instruction.registers_list[0]);
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"ADCS") ==0)
    {
        *codificacion=(1<<14)+(5<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        ADCS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);
        registro[15]++;
	}
	if( strcmp(instruction.mnemonic,"ADD") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R'))
        {
            ADD(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value));
            *codificacion=(1<<14)+(1<<10)+(instruction.op2_value<<3)+((8&instruction.op1_value)<<4)+(7&instruction.op1_value);
        }
         if((instruction.op1_type=='R') && (instruction.op2_type=='S') && (instruction.op3_type=='#'))
        {
            ADD(registro+instruction.op1_value,*(registro+13),instruction.op2_value);
            *codificacion=(21<<11)+(instruction.op1_value<<8)+instruction.op3_value;
        }
        if((instruction.op1_type=='S') && (instruction.op2_type=='S') && (instruction.op3_type=='#'))
        {
            ADD(registro+13,*(registro+13),instruction.op3_value);
            *codificacion=(11<<12)+instruction.op3_value;
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='S') && (instruction.op3_type=='R'))
        {
            ADD(registro+instruction.op1_value,*(registro+13),*(registro+instruction.op3_value));
            *codificacion=(1<<14)+(1<<10)+(13<<3)+((8&instruction.op1_value)<<4)+(7&instruction.op1_value);
        }
        if((instruction.op1_type=='S') && (instruction.op2_type=='R'))
        {
            ADD(registro+13,*(registro+13),*(registro+instruction.op2_value));
            *codificacion=(1<<14)+(9<<7)+5+(instruction.op2_value<<3);
        }
        registro[15]++;
    }
	if( strcmp(instruction.mnemonic,"ADDS") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
        {
            ADDS(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,bandera);
            *codificacion=(7<<10)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='#'))
        {
            ADDS(registro+instruction.op1_value,*(registro+instruction.op1_value),instruction.op2_value,bandera);
            *codificacion=(3<<12)+(instruction.op1_value<<8)+instruction.op2_value;
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R'))
        {
            ADDS(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value), bandera);
            *codificacion=(3<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        }
        registro[15]++;
	}
	// los parametros de las demas funciones aritmeticas, de desplazamiento y logicas son similares
    if( strcmp(instruction.mnemonic,"ANDS") ==0)
    {
        *codificacion=(1<<14)+(instruction.op2_value<<3)+instruction.op1_value;
        ANDS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"ASRS") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R'))
		{
			ASRS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);
			*codificacion=(1<<14)+(1<<8)+(instruction.op2_value<<3)+instruction.op1_value;
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
		{
			ASRS(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,bandera);
            *codificacion=(1<<12)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        }
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"BICS") ==0)
    {
        *codificacion=(1<<14)+(14<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        BICS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"CMN") ==0)
    {
        *codificacion=(1<<14)+(11<6)+(instruction.op2_value<<3)+instruction.op1_value;
        CMN(*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera); //	En diferencia a las demas funciones, se envian como parametros 2 valores
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"CMP") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R'))
		{
		    if(instruction.op1_value>=8)
		    {
                CMP(*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);	//	En diferencia a las demas funciones, se envian como parametros 2 valores
                *codificacion=(1<<14)+(5<<8)+(instruction.op2_value<<3)+(7&instruction.op1_value)+((8&instruction.op1_value)<<4);
		    }
		    else
		    {
                CMP(*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);	//	En diferencia a las demas funciones, se envian como parametros 2 valores
                *codificacion=(1<<14)+(10<<6)+(instruction.op2_value<<3)+instruction.op1_value;
		    }
		}
        if((instruction.op1_type=='R') && (instruction.op2_type=='#'))
		{
			CMP(*(registro+instruction.op1_value),instruction.op2_value, bandera);	// Como parametros se tienen el contenido de un registro y un valor
            *codificacion=(5<<11)+(instruction.op1_value<<8)+instruction.op2_value;
        }
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"EORS") ==0)
    {
        *codificacion=(1<<14)+(1<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        EORS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value),bandera);
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"LSLS") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R'))
		{
			LSLS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);
			*codificacion=(1<<14)+(1<<7)+(instruction.op2_value<<3)+instruction.op1_value;
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
		{
			LSLS(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,bandera);
            *codificacion=(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        }
        registro[15]++;
	}
    if( strcmp(instruction.mnemonic,"LSRS") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R'))
		{
	        LSRS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);
	        *codificacion=(1<<14)+(3<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
		{
			LSRS(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,bandera);
			*codificacion=(1<<11)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        }
        registro[15]++;
	}
    if( strcmp(instruction.mnemonic,"MOV") ==0)
    {
        *codificacion=(1<<14)+(3<<9)+(instruction.op2_value<<3)+(7&instruction.op1_value)+((8&instruction.op1_value)<<4);
        MOV(registro+instruction.op1_value,*(registro+instruction.op2_value));	//	Envio como parametros una direccion y el contenido de un registro
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"MOVS") ==0)
    {
		if((instruction.op1_type=='R') && (instruction.op2_type=='#'))
		{
			MOVS(registro+instruction.op1_value,instruction.op2_value, bandera);
			*codificacion=(1<<13)+(instruction.op1_value<<8)+instruction.op2_value;
		}
		if((instruction.op1_type=='R') && (instruction.op2_type=='R'))
        {
            MOVS(registro+instruction.op1_value,*(registro+instruction.op2_value),bandera);
            *codificacion=(instruction.op2_value<<3)+instruction.op1_value;
        }
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"MULS") ==0)
    {
        *codificacion=(1<<14)+(13<<6)+(instruction.op2_value<<3)+instruction.op3_value;
        MULS(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value), bandera);
        registro[15]++;
	}
	if( strcmp(instruction.mnemonic,"MVNS") ==0)
    {
        *codificacion=(1<<14)+(15<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        RSBS(registro+instruction.op1_value,*(registro+instruction.op2_value), bandera);
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"NOP") ==0)
    {
        *codificacion=(11<<12)+(15<<8);
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"ORRS") ==0)
    {
        *codificacion=(1<<14)+(3<<8)+(instruction.op2_value<<3)+instruction.op1_value;
        ORRS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"REV") ==0)
    {
        *codificacion=(11<<12)+(5<<9)+(instruction.op2_value<<3)+instruction.op1_value;
        REV(registro+instruction.op1_value, *(registro+instruction.op2_value));
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"REV16") ==0)
    {
        *codificacion=(11<<12)+(5<<9)+(1<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        REV16(registro+instruction.op1_value,*(registro+instruction.op2_value));
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"REVSH") ==0)
    {
        *codificacion=(11<<12)+(5<<9)+(3<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        REVSH(registro+instruction.op1_value,*(registro+instruction.op2_value));
        registro[15]++;
    }
	if( strcmp(instruction.mnemonic,"RORS") ==0)
    {
        *codificacion=(1<<14)+(7<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        RORS(registro+instruction.op1_value,*(registro+instruction.op2_value), bandera);
        registro[15]++;
	}
    if( strcmp(instruction.mnemonic,"RSBS") ==0)
    {
        *codificacion=(1<<14)+(9<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        RSBS(registro+instruction.op1_value,*(registro+instruction.op2_value), bandera);
        registro[15]++;
    }
    if( strcmp(instruction.mnemonic,"SBCS") ==0)
    {
        *codificacion=(1<<14)+(3<<7)+(instruction.op2_value<<3)+instruction.op1_value;
        SBCS(registro+instruction.op1_value,*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);
        registro[15]++;
	}
	if( strcmp(instruction.mnemonic,"SUB") ==0)
    {
        if((instruction.op1_type=='S') && (instruction.op2_type=='S') && (instruction.op3_type=='#'))
        {
            SUB(registro+13,*(registro+13),instruction.op3_value);
            *codificacion=(11<<12)+(1<<7)+instruction.op3_value;
        }
        registro[15]++;
    }
	if( strcmp(instruction.mnemonic,"SUBS") ==0)
    {
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='#'))
		{
			SUBS(registro+instruction.op1_value,*(registro+instruction.op2_value),instruction.op3_value,bandera);
			*codificacion=(15<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='#'))
        {
            SUBS(registro+instruction.op1_value,*(registro+instruction.op1_value),instruction.op2_value,bandera);
            *codificacion=(7<<11)+(instruction.op1_value<<8)+instruction.op2_value;
        }
        if((instruction.op1_type=='R') && (instruction.op2_type=='R') && (instruction.op3_type=='R'))
		{
			SUBS(registro+instruction.op1_value,*(registro+instruction.op2_value),*(registro+instruction.op3_value), bandera);
			*codificacion=(13<<9)+(instruction.op3_value<<6)+(instruction.op2_value<<3)+instruction.op1_value;
        }
        registro[15]++;
	}
    if( strcmp(instruction.mnemonic,"TST") ==0)
    {
        *codificacion=(1<<14)+(1<<9)+(instruction.op2_value<<3)+instruction.op1_value;
        TST(*(registro+instruction.op1_value),*(registro+instruction.op2_value), bandera);	// Como parametros se tienen el contenido de un registro y un valor
        registro[15]++;
    }
	// Las siguientes funciones, son funciones de saltos
    if( strcmp(instruction.mnemonic,"B") ==0)
    {
        *codificacion=(7<<13)+instruction.op1_value;
        B(registro,instruction.op1_value);	// Envio como parametroa la direccion de registro y el valor del salto
    }
    if( strcmp(instruction.mnemonic,"BL") ==0)
    {
        *codificacion=(31<<11)+(2047&instruction.op1_value);
        BL(registro,instruction.op1_value);	// Envio como parametroa la direccion de registro y el valor del salto
    }
    if( strcmp(instruction.mnemonic,"BLX") ==0)
    {
        *codificacion=(1<<14)+(15<<7)+(instruction.op1_value<<3);
        BLX(registro,*(registro+instruction.op1_value));	// Envio como parametroa la direccion de registro y el contenido de un registro
    }
    if( strcmp(instruction.mnemonic,"BX") ==0)
    {
        *codificacion=(1<<14)+(14<<7)+(instruction.op1_value<<3);
        if(instruction.op1_type=='L')	//	Sucede cuando
        {
            BX(registro,registro[14]);  //  PC=LR
        }
        if(instruction.op1_type=='R')	// Sucede cuando se tiene como parametro un registro diferente a LR
        {
            BX(registro,*(registro+instruction.op1_value));
        }
    }
    if( strcmp(instruction.mnemonic,"BEQ") ==0)
    {
        *codificacion=(13<<12)+instruction.op1_value;
        BEQ(registro,instruction.op1_value,*bandera);	// Envio como parametros la direccion de registro, el valor del salto y las banderas
    }
	// Todas las siguientes funciones de salto tienen los mismos parametro que BEQ
    if( strcmp(instruction.mnemonic,"BNE") ==0)
    {
        *codificacion=(13<<12)+(1<<8)+instruction.op1_value;
        BNE(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BCS") ==0)
    {
        *codificacion=(13<<12)+(2<<8)+instruction.op1_value;
        BCS(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BCC") ==0)
    {
        *codificacion=(13<<12)+(3<<8)+instruction.op1_value;
        BCC(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BMI") ==0)
    {
        *codificacion=(13<<12)+(4<<8)+instruction.op1_value;
        BMI(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BPL") ==0)
    {
        *codificacion=(13<<12)+(5<<8)+instruction.op1_value;
        BPL(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BVS") ==0)
    {
        *codificacion=(13<<12)+(6<<8)+instruction.op1_value;
        BVS(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BVC") ==0)
    {
        *codificacion=(13<<12)+(7<<8)+instruction.op1_value;
        BVC(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BHI") ==0)
    {
        *codificacion=(13<<12)+(8<<8)+instruction.op1_value;
        BHI(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BLS") ==0)
    {
        *codificacion=(13<<12)+(9<<8)+instruction.op1_value;
        BLS(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BGE") ==0)
    {
        *codificacion=(13<<12)+(10<<8)+instruction.op1_value;
        BGE(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BLT") ==0)
    {
        *codificacion=(13<<12)+(11<<8)+instruction.op1_value;
        BLT(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BGT") ==0)
    {
        *codificacion=(13<<12)+(12<<8)+instruction.op1_value;
        BGT(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BLE") ==0)
    {
        *codificacion=(13<<12)+(13<<8)+instruction.op1_value;
        BLE(registro,instruction.op1_value,*bandera);
    }
    if( strcmp(instruction.mnemonic,"BAL") ==0)
    {
        *codificacion=(13<<12)+(14<<8)+instruction.op1_value;
        BAL(registro,instruction.op1_value,*bandera);
    }
}
Exemple #8
0
void decodeInstruction(instruction_t instruction, uint32_t *dir_reg, char *dir_flags, uint8_t *SRAM, uint16_t *dec)
{
	uint8_t *R_activos=instruction.registers_list;
	/* Comparacion de mnemonic y Llamado de las funciones */
	if( strcmp(instruction.mnemonic,"ADC") == 0 || strcmp(instruction.mnemonic,"ADCS") == 0){
		dir_reg[PC]++;
		*dec=16704;
		*dec=*dec|instruction.op3_value<<3|instruction.op1_value;
		dir_reg[instruction.op1_value]=ADC(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);
	}

	if( strcmp(instruction.mnemonic,"ADDS") == 0 || strcmp(instruction.mnemonic,"ADD") == 0){
		dir_reg[PC]++;
		if(instruction.op2_type=='S'){
			*dec=45056;
			dir_reg[SP]=ADD(dir_reg[SP],instruction.op3_value,dir_flags);
			*dec=*dec|instruction.op3_value;}
		else if(instruction.op3_type=='#'){
			*dec=7168;
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;
			dir_reg[instruction.op1_value]=ADD(dir_reg[instruction.op2_value], instruction.op3_value,dir_flags);
			mvprintw(4,20,"%X",*dec);}
		else{
			*dec=6144;
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;
			dir_reg[instruction.op1_value]=ADD(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);}
	}
	
	if( strcmp(instruction.mnemonic,"AND") == 0 || strcmp(instruction.mnemonic,"ANDS") == 0){
		dir_reg[PC]++;
		*dec=16384;
		if(instruction.op3_type=='#'){
			dir_reg[instruction.op1_value]=AND(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);}
		else
			dir_reg[instruction.op1_value]=AND(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"ASR") == 0 || strcmp(instruction.mnemonic,"ASRS") == 0){
		dir_reg[PC]++;
		if(instruction.op3_type=='#'){
			*dec=4096;
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;
			dir_reg[instruction.op1_value]=ASR(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);}
		else{
			*dec=16640;
			*dec=*dec|instruction.op3_value<<3|instruction.op1_value;
			dir_reg[instruction.op1_value]=ASR(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);}
	}
	
	if( strcmp(instruction.mnemonic,"BICS") == 0 || strcmp(instruction.mnemonic,"BICS") == 0){
		dir_reg[PC]++;
		if(instruction.op3_type=='#')
			dir_reg[instruction.op1_value]=BIC(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);
		else{
			*dec=17280;
			dir_reg[instruction.op1_value]=BIC(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);
			*dec=*dec|instruction.op3_value<<3|instruction.op1_value;}
	}
	
	if( strcmp(instruction.mnemonic,"CMN" ) == 0 || strcmp(instruction.mnemonic,"CMNS") == 0){
		dir_reg[PC]++;
		CMN(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value],dir_flags);
		*dec=17088;
		*dec=*dec|instruction.op2_value<<3|instruction.op1_value;
		mvprintw(4,20,"%X",*dec);
	}
	
	if( strcmp(instruction.mnemonic,"CMP") == 0 || strcmp(instruction.mnemonic,"CMPS") == 0){
		dir_reg[PC]++;
		CMP(dir_reg[instruction.op1_value],dir_reg[instruction.op2_value],dir_flags);
		*dec=17024;
		*dec=*dec|instruction.op2_value<<3|instruction.op1_value;
		mvprintw(4,20,"%X",*dec);
	}
	
	if( strcmp(instruction.mnemonic,"EOR") == 0 || strcmp(instruction.mnemonic,"EORS") == 0){
		dir_reg[PC]++;
		*dec=16448;
		if(instruction.op3_type=='#')
			dir_reg[instruction.op1_value]=EOR(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);
		else
			dir_reg[instruction.op1_value]=EOR(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"LSLS") == 0 || strcmp(instruction.mnemonic,"LSL") == 0){
		dir_reg[PC]++;
		if(instruction.op3_type=='#'){
			*dec=0;
			dir_reg[instruction.op1_value]=LSL(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
		else{
			*dec=16512;
			dir_reg[instruction.op1_value]=LSL(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);
			*dec=*dec|instruction.op3_value<<3|instruction.op1_value;}
	}
	
	if( strcmp(instruction.mnemonic,"LSRS") == 0 || strcmp(instruction.mnemonic,"LSR") == 0){
		dir_reg[PC]++;
		if(instruction.op3_type=='#'){
			*dec=2048;
			dir_reg[instruction.op1_value]=LSR(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
		else{
			*dec=16576;
			dir_reg[instruction.op1_value]=LSR(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);
			*dec=*dec|instruction.op3_value<<3|instruction.op1_value;}
	}
	
	if( strcmp(instruction.mnemonic,"MOV") == 0 || strcmp(instruction.mnemonic,"MOVS") == 0){
		dir_reg[PC]++;
		if(instruction.op2_type=='#'){
			*dec=8192;
			dir_reg[instruction.op1_value]=MOV(instruction.op2_value,dir_flags);
			*dec=*dec|instruction.op1_value<<8|instruction.op2_value;}
		else{
			*dec=0;
			dir_reg[instruction.op1_value]=MOV(dir_reg[instruction.op2_value],dir_flags);
			*dec=*dec|instruction.op2_value<<3|instruction.op1_value;}
	}
	
	if( strcmp(instruction.mnemonic,"MUL") == 0 || strcmp(instruction.mnemonic,"MULS") == 0){
		dir_reg[PC]++;
		*dec=17216;
		if(instruction.op3_type=='#'){
			dir_reg[instruction.op1_value]=MUL(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);}
		else{
			dir_reg[instruction.op1_value]=MUL(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);
			*dec=*dec|instruction.op2_value<<3|instruction.op1_value;}
	}
	
	if( strcmp(instruction.mnemonic,"MVN") == 0 || strcmp(instruction.mnemonic,"MVNS") == 0){
		dir_reg[PC]++;
		*dec=17344;
		dir_reg[instruction.op1_value]=MVN(dir_reg[instruction.op2_value], dir_flags);
		*dec=*dec|instruction.op2_value<<3|instruction.op1_value;
	}
	
	if( strcmp(instruction.mnemonic,"ORR") == 0 || strcmp(instruction.mnemonic,"ORRS") == 0){
		dir_reg[PC]++;
		*dec=17152;
		if(instruction.op3_type=='#'){
			dir_reg[instruction.op1_value]=ORR(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);}
		else{
			dir_reg[instruction.op1_value]=ORR(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);
			*dec=*dec|instruction.op3_value<<3|instruction.op1_value;}
	}
	
	if( strcmp(instruction.mnemonic,"REV") == 0 || strcmp(instruction.mnemonic,"REVS") == 0){
		dir_reg[PC]++;
		*dec=47616;
		dir_reg[instruction.op1_value]=REV(dir_reg[instruction.op2_value]);
		*dec=*dec|instruction.op2_value<<3|instruction.op1_value;
	}
	
	if( strcmp(instruction.mnemonic,"REVG") == 0 || strcmp(instruction.mnemonic,"REVGS") == 0){
		dir_reg[PC]++;
		*dec=47680;
		dir_reg[instruction.op1_value]=REVG(dir_reg[instruction.op2_value]);
		*dec=*dec|instruction.op2_value<<3|instruction.op1_value;
	}
	
	if( strcmp(instruction.mnemonic,"REVSH") == 0 || strcmp(instruction.mnemonic,"REVSHS") == 0){
		dir_reg[PC]++;
		*dec=47808;
		dir_reg[instruction.op1_value]=REVSH(dir_reg[instruction.op2_value]);
		*dec=*dec|instruction.op2_value<<3|instruction.op1_value;
	}
	
	if( strcmp(instruction.mnemonic,"ROR") == 0 || strcmp(instruction.mnemonic,"RORS") == 0){
		dir_reg[PC]++;
		*dec=16832;
		if(instruction.op3_type=='#'){
			dir_reg[instruction.op1_value]=ROR(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);}
		else{
			dir_reg[instruction.op1_value]=ROR(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);
			*dec=*dec|instruction.op3_value<<3|instruction.op1_value;}
	}
	
	if( strcmp(instruction.mnemonic,"RSB") == 0 || strcmp(instruction.mnemonic,"RSBS") == 0){
		dir_reg[PC]++;
		*dec=16690;
		dir_reg[instruction.op1_value]=RSB(dir_reg[instruction.op2_value], dir_flags);
		*dec=*dec|instruction.op2_value<<3|instruction.op1_value;
	}
	
	if( strcmp(instruction.mnemonic,"SBC") == 0 || strcmp(instruction.mnemonic,"SBCS") == 0){
		dir_reg[PC]++;
		*dec=16768;
		SBC(dir_reg[instruction.op1_value],dir_reg[instruction.op2_value], dir_flags);
		*dec=*dec|instruction.op2_value<<3|instruction.op1_value;
	}
	
	if( strcmp(instruction.mnemonic,"SUBS") == 0 || strcmp(instruction.mnemonic,"SUB") == 0){
		dir_reg[PC]++;
		if(instruction.op2_type=='S'){
			*dec=45184;
			dir_reg[SP]=SUB(dir_reg[SP],instruction.op3_value,dir_flags);
			*dec=*dec|instruction.op3_value;}
		else if(instruction.op3_type=='#'){
			*dec=7680;
			dir_reg[instruction.op1_value]=SUB(dir_reg[instruction.op2_value],instruction.op3_value,dir_flags);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
		else{
			*dec=6656;
			dir_reg[instruction.op1_value]=SUB(dir_reg[instruction.op2_value],dir_reg[instruction.op3_value],dir_flags);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
	}
	
	if( strcmp(instruction.mnemonic,"TST") == 0 || strcmp(instruction.mnemonic,"TSTS") == 0){
		dir_reg[PC]++;
		*dec=16896;
		TST(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], dir_flags);
		*dec=*dec|instruction.op2_value<<3|instruction.op1_value;
	}
	
	if( strcmp(instruction.mnemonic,"NOP") == 0 ){
		NOP(dir_reg);
		*dec=48896;
	}
	
	if( strcmp(instruction.mnemonic,"B") == 0 ){
		*dec=57344;
		*dec=*dec|instruction.op1_value;
		B(instruction.op1_value, dir_reg);
	}
	
	if( strcmp(instruction.mnemonic,"BL") == 0 ){
		*dec=0;
		BL(instruction.op1_value, dir_reg);
	}
	
	if( strcmp(instruction.mnemonic,"BX") == 0 ){
		*dec=18176;
		BX(dir_reg);
	}
	
	if( strcmp(instruction.mnemonic,"BEQ") == 0 ){
		*dec=0;
		BEQ(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BNE") == 0 ){
		*dec=0;
		BNE(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BCS") == 0 ){
		*dec=0;
		BCS(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BCC") == 0 ){
		*dec=0;
		BCC(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BMI") == 0 ){
		*dec=0;
		BMI(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BPL") == 0 ){
		*dec=0;
		BPL(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BVS") == 0 ){
		*dec=0;
		BVS(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BVC") == 0 ){
		*dec=0;
		BVC(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BHI") == 0 ){
		*dec=0;
		BHI(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BLS") == 0 ){
		*dec=0;
		BLS(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BGE") == 0 ){
		*dec=0;
		BGE(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BLT") == 0 ){
		*dec=0;
		BLT(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BGT") == 0 ){
		*dec=0;
		BGT(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BLE") == 0 ){
		*dec=0;
		BLE(instruction.op1_value, dir_reg, dir_flags);
	}
	
	if( strcmp(instruction.mnemonic,"BAL") == 0 ){
		*dec=0;
		BAL(instruction.op1_value, dir_reg);
	}
	
	if(strcmp(instruction.mnemonic,"PUSH")==0){
		dir_reg[PC]++;
		*dec=46080;
		PUSH(SRAM, dir_reg,R_activos);
	}
	
	if(strcmp(instruction.mnemonic,"POP")==0){
		dir_reg[PC]++;
		*dec=48128;
		POP(SRAM,dir_reg,R_activos);
	}
	
	data=(uint8_t)dir_reg[instruction.op1_value];
	if(strcmp(instruction.mnemonic,"LDR")==0){
		dir_reg[PC]++;
		if(instruction.op2_type=='=' && instruction.op3_type=='N'){
			*dec=0;
			dir_reg[instruction.op1_value]=instruction.op2_value;}
		else if(instruction.op2_type=='S'){
			*dec=38912;
			dir_reg[instruction.op1_value]=LDR(dir_reg[SP], instruction.op3_value<<2, SRAM);
			*dec=*dec|instruction.op3_value|instruction.op1_value<<8;}
		else if(instruction.op3_type=='#' || instruction.op3_type=='N'){
			*dec=26624;
			if((dir_reg[instruction.op2_value]+(instruction.op3_value<<2))>=0x40000000)
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(instruction.op3_value<<2)), &data,Read);
			else
				dir_reg[instruction.op1_value]=LDR(dir_reg[instruction.op2_value], instruction.op3_value<<2, SRAM);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value|instruction.op1_value;}
		else{
			*dec=22528;
			if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000)
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value]), &data,Read);
			else
				dir_reg[instruction.op1_value]=LDR(dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
	}
	
	if(strcmp(instruction.mnemonic,"LDRB")==0){
		dir_reg[PC]++;
		if(instruction.op3_type=='#' || instruction.op3_type=='N'){
			*dec=30720;
			if((dir_reg[instruction.op2_value]+instruction.op3_value)>=0x40000000)
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+instruction.op3_value), &data,Read);	
			else
				dir_reg[instruction.op1_value]=LDRB(dir_reg[instruction.op2_value], instruction.op3_value, SRAM);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
		else{
			*dec=23552;
			if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000)
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value]), &data,Read);
			else 
				dir_reg[instruction.op1_value]=LDRB(dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
	}
	
	if(strcmp(instruction.mnemonic,"LDRH")==0){
		dir_reg[PC]++;
		if(instruction.op3_type=='#' || instruction.op3_type=='N'){
			*dec=34816;
			if((dir_reg[instruction.op2_value]+(instruction.op3_value<<1))>=0x40000000)
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(instruction.op3_value<<1)), &data,Read);
			else
				dir_reg[instruction.op1_value]=LDRH(dir_reg[instruction.op2_value], instruction.op3_value<<1, SRAM);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
		else{
			*dec=23040;
			if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000)
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value]), &data,Read);
			else
				dir_reg[instruction.op1_value]=LDRH(dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
	}
	
	if(strcmp(instruction.mnemonic,"LDRSB")==0){
		dir_reg[PC]++;
		*dec=22016;
		*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;
		if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000)
			IOAccess((uint8_t)(dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value]), &data,Read);
		else
			dir_reg[instruction.op1_value]=LDRSB(dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM);
	}
	
	if(strcmp(instruction.mnemonic,"LDRSH")==0){
		dir_reg[PC]++;
		*dec=24064;
		*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;
		if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000)
			IOAccess((uint8_t)(dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value]), &data,Read);
		else
			dir_reg[instruction.op1_value]=LDRSH(dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM);
	}
	
	if(strcmp(instruction.mnemonic,"STR")==0){
		dir_reg[PC]++;
		if(instruction.op2_type=='S'){
			*dec=38912;
			STR(dir_reg[instruction.op1_value],dir_reg[SP], instruction.op3_value<<2, SRAM);
			*dec=*dec|instruction.op3_value|instruction.op1_value<<8;}
		else if(instruction.op3_type=='#' || instruction.op3_type=='N'){
			*dec=24576;
			if((dir_reg[instruction.op2_value]+(instruction.op3_value<<2))>=0x40000000){
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(instruction.op3_value<<2)), &data,Write);}
			else{
				STR(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], instruction.op3_value<<2, SRAM);}
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;
			mvprintw(1,3,"Hola");}
		else{
			*dec=20480;
			if((dir_reg[instruction.op2_value]+dir_reg[instruction.op2_value])>=0x40000000)
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(dir_reg[instruction.op3_value])), &data,Write);
			else{
				STR(dir_reg[instruction.op1_value], instruction.op2_value, instruction.op3_value, SRAM);}
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
	}
	
	if(strcmp(instruction.mnemonic,"STRB")==0){
		dir_reg[PC]++;
		if(instruction.op3_type=='#' || instruction.op3_type=='N'){
			*dec=28672;
			if(dir_reg[instruction.op2_value]+instruction.op3_value>=0x40000000){
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+instruction.op3_value), &data,Write);}
			else{			
				STRB(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], instruction.op3_value, SRAM);}
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
		else{
			*dec=21504;
			if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000){
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(dir_reg[instruction.op3_value])), &data,Write);}
			else{
				STRB(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM);}
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
	}
	
	if(strcmp(instruction.mnemonic,"STRH")==0){
		dir_reg[PC]++;
		if(instruction.op3_type=='#' || instruction.op3_type=='N'){
			*dec=32768;
			if(((dir_reg[instruction.op2_value])+(instruction.op3_value<<1))>=0x40000000)
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(instruction.op3_value<<1)),&data,Write);
			else
				STRH(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], instruction.op3_value<<1, SRAM);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
		else{
			*dec=20992;
			if((dir_reg[instruction.op2_value]+dir_reg[instruction.op3_value])>=0x40000000)
				IOAccess((uint8_t)(dir_reg[instruction.op2_value]+(dir_reg[instruction.op3_value])), &data,Write);
			else
				STRH(dir_reg[instruction.op1_value], dir_reg[instruction.op2_value], dir_reg[instruction.op3_value], SRAM);
			*dec=*dec|instruction.op3_value<<6|instruction.op2_value<<3|instruction.op1_value;}
	}
}