I am writing a basic ASM code using MASM & Irvine32. The code is that it takes input character wise, user enters how many characters he wants to enter & the loop runs that many times. The Procedure only accepts Alphabets. Displays rejected messages if num or something else pressed. Returns to Main (calling function) if ecx == 0 (number entered by user). Now my Problem is that the ret keyword gives back the control to the start of the same Procedure(called procedure) instead of going back to main(caller).
include Irvine32.inc
.data
Input_Prompt BYTE "Enter String:", 0
Max_Length_input BYTE "Enter max length to read:", 0
Rejected_mess BYTE "Rejected !", 0
ret_mess BYTE "returing mess !", 0
USER_STR BYTE ?
.code
main PROC
mov edx, offset Max_Length_input ;ask for max length
call WriteString
call Readint
mov ecx, eax
mov esi, offset USER_STR ;passing offset of storage
call String_Input
main endp
String_Input PROC
mov ebx, 0
mov edx, offset Input_Prompt ;ask for input
l1:
call WriteString
call Readchar
call writechar
call crlf
cmp al, 'a'
JA L2
cmp al, 'z'
JB L2
L2:
cmp al, 'A'
JA break
JB Reject
cmp al, 'Z'
JB break
JA Reject
break:
mov [esi+ebx], al ;filling chars in the storage
inc ebx
loop l1
mov edx, offset USER_STR ;displaying final data in storage
call writestring
mov edx, offset ret_mess
call crlf
call writestring
call crlf
ret
reject:
mov edx, offset Rejected_mess
call crlf
call writestring
String_Input endp
exit
end main
There is a similar question on Stack overflow RET function returning to beginning of code instead of CALL point But that has Push and pop whereas I haven't touched the Stack. What am I missing. Thanks for ur help