Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Relative jump out of range by 0002h and 000fh bytes *ERROR*

Status
Not open for further replies.

aldeburan

Technical User
Sep 19, 2002
8
GB
Hello,
ive to write an assembly language program for college that will play musical notes when the user strikes the keys (1-8). Heres my code:

.model large
.stack 100h
.data
prompt DB 'Press 1-8 to play notes!',13,10,'$'
.code
mov ax,@data
mov ds,ax
mov dx, OFFSET prompt
mov ah,9
int 21h
start:
mov ah,1
int 21h
cmp al,'1'
jz is1
cmp al,'2'
jz is2
cmp al,'3'
jz is3
cmp al,'4'
jz is4
cmp al,'5'
jz is5
cmp al,'6'
jz is6
cmp al,'7'
jz is7
cmp al,'8'
jz is8 ;*ERROR* relative jump out of
cmp al,'x' ;range by 0002h bytes
jz isx ;*ERROR* relative jump out of
jmp start ;range by 000fh bytes
is1:
mov al,10110110b
out 43h,al
mov al,7dh
out 42h,al
mov al,0a9h
out 42h,al
in al,61h
or al,00000011b
out 61h,al
jmp delay
is2:
mov al,0beh
out 42h,al
mov al,54h
out 42h,al
in al,61h
or al,00000011b
out 61h,al
jmp delay
is3:
mov al,5fh
out 42h,al
mov al,2ah
out 42h,al
in al,61h
or al,00000011b
out 61h,al
jmp delay
is4:
mov al,2fh
out 42h,al
mov al,15h
out 42h,al
in al,61h
or al,00000011b
out 61h,al
jmp delay
is5:
mov al,97h
out 42h,al
mov al,0ah
out 42h,al
in al,61h
or al,00000011b
out 61h,al
jmp delay
is6:
mov al,4bh
out 42h,al
mov al,5h
out 42h,al
in al,61h
or al,00000011b
out 61h,al
jmp delay
is7:
mov al,77h
out 42h,al
mov al,6h
out 42h,al
in al,61h
or al,00000011b
out 61h,al
jmp delay
is8:
mov al,52h
out 42h,al
mov al,1h
out 42h,al
in al,61h
or al,00000011b
out 61h,al
jmp delay

isx:
in al,61h
and al,11111100b
out 61h,al
jmp done
delay:
mov ah,86h
mov cx,02h
mov dx,0d090h
int 15h
in al,61h
and al,11111100b
out 61h,al
jmp start
done:
mov ah,4ch
int 21h
END

the code is designed to play all 8 octaves of A (Well, as well as it can as it is hardly a hi-fi) which seems to work ok when i have entered code for the keys 1-6, but when i put the code in for keys 7 and 8 i get the errors shown on lines 29 and 31.
Can anyone please help me by giving me some advice on why im getting these errors when i am assembling the code.
Thank you
 
Hi,
I think the error you got is because the jump condition already out of limit. The limitation of jump condition is sign byte: -128 to +127

I add one location into the code and put your code in that location. Here it is:
Code:
   ...
   ...

start:
   ...
   ...
   cmp al,'5'
   jz is5
   cmp al,'6'
   jz is6
   jmp IsOtherKey
   ...
   ...
   ...

is8:
   ...
   ...

IsOtherKey:
   cmp al,'7'   
   jz is7        
   cmp al,'8'    
   jz is8              ;*ERROR* relative jump out of 
   cmp al,'x'          ;range by 0002h bytes 
   jz isx              ;*ERROR* relative jump out of 
   jmp start           ;range by 000fh bytes

isx:
   ...
   ...
   END

Try that first and let me know how it works
Regards
 
Thanx AirCon,
That was strange, i tried something very similar yesterday with no luck, well there was some luck, however whenever i pressed 7 or 8 it took two key presses before the sound played. Anyway i tried what you suggested today and hey presto it worked.
So thanx for your time and advice and have a good day
 
i notice you have alot of subroutines that are the same but with only minor register value diferences.

you could make your program alot smaller if you had the subroutines push the different values onto the stack then call the same routine which poped these different values off the stack and performed its task.

for example...

(notice i reversed the order of values, is1 is different from the others as it also loads port 043h)

is1:
mov al,10110110b
out 43h,al
mov al,0a9h
push ax
mov al,7dh
push ax
jmp mainroutine
is2:
mov al,54h
push ax
mov al,0beh
push ax
jmp mainroutine
is3:
mov al,2ah
push ax
mov al,5fh
push ax
jmp mainroutine

mainroutine:
pop ax
out 42h,al
pop ax
out 42h,al
in al,61h
or al,00000011b
out 61h,al
jmp delay


hope this gives you an idea or 2
straiph


"There are 10 types of people in this world, those who know binary and those who don't!"
 
Thanx straiph, it would seem more logical to use the subroutines to reduce program size. I see why you've reversed the values so when they are popped from the stack they are in the correct order. My main objective was just to get the prog working as this is the first time i have ever done any x86 programming.
Anyway thanx for your advice and i will use the subroutines. Cheers ;o)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top