assembly - Macro in loop works once, then doesn't -
procedure readval should loop , ask user input 10 integers (as strings), storing each in array. readval uses macro getstring , works first time through. other 9 times, prints "please enter unsigned integer:" not stop allow user enter value. so, it's calling macro, why not stop , wait input next 9 times.
include irvine32.inc len = 10 ; number of elements in array. getstring macro buffer, size push eax push ecx push edx mov edx, offset usermsg_2 call writestring mov edx, buffer ; buffer passed reference, no offset req'd. mov eax, size mov ecx, [eax] ; dereference sizeelem ecx counter. call readstring pop edx pop ecx pop eax endm .data usermsg_2 byte "please enter unsigned number: ",0 array dword len dup(?) arlength dword len sizeelem byte 11 ; number of digits allowed in. reading ints strings. holder dword ? ; temp memory location storing string input/output. .code main proc push offset array push offset arlength push offset sizeelem push offset holder call readval exit main endp readval proc push ebp mov ebp, esp push ecx mov esi, [ebp+20] ; esi has starting address of array. mov eax, [ebp+16] ; @arlength mov ecx, [eax] ; ecx gets arlength. cmp ecx, 0 je l2 l1: getstring [ebp+8], [ebp+12] ; [ebp+8] gets user inputted string. mov esi, [ebp+8] ; mov string in holder array[esi]. add esi, type dword loop l1 l2: pop ecx pop ebp ret 16 readval endp end main
i think problem readstring expects value in ecx dword. giving number byte confusing it. declaring sizeelem dword solves issue.
you might want declare holder using bytes instead of dword while you're @ too, think that's more typical of string storage.
Comments
Post a Comment