I am having a problem with my loop not function right and I think I have narrowed the problem down to the MACRO I made for reading in integers the ECX register isn't obtaining a value and stays at 0 while EAX get the value of 1, so when I try my loop using the variable declared it falls into the infinite loop. I tested and loops will do that if you make the counter 0.

Here is my MACRO:

mReadInt MACRO intNum:REQ
	push eax
	push ecx
	mov eax, OFFSET intNum
	mov ecx, SIZEOF intNum
	call ReadInt
	pop ecx
	pop eax
ENDM

Here is my loop:

mov ecx, number
LP1:
	mWriteString _string
	call Crlf
	LOOP LP1

Not enought code, to help you,

however Loop decrements ecx and checks for zero. So unless <number> is the loop count, there's a problem.

Here is full code, I cleaned it all up and made it one macro instead of multiple so it is less lines.

TITLE MASM Template						(main.asm)

INCLUDE Irvine32.inc
.data
_string BYTE 31 DUP(?)
number DWORD ?
x DWORD ?
y DWORD ?
sum DWORD ?
rmdr DWORD ?
.code
main PROC
;Macro to write instructions to console
mWrite MACRO text
	LOCAL string
	.data
	string BYTE text,0
	.code
	push edx
	mov edx, OFFSET string
	call WriteString
	pop edx
ENDM
;Macro to take a 32-bit integer from user
;and take a string from user then output it
;x amount of times
myMacro MACRO intNum:REQ, varName:REQ, buffer:REQ
	mWrite "Enter integer: "
	push eax
	push ecx
	mov ecx, OFFSET intNum
	mov eax, SIZEOF intNum
	call readint
	pop ecx
	pop eax
	call Crlf
	
	call dumpregs ; for texting purpose
	
	mWrite "Enter String: "
	push ebx
	push ecx
	mov edx, OFFSET varName
	mov ecx, SIZEOF varName
	call readstring
	pop edx
	pop ecx
	call Crlf
	
	call dumpregs ; for testing purpose
	
;Loop in macro to display the _string
;x(number) amount of time	
	
	mov ecx, number ;loop counter
	myLoop:
		push edx
		mov edx, OFFSET buffer
		call WriteString
		pop edx
		call Crlf
		loop myLoop
ENDM

;Invoking myMacro
	myMacro number, _string, _string
	
	exit
main ENDP

END main

You are using a macro within a macro, which normally isn't a good thing to do. BUT, you still don't have enough information.

Crlf
readstring
WriteString

based upon the non standardization of the naming this indicates these are not standard library functions.

Need to see them too!

Also, get those macros out of the main line code. Put them at the top of the file!

Why are you calling dumpregs? Why not single-step and examine the register values at each step!

You are using a macro within a macro, which normally isn't a good thing to do. BUT, you still don't have enough information.

Crlf
readstring
WriteString

based upon the non standardization of the naming this indicates these are not standard library functions.

Need to see them too!

Also, get those macros out of the main line code. Put them at the top of the file!

Why are you calling dumpregs? Why not single-step and examine the register values at each step!

I figured it out it was simple I was trying to make this to hard

all I did was change the int part to

mWrite "Enter integer: "
	call readint
	mov number, eax

then for the loop all I had to do was mov ecx, number

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.