Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

JB instruction out of range so quick!!?

Status
Not open for further replies.

AceOfHearts

New Member
Hi,

My assembly code is really not that long. I have a few JB instruction there. When I try to compile it, it keeps saying 'out of range' on those instructions and would not compile.
:confused:

Now, the place where it should jump to is really not too further away, I cant put any numerical values to it. But if becomes out of range so quick, than I honestly cannot think how this instruction be used for any really useful purpose. I only have two small LCD routines that show two words between the JB instruction and the place it should jump to.

Any help with regard to how I can extend the range of this instruction would be grately appreciates.

I am talking assembly and 8051 uC .

peace.
 
till i remember..

yes.. you have to take care of the jump instruction always..

LJMP is good..

But let me offer you few more tips.

" out of range " or similar problems also comes due to following reasons:

1. when the file of program you've placed in the folder's folder's folder... the path sometimes becomes too long for some compilers.. the compilers say.. the address is out of range..

2. when you declare an array that is too long.. then also..

regards,

Simran..:)
 
simrantogether said:
yes.. you have to take care of the jump instruction always..

LJMP is good..

But let me offer you few more tips.

" out of range " or similar problems also comes due to following reasons:

1. when the file of program you've placed in the folder's folder's folder... the path sometimes becomes too long for some compilers.. the compilers say.. the address is out of range..

2. when you declare an array that is too long.. then also..

regards,

Simran..:)

Thanks Simran for the tips! :)

peace.
 
The instructions
CJNE, DJNZ, JB, JBC, JC, JNB, JNC, JNZ and JZ
can jump 128 bytes forward or backward in program memory regarding to their own location in program memory.

The amount of instructions between these instruction and the label depend on the instructions used.
Since most of the instructions are 1 or 2 bytes you can place about 80 instructions between your JB instruction and your label.


This has nothing to do with folder and path names like simrantogether suggested :eek:
Placing an array of constants in the middle of your code is the most stupid thing to do :eek:


So if you still encounter that problem share your code so that we can check what's wrong :)
 
Last edited:
I'm like 12 years too late. I have the same out of range issue with JB, though my code is kinda long. I meant to interface keypad with LCD on edsim51. Can someone help me out?
 

Attachments

  • Keypad to LCD module.asm
    5.4 KB · Views: 169
Don't recognize the code but is there an opposite instruction (JB = jump below? - opposite Jump above or equal) to jump past a long jump?

Mike.
Edit, is JNB Jump Not Below? Which would be the opposite.
 
To illustrate what I think Pommie is saying see:

IOW: when a conditional jump is out of range, re-write the conditional code to execute a long jump when the original condition is true.

Instead of:
JB label

Write:
JNB Hlabel
JMP label
Hlabel

Pretty much exactly what you do in PIC assembler as well - and I suppose many others?.

From what I can vaguely remember from my long ago 6502 days, that was similar - you only had very short range branch instructions, so you also used the opposite branch over a long jump.
 
you only had very short range branch instructions

If they are the same as the 6800 series CPUs, a "branch" instruction used a 8 bit signed value (added to the address counter), offset from the next sequential instruction address. That gave -128 to +127 address range, which is quite a bit of machine code. For larger but moderate size routines, you could always have another unconditional branch at the target address to extend the range.

They were fast and code using them was relocatable, a great advantage for hand-assembly or working directly in machine code.

Jump instructions were to absolute addresses, but more program bytes used and slightly slower.
 
If they are the same as the 6800 series CPUs, a "branch" instruction used a 8 bit signed value (added to the address counter), offset from the next sequential instruction address. That gave -128 to +127 address range, which is quite a bit of machine code. For larger but moderate size routines, you could always have another unconditional branch at the target address to extend the range.

They were fast and code using them was relocatable, a great advantage for hand-assembly or working directly in machine code.

Jump instructions were to absolute addresses, but more program bytes used and slightly slower.

The 6800 was quite similar to 6502.
 
I've attached the code i'm working on. Its suppose to display whatever you press on the keypad in edsim51 simulator to appear on the LCD. The LCD is set but the value is not displayed. I honestly don't know what is wrong, i just need help.
 

Attachments

  • Keypad to LCD module1.asm
    5.5 KB · Views: 153
I've attached the code i'm working on. Its suppose to display whatever you press on the keypad in edsim51 simulator to appear on the LCD. The LCD is set but the value is not displayed. I honestly don't know what is wrong, i just need help.

It appears that your situation goes well beyond a branch out of range error and may not even have included that error. Edit: I tried your first attachment code and it does have the range error. Maybe that is a good place to start. Also, don't just keep attaching new versions of the code. Let's do it step by step with you explaining what you are changing.

so, you get the range error here (in your first attachment):
JB F0, Row0

how did you fix that?



I would suggest this.

Start another thread and describe as best as you can your situation. For example, if it is homework, say so. If it doesn't work, don't just say that it doesn't work, tell us exactly what is happening and what is not happening.

Using that simulator, you can step through the code. Do that and try to describe the program flow. Use some breakpoints and so on and so forth. Divide and conquer.

You have to know what your program is supposed to do so that you can see what it is doing.

Help us help you.

edsim1.jpg


To other members - I think the last time I did anything with 8051 code was 30 years ago and I do have an 8051 board around here somewhere. EdSim51 was simple to download and run on win (it is java).
 
Last edited:
I had to rewrite the whole code but now it works. Thanks

Great to hear!. If you are up to it, could you post the final code? I promise, no critique, I was just getting into that simulator and wouldn't mind testing it out with working code.
 
Great to hear!. If you are up to it, could you post the final code? I promise, no critique, I was just getting into that simulator and wouldn't mind testing it out with working code.
Have you tried MCU8051IDE? Looks similar to Edsim….
 
Here it is.
Thks. I did load it in but it does not work for me - does something but not displaying as I thought. There are lots of settings and so forth so there are probably some good reasons why. Anyways, I am glad that you got it working ok.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top