Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8051 asm error 51: Target out of range

Status
Not open for further replies.

Karthikeyan.K

Newbie level 4
Newbie level 4
Joined
Jan 8, 2015
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
77
Hai all,

I have an issue with my keil c compiler. I've some 8051 assembly code in keil Software.
In code, if I use SJMP Instruction then the compiler shows the following error.

error A51: TARGET OUT OF RANGE

I referred the keil C Technical support page hence I found one remedy. But the explanation they provide is somewhat tough to me.

They said that the location we specify to jump can not be reached by this instruction below.
JNZ label

Instead, we can use this Instruction.
JZ Hlabel
JMP label
Hlabel:

Keil C Technical Support Page for reference: https://www.keil.com/support/docs/3026.htm

So what they are try to say with this code?
And how can I relate this code with SJMP?

Please anybody explain. Thanks.
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    4.3 KB · Views: 160
  • 1Untitled.jpg
    1Untitled.jpg
    1.7 KB · Views: 144
  • 2Untitled.jpg
    2Untitled.jpg
    9.1 KB · Views: 141

I believe it's easy to understand if you study 8051 instruction set (A good idea anyway).

Conditional branch instruction have only short reach (+/- 127), if the target address can't be reached by it, you must use a LJMP to absolute address.
 
I believe it's easy to understand if you study 8051 instruction set (A good idea anyway).

Conditional branch instruction have only short reach (+/- 127), if the target address can't be reached by it, you must use a LJMP to absolute address.

Hai FVM,

You are right. The spec says that Conditional branch (JNZ,JNB etc.,) have only short reach of (+/- 127). But what is this +/-127 ? Whether it is like, JNB or JNZ will reach only within 127 locations back and forth? or It will reach atleast 127 bytes back and forth? (I believe that each location in a ROM memory have one Instruction word which is more that atleast one byte.)

So how this calculation will be? If it is long to explain, please point me any references.

Thank you sir.
 

Hai FVM!
Thanks for your help Sir. I've found the answer. Each instruction word may be of any size of bytes. So we have to calculate as 1 byte as one address location and 2 byte of a same instruction word as another address location. In this way, we can go upto 127 address locations back and forth. So If we try to reach more than 127th byte, then we cannot use those conditional branch instructions(JNB,JNZ etc.,).
I these situations we have move near by locations of our target and then we can perform our conditional branch instructions.

Thank you sir,. I am clear now.! :)
 

Each instruction word may be of any size of bytes.
Not any. 1 - 3 actually.

Take a look at your assembly listing and see how code addresses and instruction lines are related. Strictly speaking the branch range is (-128 to + 127) relative to the address of the next instruction. There are detailed examples how PC (program counter) is updated during execution of a branch instruction in the instruction set description. You really should study the documents.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top