⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opcodes.c

📁 这是模拟器源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
{
	u32 offset = DP_REG_OPERAND(IMM_SHIFT);
	DEST_REG = (u32)read_byte (BASE_REG);
	BASE_REG -= offset;
	advance_instruction_pipe(); return 1;
}

int ins_ldrb_imm_pre_up (void)
{
	u32 offset = (OPCODE&0xFFF);
	DEST_REG = (u32)read_byte (BASE_REG + offset);
	if (OPCODE&0x200000) BASE_REG += offset;	
	advance_instruction_pipe(); return 3;
}

int ins_ldrb_imm_pre_down (void)
{
	u32 offset = (OPCODE&0xFFF);
	DEST_REG = (u32)read_byte (BASE_REG - offset);
	if (OPCODE&0x200000) BASE_REG -= offset;	
	advance_instruction_pipe(); return 3;
}

int ins_ldrb_imm_post_up (void)
{
	u32 offset = (OPCODE&0xFFF);
	DEST_REG = (u32)read_byte (BASE_REG);
	BASE_REG += offset;
	advance_instruction_pipe(); return 3;
}

int ins_ldrb_imm_post_down (void)
{
	u32 offset = (OPCODE&0xFFF);
	DEST_REG = (u32)read_byte (BASE_REG);
	BASE_REG -= offset;
	advance_instruction_pipe(); return 3;
}

int ins_str_pre_up (void)
{
	u32 offset = DP_REG_OPERAND(IMM_SHIFT);	
	if (((OPCODE>>12)&0xF)==15) write_word (BASE_REG + offset, DEST_REG+4);
	else write_word (BASE_REG + offset, DEST_REG);
	if (OPCODE&0x200000) BASE_REG += offset;	
	advance_instruction_pipe(); return 1;
}

int ins_str_pre_down (void)
{
	u32 offset = DP_REG_OPERAND(IMM_SHIFT);
	if (((OPCODE>>12)&0xF)==15) write_word (BASE_REG - offset, DEST_REG+4);
	else write_word (BASE_REG - offset, DEST_REG);
	if (OPCODE&0x200000) BASE_REG -= offset;	
	advance_instruction_pipe(); return 1;
}

int ins_str_post_up (void)
{
	u32 offset = DP_REG_OPERAND(IMM_SHIFT);
	if (((OPCODE>>12)&0xF)==15) write_word (BASE_REG, DEST_REG+4); 
	else write_word (BASE_REG, DEST_REG); 
	BASE_REG += offset;
	advance_instruction_pipe(); return 1;
}

int ins_str_post_down (void)
{
	u32 offset = DP_REG_OPERAND(IMM_SHIFT);
	if (((OPCODE>>12)&0xF)==15) write_word (BASE_REG, DEST_REG+4); 
	else write_word (BASE_REG, DEST_REG); 
	BASE_REG -= offset;
	advance_instruction_pipe(); return 1;
}

int ins_str_imm_pre_up (void)
{
	u32 offset = (OPCODE&0xFFF);
	if (((OPCODE>>12)&0xF)==15) write_word (BASE_REG + offset, DEST_REG+4);
	else write_word (BASE_REG + offset, DEST_REG);
	if (OPCODE&0x200000) BASE_REG += offset;	
	advance_instruction_pipe(); return 2;
}

int ins_str_imm_pre_down (void)
{
	u32 offset = (OPCODE&0xFFF);
	if (((OPCODE>>12)&0xF)==15) write_word (BASE_REG - offset, DEST_REG+4);
	else write_word (BASE_REG - offset, DEST_REG);
	if (OPCODE&0x200000) BASE_REG -= offset;	
	advance_instruction_pipe(); return 2;
}

int ins_str_imm_post_up (void)
{
	u32 offset = (OPCODE&0xFFF);
	if (((OPCODE>>12)&0xF)==15) write_word (BASE_REG, DEST_REG+4); 
	else write_word (BASE_REG, DEST_REG); 
	BASE_REG += offset;
	advance_instruction_pipe(); return 2;
}

int ins_str_imm_post_down (void)
{
	u32 offset = (OPCODE&0xFFF);
	if (((OPCODE>>12)&0xF)==15) write_word (BASE_REG, DEST_REG+4); 
	else write_word (BASE_REG, DEST_REG);
	BASE_REG -= offset;
	advance_instruction_pipe(); return 2;
}

int ins_strb_pre_up (void)
{
	u32 offset = DP_REG_OPERAND(IMM_SHIFT);
	write_byte (BASE_REG + offset, (u8)DEST_REG); 
	if (OPCODE&0x200000) BASE_REG += offset;	
	advance_instruction_pipe(); return 1;
}

int ins_strb_pre_down (void)
{
	u32 offset = DP_REG_OPERAND(IMM_SHIFT);
	write_byte (BASE_REG - offset, (u8)DEST_REG); 
	if (OPCODE&0x200000) BASE_REG -= offset;	
	advance_instruction_pipe(); return 1;
}

int ins_strb_post_up (void)
{
	u32 offset = DP_REG_OPERAND(IMM_SHIFT);
	write_byte (BASE_REG, (u8)DEST_REG); 
	BASE_REG += offset;
	advance_instruction_pipe(); return 1;
}

int ins_strb_post_down (void)
{
	u32 offset = DP_REG_OPERAND(IMM_SHIFT);
	write_byte (BASE_REG, (u8)DEST_REG); 
	BASE_REG -= offset;
	advance_instruction_pipe(); return 1;
}

int ins_strb_imm_pre_up (void)
{
	u32 offset = (OPCODE&0xFFF);
	write_byte (BASE_REG + offset, (u8)DEST_REG);
	if (OPCODE&0x200000) BASE_REG += offset;	
	advance_instruction_pipe(); return 2;
}

int ins_strb_imm_pre_down (void)
{
	u32 offset = (OPCODE&0xFFF);
	write_byte (BASE_REG - offset, (u8)DEST_REG);
	if (OPCODE&0x200000) BASE_REG -= offset;	
	advance_instruction_pipe(); return 2;
}

int ins_strb_imm_post_up (void)
{
	u32 offset = (OPCODE&0xFFF);
	write_byte (BASE_REG, (u8)DEST_REG); 
	BASE_REG += offset;
	advance_instruction_pipe(); return 2;
}

int ins_strb_imm_post_down (void)
{
	u32 offset = (OPCODE&0xFFF);
	write_byte (BASE_REG, (u8)DEST_REG); 
	BASE_REG -= offset;
	advance_instruction_pipe(); return 2;
}

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

int ins_ldrh_pre (void)
{
	u32 offset = arm->gp_reg [OPCODE&0xF];
	
	if (OPCODE&0x800000) {
		DEST_REG = (u32)read_hword (BASE_REG + offset);
		if (OPCODE&0x200000) BASE_REG += offset;	
	}
	else {
		DEST_REG = (u32)read_hword (BASE_REG - offset);
		if (OPCODE&0x200000) BASE_REG -= offset;	
	}

	advance_instruction_pipe();
	return 3;
}

int ins_ldrh_post (void)
{
	u32 offset = arm->gp_reg [OPCODE&0xF];
	
	DEST_REG = read_hword (BASE_REG);
	if (OPCODE&0x800000) BASE_REG += offset; else BASE_REG -= offset;

	advance_instruction_pipe();
	return 3;
}

int ins_ldrsb (void)
{
	u32 offset = arm->gp_reg [OPCODE&0xF];
	
	if (OPCODE&0x1000000) {
		if (OPCODE&0x800000) {
			DEST_REG = (s32)read_byte (BASE_REG + offset);
			if (OPCODE&0x200000)
				BASE_REG += offset;	
		}
		else {
			DEST_REG = (s32)read_byte (BASE_REG - offset);
			if (OPCODE&0x200000)
				BASE_REG -= offset;	
		}
	}
	else {
		DEST_REG = (s32)read_byte (BASE_REG);
		if (OPCODE&0x800000) BASE_REG += offset; else BASE_REG -= offset;
	}
	advance_instruction_pipe();
	return 3;
}

int ins_ldrsh (void)
{
	u32 offset = arm->gp_reg [OPCODE&0xF];
	u16 temp;

	if (OPCODE&0x1000000) {
		if (OPCODE&0x800000) {
			temp = read_hword (BASE_REG + offset);
			
			if (temp&0x8000) {
				DEST_REG = 0 - temp;
			}
			else {
				DEST_REG = temp;
			}
			
			if (OPCODE&0x200000)
				BASE_REG += offset;	
		}
		else {
			temp = read_hword (BASE_REG - offset);
			
			if (temp&0x8000) {
				DEST_REG = 0 - temp;
			}
			else {
				DEST_REG = temp;
			}

			if (OPCODE&0x200000)
				BASE_REG -= offset;	
		}
	}
	else {
		temp = read_hword (BASE_REG);

		if (temp&0x8000) {
			DEST_REG = 0 - temp;
		}
		else {
			DEST_REG = temp;
		}

		if (OPCODE&0x800000) BASE_REG += offset; else BASE_REG -= offset;
	}
	advance_instruction_pipe();
	return 3;
}

int ins_strh_pre (void)
{
	u32 offset = arm->gp_reg [OPCODE&0xF];
	
	if (OPCODE&0x800000) {
		write_hword (BASE_REG+offset, (u16)DEST_REG);
		if (OPCODE&0x200000)
			BASE_REG += offset;	
	}
	else {
		write_hword (BASE_REG-offset, (u16)DEST_REG);
		if (OPCODE&0x200000)
			BASE_REG -= offset;	
	}

	advance_instruction_pipe();
	return 2;
}

int ins_strh_post (void)
{
	u32 offset = arm->gp_reg [OPCODE&0xF];

	write_hword (BASE_REG, (u16)DEST_REG);
	if (OPCODE&0x800000) BASE_REG += offset; else BASE_REG -= offset;

	advance_instruction_pipe();
	return 2;
}

int ins_ldrh_imm_pre (void)
{
	u32 offset = ((OPCODE&0xF00)>>4)|(OPCODE&0xF);
	
	if (OPCODE&0x800000) {
		DEST_REG = read_hword (BASE_REG + offset);
		if (OPCODE&0x200000)
			BASE_REG += offset;	
	}
	else {
		DEST_REG = read_hword (BASE_REG - offset);
		if (OPCODE&0x200000)
			BASE_REG -= offset;	
	}

	advance_instruction_pipe();
	return 3;
}

int ins_ldrh_imm_post (void)
{
	u32 offset = ((OPCODE&0xF00)>>4)|(OPCODE&0xF);
	
	DEST_REG = read_hword (BASE_REG);
	if (OPCODE&0x800000) BASE_REG += offset; else BASE_REG -= offset;

	advance_instruction_pipe();
	return 3;
}

int ins_ldrsb_imm (void)
{
	u32 offset = ((OPCODE&0xF00)>>4)|(OPCODE&0xF);
	
	if (OPCODE&0x1000000) {
		if (OPCODE&0x800000) {
			DEST_REG = (s32)read_byte (BASE_REG + offset);
			if (OPCODE&0x200000)
				BASE_REG += offset;	
		}
		else {
			DEST_REG = (s32)read_byte (BASE_REG - offset);
			if (OPCODE&0x200000)
				BASE_REG -= offset;	
		}
	}
	else {
		DEST_REG = (s32)read_byte (BASE_REG);
		if (OPCODE&0x800000) BASE_REG += offset; else BASE_REG -= offset;
	}
	advance_instruction_pipe();
	return 3;
}

int ins_ldrsh_imm (void)
{
	u32 offset = ((OPCODE&0xF00)>>4)|(OPCODE&0xF);
	u16 temp;
	
	if (OPCODE&0x1000000) {
		if (OPCODE&0x800000) {
			temp = read_hword (BASE_REG + offset);
			
			if (temp&0x8000) {
				DEST_REG = 0 - temp;
			}
			else {
				DEST_REG = temp;
			}

			if (OPCODE&0x200000)
				BASE_REG += offset;	
		}
		else {
			temp = read_hword (BASE_REG - offset);

			if (temp&0x8000) {
				DEST_REG = 0 - temp;
			}
			else {
				DEST_REG = temp;
			}

			if (OPCODE&0x200000)
				BASE_REG -= offset;	
		}
	}
	else {
		temp = read_hword (BASE_REG);

		if (temp&0x8000) {
			DEST_REG = 0 - temp;
		}
		else {
			DEST_REG = temp;
		}

		if (OPCODE&0x800000) BASE_REG += offset; else BASE_REG -= offset;
	}
	advance_instruction_pipe();
	return 3;
}

int ins_strh_imm_pre (void)
{
	u32 offset = ((OPCODE&0xF00)>>4)|(OPCODE&0xF);
	
	if (OPCODE&0x800000) {
		write_hword (BASE_REG+offset, (u16)DEST_REG);
		if (OPCODE&0x200000)
			BASE_REG += offset;	
	}
	else {
		write_hword (BASE_REG-offset, (u16)DEST_REG);
		if (OPCODE&0x200000)
			BASE_REG -= offset;	
	}
	advance_instruction_pipe();
	return 2;
}

int ins_strh_imm_post (void)
{
	u32 offset = ((OPCODE&0xF00)>>4)|(OPCODE&0xF);
	write_hword (BASE_REG, (u16)DEST_REG);
	if (OPCODE&0x800000) BASE_REG += offset; else BASE_REG -= offset;
	advance_instruction_pipe();
	return 2;
}

int ins_stm (void)
{
	int i;
	u32 offset=0;
	int n=0;

	if (OPCODE&0x1000000) {

		if (OPCODE&0x800000) {
	
			for (i=0; i<16; i++) {

				if (OPCODE&(0x1<<i)) {

					if (OPCODE&0x200000) BASE_REG += 4; else offset += 4;
					write_word (BASE_REG+offset, arm->gp_reg [i]);
				}
			}
		}
		else {

			for (i=15; i>=0; i--) {
				
				if (OPCODE&(0x1<<i)) {

					if (OPCODE&0x200000) BASE_REG -= 4; else offset += 4;
					write_word (BASE_REG-offset, arm->gp_reg [i]);
				}
			}
		}	
	}
	else {

		if (OPCODE&0x800000) {
	
			for (i=0; i<16; i++) {

				if (OPCODE&(0x1<<i)) {

					write_word (BASE_REG+offset, arm->gp_reg [i]);
					if (OPCODE&0x200000) BASE_REG += 4; else offset += 4;
				}
			}
		}
		else {

			for (i=15; i>=0; i--) {
				
				if (OPCODE&(0x1<<i)) {

					write_word (BASE_REG-offset, arm->gp_reg [i]);
					if (OPCODE&0x200000) BASE_REG -= 4; else offset += 4;
				}
			}
		}	
	}
	advance_instruction_pipe();
	return (2+n);
}

int ins_ldm (void)
{
	u32 temp;
	u32 update_base = 0;
	u32 i;
	s32 offset=0;
	u32 n=0;

		if (OPCODE&0x1000000) {

		if (OPCODE&0x800000) {
	
			for (i=0; i<16; i++) {

				if (OPCODE&(0x1<<i)) {

					if (OPCODE&0x200000) BASE_REG += 4; else offset += 4;
					if (i != ((OPCODE>>16)&0xF)) arm->gp_reg [i] = read_word (BASE_REG+offset);
					else {temp = read_word (BASE_REG+offset); update_base = 1;}
				}
			}
		}
		else {

			for (i=15; i>=0; i--) {
				
				if (OPCODE&(0x1<<i)) {

					if (OPCODE&0x200000) BASE_REG -= 4; else offset += 4;
					if (i != ((OPCODE>>16)&0xF)) arm->gp_reg [i] = read_word (BASE_REG-offset);
					else {temp = read_word (BASE_REG+offset); update_base = 1;}
				}
			}
		}	
	}
	else {

		if (OPCODE&0x800000) {
	
			for (i=0; i<16; i++) {

				if (OPCODE&(0x1<<i)) {

					if (i != ((OPCODE>>16)&0xF)) arm->gp_reg [i] = read_word (BASE_REG+offset);
					else {temp = read_word (BASE_REG+offset); update_base = 1;}
					if (OPCODE&0x200000) BASE_REG += 4; else offset += 4;
				}
			}
		}
		else {

			for (i=15; i>=0; i--) {
				
				if (OPCODE&(0x1<<i)) {

					if (i != ((OPCODE>>16)&0xF)) arm->gp_reg [i] = read_word (BASE_REG-offset);
					else {temp = read_word (BASE_REG+offset); update_base = 1;}
					if (OPCODE&0x200000) BASE_REG -= 4; else offset += 4;
				}
			}
		}	
	}

	if (update_base) BASE_REG = temp;

	if (OPCODE & 0x8000) {
		fill_instruction_pipe();
	}
	else {
		advance_instruction_pipe();
	}

	return (n+1);
}

int ins_swi (void)
{
	advance_instruction_pipe();
	return 1;
}

int ins_swp (void)
{
	u32 temp;
	temp = read_word (BASE_REG);
	write_word (BASE_REG, OP_REG);
	DEST_REG = temp;
	advance_instruction_pipe(); return 4;
}

int ins_swpb (void)
{
	u8 temp;
	temp = read_byte (BASE_REG);
	write_byte (BASE_REG, (u8)OP_REG);
	DEST_REG = temp;
	advance_instruction_pipe(); return 4;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -