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

📄 cpu.s

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 S
📖 第 1 页 / 共 4 页
字号:
	movl %eax, %ecx	shrl $12, %eax	movl rmap(,%eax,4), %edx	testl %edx,%edx	jnz .Lusemap\@	pushl %ecx	call mem_read	movsbl %al, %eax	popl %ecx	jmp .Lfinish\@.Lusemap\@:	movsbl (%edx,%ecx),%eax.Lfinish\@:	.endm	# fetch from PC	# result in %al, upper bytes filled with 0 automagically	.macro _fetch	movl %ebp, %eax	movl %ebp, %ecx	shrl $12, %eax	incw %bp	movl rmap(,%eax,4), %edx	testl %edx,%edx	jnz .Lusemap\@	pushl %ecx	call mem_read	popl %ecx	jmp .Lfinish\@.Lusemap\@:	movb (%edx,%ecx),%al.Lfinish\@:		.endm	# fetch signed byte from PC	# result in %eax	.macro _fetchs	movl %ebp, %eax	movl %ebp, %ecx	shrl $12, %eax	incw %bp	movl rmap(,%eax,4), %edx	testl %edx,%edx	jnz .Lusemap\@	pushl %ecx	call mem_read	popl %ecx	movsbl %al, %eax	jmp .Lfinish\@.Lusemap\@:	movsbl (%edx,%ecx),%eax.Lfinish\@:		.endm	# fetch word from PC	# result in %ax, padded with zeros	.macro _fetchw	movl %ebp, %eax	movl %ebp, %edx	shrl $12, %eax	incl %edx	movl %ebp, %ecx	testl $0xfff, %edx	jz .Lunaligned\@	movl rmap(,%eax,4), %edx	testl %edx, %edx	jnz .Lusemap\@.Lunaligned\@:	incl %ebp	pushl %ecx	call mem_read	pushl %eax	pushl %ebp	incl %ebp	call mem_read	popl %ecx	popl %ecx	movb %al, %ah	movb %cl, %al	popl %ecx	andl $0xffff, %ebp	jmp .Lfinish\@.Lusemap\@:	movw (%edx,%ecx),%ax	addw $2, %bp.Lfinish\@:	.endm	# read word from %eax, upper byte must be zero	# result in %ax, padded with zeros	.macro _readw	movl %eax, %edx	shrl $12, %eax	movl %edx, %ecx	incl %edx	testl $0xfff, %edx	jz .Lunaligned\@	movl rmap(,%eax,4), %edx	testl %edx, %edx	jnz .Lusemap\@.Lunaligned\@:	pushl %ecx	pushl %ecx	call mem_read	popl %ecx	popl %ecx	incl %ecx	pushl %eax	pushl %ecx	call mem_read	popl %ecx	popl %ecx	movb %al, %ah	movb %cl, %al	jmp .Lfinish\@.Lusemap\@:	movw (%edx,%ecx),%ax.Lfinish\@:	.endm	# write word to addr %eax, upper bytes must be zero	# source byte passed in %dx	.macro _writew	movl %eax, %ecx	shrl $12, %eax	pushl %edx	movl %ecx, %edx	incl %edx	testl $0xfff, %edx	jz .Lunaligned\@	movl wmap(,%eax,4), %edx	testl %edx, %edx	jnz .Lusemap\@.Lunaligned\@:	popl %edx	pushl %edx	pushl %ecx	pushl %edx	pushl %ecx	call mem_write	popl %ecx	popl %ecx	popl %ecx	popl %edx	incl %ecx	shrl $8, %edx	pushl %edx	pushl %ecx	call mem_write	addl $8, %esp	jmp .Lfinish\@.Lusemap\@:	popl %eax	movw %ax, (%edx,%ecx).Lfinish\@:	.endm			.macro _end	jmp opdone	.endm	.macro _endnz	jnz opdone	.endm	.macro _endz	jz opdone	.endm		.macro _LD dst=B, src=B	movb \src, %al	movb %al, \dst	_end	.endm	.macro _ld_from_hl dst=B	movl HL, %eax	_readb	movb %al, \dst	.endm	.macro _ld_to_hl src=B	movl HL, %eax	movb \src, %dl	_writeb	.endm	.macro _ld_from_imm dst=B	_fetch	movb %al, \dst	.endm	.macro _push	movl %eax, %edx	movl SP, %eax	subw $2, %ax	movl %eax, SP	_writew	.endm	.macro _pop	movl SP, %eax	_readw	addw $2, SP	.endm	.macro _JR	movl %ebp, %eax	_readbs	incl %eax	addw %ax, %bp	.endm	.macro _JP	_fetchw	movl %eax, %ebp	.endm	.macro _CALL	movl %ebp, %eax	addl $2, %eax	_push	_JP	.endm	.macro _RET	_pop	movl %eax, %ebp	.endm	.macro _NOJR	incw %bp	decl %edi	.endm	.macro _NOJP	addw $2, %bp	decl %edi	.endm	.macro _NOCALL	addw $2, %bp	subl $3, %edi	.endm	.macro _NORET	subl $3, %edi	.endm	# Use %dl to pass memory values to inc	.macro _INC reg=B, instr=incb, table=incflagtable	xorl %eax, %eax	\instr \reg	movb \reg, %al	andb $0x1f, %bl	orb \table(%eax), %bl	.endm	.macro _DEC reg=B	_INC \reg, decb, decflagtable	.endm	.macro _INCW reg=HL	incw \reg	_end	.endm	.macro _DECW reg=HL	decw \reg	_end	.endm	.macro _ADD instr=addb, table=addflagtable	\instr %al, %bh	lahf	xorl %ecx, %ecx	movb %ah, %cl	movb \table(%ecx), %bl	.endm	.macro _SUB	_ADD subb, subflagtable	.endm	.macro _ADC instr=adcb, table=addflagtable	rolb $4, %bl	_ADD \instr, \table	.endm	.macro _SBC	_ADC sbbb, subflagtable	.endm	.macro _CP	_ADD cmpb, subflagtable	.endm	.macro _ADDW	movl HL, %edx	addb %al, %dl	adcb %ah, %dh	lahf	movl %edx, HL	movb $0, %dh	movb %ah, %dl	andb $0x8f, %bl	movb addflagtable(%edx), %al	andb $0x70, %al	orb %al, %bl	.endm		.macro _ADDSP dst=SP	movl SP, %edx	addb %al, %dl	adcb %ah, %dh	lahf	movl %edx, \dst	movb $0, %dh	movb %ah, %dl	andb $0x0f, %bl	movb addflagtable(%edx), %al	andb $0x70, %al	orb %al, %bl	.endm	.macro _AND	movb $0x20, %bl	andb %al, %bh	_endnz	orb $0x80, %bl	.endm	.macro _OR instr=orb	\instr %al, %bh	setzb %bl	rorb $1, %bl	.endm	.macro _XOR	_OR xorb	.endm	.macro _RLCA instr=rolb	movb $0, %bl	\instr $1, %bh	rcrb $4, %bl	.endm	.macro _RRCA	_RLCA rorb	.endm	.macro _RLA instr=rclb	rolb $4, %bl	movb $0, %bl	\instr $1, %bh	rcrb $4, %bl	.endm	.macro _RRA	_RLA rcrb	.endm	.macro _RLC reg=B, instr=rolb	xorl %eax, %eax	movb \reg, %al	xorb %bl, %bl	\instr $1, %al	rcrb $4, %bl	movb %al, \reg	orb zflag_table(%eax), %bl	.endm	.macro _RRC reg=B	_RLC \reg, rorb	.endm		.macro _RL reg=B, instr=rclb	xorl %eax, %eax	andb $0x10, %bl	movb \reg, %al	rclb $4, %bl	\instr $1, %al	rcrb $4, %bl	movb %al, \reg	orb zflag_table(%eax), %bl	.endm		.macro _RR reg=B	_RL \reg, rcrb	.endm	.macro _SLA reg=B instr=shlb	movb $0, %cl	\instr $1, \reg	setz %bl	rcrb $4, %cl	rorb $1, %bl	orb %cl, %bl	.endm	.macro _SRA reg=B	_SLA \reg, sarb	.endm		.macro _SRL reg=B	_SLA \reg, shrb	.endm	.macro _SWAP reg=B	movb \reg, %al	xorb %bl, %bl	rolb $4, %al	testb %al, %al	movb %al, \reg	_endnz	orb $0x80, %bl	_end	.endm		.macro _SWAP_A	xorb %bl, %bl	rolb $4, %bh	testb %bh, %bh	_endnz	orb $0x80, %bl	_end	.endm		.macro _SWAP_MEM	movl HL, %eax	_readb	movb %al, %dl	xorb %bl, %bl	rolb $4, %dl	movl HL, %eax	testb %dl, %dl	jnz .Lnonzero\@	orb $0x80, %bl.Lnonzero\@:	_writeb	_end	.endm	.macro _BIT bit=0, reg=B	andb $0x1f, %bl	movb \reg, %al	orb $0x20, %bl	testb $(1<<\bit), %al	_endnz	orb $0x80, %bl	_end	.endm	.macro _BIT_MEM bit=0	movl HL, %eax	_readb	_BIT \bit, %al	.endm	.macro _RES bit=0, reg=B	andb $(~(1<<\bit)), \reg	_end	.endm		.macro _RES_MEM bit=0	movl HL, %eax	_readb	movb %al, %dl	movl HL, %eax	andb $(~(1<<\bit)), %dl	_writeb	_end	.endm	.macro _SET bit=0, reg=B	orb $(1<<\bit), \reg	_end	.endm		.macro _SET_MEM bit=0	movl HL, %eax	_readb	movb %al, %dl	movl HL, %eax	orb $(1<<\bit), %dl	_writeb	_end	.endm		.macro _DAA	xorl %eax, %eax	movb %bl, %ah	andb $0x70, %ah	movb %bh, %al	shrb $4, %ah	xorl %ecx, %ecx	movb daa_table(%eax), %cl	andb $0x4f, %bl	addb %cl, %al	shrb $2, %cl	xorb %ah, %ah	movb %al, %bh	orb daa_carry_table(%ecx), %bl	orb zflag_table(%eax), %bl	.endm			.macro _make_bit_ops reg=B, op=BIT, bit=0, u=___\op\u\bit\u\reg:		_\op \bit, \reg	.endm	.macro _make_cb_ops reg=B__RLC_\reg:	_RLC \reg	_end__RRC_\reg:	_RRC \reg	_end__RL_\reg:	_RL \reg	_end__RR_\reg:	_RR \reg	_end__SLA_\reg:	_SLA \reg	_end__SRA_\reg:	_SRA \reg	_end__SWAP_\reg:	_SWAP \reg__SRL_\reg:	_SRL \reg	_end	_make_bit_ops \reg, BIT, 0	_make_bit_ops \reg, BIT, 1	_make_bit_ops \reg, BIT, 2	_make_bit_ops \reg, BIT, 3	_make_bit_ops \reg, BIT, 4	_make_bit_ops \reg, BIT, 5	_make_bit_ops \reg, BIT, 6	_make_bit_ops \reg, BIT, 7	_make_bit_ops \reg, RES, 0	_make_bit_ops \reg, RES, 1	_make_bit_ops \reg, RES, 2	_make_bit_ops \reg, RES, 3	_make_bit_ops \reg, RES, 4	_make_bit_ops \reg, RES, 5	_make_bit_ops \reg, RES, 6	_make_bit_ops \reg, RES, 7	_make_bit_ops \reg, SET, 0	_make_bit_ops \reg, SET, 1	_make_bit_ops \reg, SET, 2	_make_bit_ops \reg, SET, 3	_make_bit_ops \reg, SET, 4	_make_bit_ops \reg, SET, 5	_make_bit_ops \reg, SET, 6	_make_bit_ops \reg, SET, 7	.endm		.macro _make_cb_hl_op op=RLC suf=_$HL mem=_MEM__\op\suf:	movl HL, %eax	_readb	movb %al, %dl	_\op %dl	movl HL, %eax	_writeb	_end	.endm		.macro _make_cb_hl_bit_op op=BIT bit=0 u=_ suf=_$HL mem=_MEM__\op\u\bit\suf:	_\op\mem \bit	.endm				.text	.p2align 5	.globl cpu_emulate	.globl cpu_step__INVALID:	pushl %eax	pushl $invalid	call die__LD_B_C:	_LD B,C

⌨️ 快捷键说明

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