All pastes #748808 Raw Edit

Anonymous

public text v1 · immutable
#748808 ·published 2007-10-25 04:25 UTC
rendered paste body
.DATA                    ; reserve storage for data
explain		BYTE	"This will calculate the greatest common divisor of two numbers.",cr,Lf,0
prompt1		BYTE	"First number:  ",0
prompt2		BYTE	"Second number:  ",0
string		BYTE	20 DUP (?)		; for inputing each number
a		DWORD	?			; for temporary storage
final		BYTE	cr,Lf,"The GCD is: "	; final output control
gcd		BYTE	11 DUP (?)
		BYTE	cr,Lf,0

.CODE                               ; start of main program code
_start:
		output 	explain      		; outputs explanation

		output 	prompt1			; prompt output
		input 	string,20		; inputs into string
		atod	string			; converts ASCII to doubleword
		mov	ebx, eax		; moves first number to ebx

		output 	prompt2			; prompt output
		input 	string,20		; inputs into string
		atod	string			; converts ASCII to doubleword
		mov	edx, eax		; moves second number to edx

		
aloop:		mov	a, edx			; copies ebx into temp variable a
		mov	eax, ebx		; preps for division by copying ebx into eax
		div	edx			; divides by edx, edx now holds the remainder
		mov	ebx, a			; copies a back into ebx

		cmp	edx,0			; compare edx (the "remainder" of the div) to 0
		jz	exitplace		; jump if zero

		loop	aloop			; loop back to aloop

exitplace:	dtoa	gcd, ebx
		output 	final			; outputs final prompts