×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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

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

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:

   ...
   ...

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

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

(OP)
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

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

Glad it worked
Regards

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

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!"

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

(OP)
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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close