I m having a problem with my loop, the code contained in it is long and it gives me error jump destination too far : by 3 byte(s)
. When ı remove:
mov edx,offset str1
call writestring
this part below the main PROC, it doesnt give an error. But ı need this string user enters a negative number to give a message. How can ı?
INCLUDE Irvine32.inc
.data
money dword 200,100,50,20,10,5,1
str1 byte "Enter the amounts for each value of money : ",0
str2 byte "The sum of your moneys are:",0
total dword 0
buffer dword 1000 dup(0),0
str3 byte "Do not enter neg number ",0
.code
main PROC
mov edx,offset str1
call writestring
call crlf
mov ecx,lengthof money
mov esi,0
mov edi,0
start1:
jmp continue
don:
push ecx
mov edx,ecx
mov edx,0
mov edx,7
sub edx,ecx
mov ecx,edx
mov edi,0
mov esi,0
start2:
mov eax,money[esi]
call writedec
mov ebx,eax
mov al,'x'
call writechar
mov eax,buffer[edi]
call writedec
call crlf
add esi,4
add edi,4
loop start2
pop ecx
continue:
;**************************************************
mov edx,0
mov eax,money[esi]
call writedec
mov ebx,eax
mov al,'x'
call writechar
call readint
;***************************************************
sub eax,0
js don
mov buffer[edi],eax
;*************************
mul ebx
add total,eax ;we add each the multiplication to total.
add esi,4 ;increases the index by 4.(because of dword type)
add edi,4
loop start1
mov edx,offset str2
call writestring
mov eax, total
call writedec
exit
main ENDP
END main
loop
has limited range. It can only jump up to 127 bytes ahead or 128 back in the instruction stream measured from the start of the following instruction.To get around that, you can do something like the following.
Instead of
if the label is out of reach you can do something like this:
or else use a different construct based on conditional jumps that don't have the range limitation.