quotient.asm

来自「嵌入式系统基础课件」· 汇编 代码 · 共 56 行

ASM
56
字号
		SECTION	.data

dividend128	DD	0	; bits 0-31
		DD	0	; bits 32-63
		DD	0	; bits 64-95
		DD	0	; bits 96-127

quotient128	DD	0	; bits 0-31
		DD	0	; bits 32-63
		DD	0	; bits 64-95
		DD	0	; bits 96-127

		SECTION	.text
		ALIGN	16
		BITS	32

		GLOBAL	_Quotient

; Function prototype:
; UNSIGNED64 Quotient(UNSIGNED64 dividend64, UNSIGNED32 divisor32)

_Quotient:	PUSH	EBP
		MOV	EBP,ESP
		SUB	ESP,16	; Allocate space for dividend128
		SUB	ESP,16	; Allocate space for quotient128

%define	divisor32	EBP+16	; Use these identifiers to reference the
%define	dividend64	EBP+8	; function parameters, as in "[divisor32]".

%define	dividend128	EBP-16	; Use these identifiers to reference the
%define	quotient128	EBP-32	; extended dividend and 128-bit quotient

	; We really only have a 64-bit dividend,
	; so first extend it to a 128-bit version.

		MOV	EAX,[dividend64+0]
		MOV	[dividend128+0],EAX
		MOV	EAX,[dividend64+4]
		MOV	[dividend128+4],EAX
		MOV	DWORD [dividend128+8],0
		MOV	DWORD [dividend128+12],0

	; Insert your code here for "quotient128 = dividend128 / divisor32"

	; We only want to return bits 63-0 of the result...

		MOV	EAX,[quotient128+0]
		MOV	EDX,[quotient128+4]

	; Restore stack pointer and old EBP and return...

		MOV	ESP,EBP
		POP	EBP
		RET

⌨️ 快捷键说明

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