Austin Hunter
Austin Hunter

Reputation: 394

x86 assembly program stuck in a loop

I am writing a x86 assembly program. For some reason my loop is getting stuck. I was wondering if anyone can help me figure out why je statement isnt being executed? If I put an output inside of second loop, it will output forever until crashing. So how come the je comparison is not firing properly?

;;Ignore compute_bs MACRO, it should not be relevant to my issue;;

Thanks

interpolate_proc PROC	NEAR32
	push ebp
	mov ebp, esp
	fldz
	mov cx, degree
	
	START_LOOP:
		mov eax, 0
		cmp cx, 0
		je END_LOOP
		mov dx,0

		fld1
		SECOND_LOOP:
			cmp dx, cx   ;<-- Not executing. even though inc dx
			je SECOND_END

			mov ebx, array
			fld REAL4 PTR x
			mov ax, 8
			mul dx
			add ebx, eax
			fld REAL4 PTR [ebx]
			fsubr
			fmul
			inc dx
			jmp SECOND_LOOP
			
		SECOND_END:
			output prompt
			mov ebx, array
			compute_bs ebx, cx
			mov temp, eax
			fld REAL4 PTR temp
			fmul
			fadd
			
		dec cx
		jmp START_LOOP	
		
	END_LOOP:
	
	compute_bs ebx, cx
	mov temp, eax
	fld REAL4 PTR temp
	fadd
	fstp REAL4 PTR temp
	mov eax, temp
	mov esp, ebp
	pop ebp
interpolate_proc ENDP
END

Upvotes: 1

Views: 295

Answers (1)

Weather Vane
Weather Vane

Reputation: 34575

The instruction

mul dx

multiplies ax by dx and places the 32-bit product in dx:ax, overwriting your operand in dx. So the loop test will fail.

Upvotes: 3

Related Questions