Full Version : BREQ question
avr >>ASM PROGRAMMING (AVR) >>BREQ question


pio- 04-03-2007
I tryed assemble this code:

CODE

BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1
BREQ 1


and I got this error:

test3.asm: 66: Error: Branch out of range (-64 <= k <= 63)
test3.asm: 67: Error: Branch out of range (-64 <= k <= 63)

why? How these instructions are translated? Code of these instructions depend from place in memory?

dodew001- 04-09-2007
Syntax: Operands: Program Counter:
BREQ k -64 ≤ k ≤ +63 PC ← PC + k + 1
PC ← PC + 1, if condition is false

looking at your code and at the AVR instruction set I saw nothing wrong (other then a useless code). So I tried the code myself, with only a few breq commands. The shortened code resulted in a clean assembly. Using the debug tool I saw what wend wrong with your code. The assembler doesn't treat de 1 (behind de breq) as an direct operand, but as an calculated operand directing to line 1. This behavior itself doesn't explain the assembly error, it just different then one might expect. Trying to assemble your whole code the assembler calculates the k parameter to redirect the pc to 1, arrived on line 66 it has to go back 65 lines compromising the maximum of 64 (k -64 ≤ k ≤ +63) .


I haven't found a way to tell the assembler to use the 1 as an direct operand, but I did find a work around: just add de program counter and you get your desired jump.



CODE
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1
breq pc+1



I hope this answers your questions.

pio- 05-02-2007
Thanks for your explenation.

Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.