Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Jumptable

Jumptable

2005-05-17 by Paul Maddox

All,

 Is it possible to impliment a jump table based on the value read from an IO 
port?
What I want is to have a 8 routines, and when the value from a port is read 
(3 bit value) it jumps to the appropriate routine, I want to avoid CMP and 
BREQ if possible as I need a constant length for this, using multiple 
CMP/BREQs would result in a variable excution time.

Oh, I'm doing this in assembler....

Any thoughts?

Paul

Re: [AVR-Chat] Jumptable

2005-05-17 by Leon Heller

----- Original Message -----
Sent: Tuesday, May 17, 2005 11:31 AM
Subject: [AVR-Chat] Jumptable

All,

Is it possible to impliment a jump table based on the value read from an IO
port?
What I want is to have a 8 routines, and when the value from a port is read
(3 bit value) it jumps to the appropriate routine, I want to avoid CMP and
BREQ if possible as I need a constant length for this, using multiple
CMP/BREQs would result in a variable excution time.

Oh, I'm doing this in assembler....

Any thoughts?

I've not actually done it but it should be quite easy: something like using the ICALL instruction after setting the Z registers to the start of the jump table and adding the input value to ZL. It's actually more complicated than that, but you should get the idea.
Leon
--

Re: [AVR-Chat] Jumptable

2005-05-17 by Paul Maddox

Leon,

Thanks, I hadn't spotted that in the instruction set.
Just looking at IJMP, it may be simpler to use, no pushing/pulling from the 
stack and its 1 less clock cycle (speed is king)...

Paul
Show quoted textHide quoted text
----- Original Message ----- 
From: "Leon Heller" <leon.heller@dsl.pipex.com>
To: <AVR-Chat@yahoogroups.com>
Sent: Tuesday, May 17, 2005 12:05 PM
Subject: Re: [AVR-Chat] Jumptable


  ----- Original Message ----- 
  From: Paul Maddox
  To: AVR-Chat@yahoogroups.com
  Sent: Tuesday, May 17, 2005 11:31 AM
  Subject: [AVR-Chat] Jumptable


  All,

  Is it possible to impliment a jump table based on the value read from an 
IO
  port?
  What I want is to have a 8 routines, and when the value from a port is 
read
  (3 bit value) it jumps to the appropriate routine, I want to avoid CMP and
  BREQ if possible as I need a constant length for this, using multiple
  CMP/BREQs would result in a variable excution time.

  Oh, I'm doing this in assembler....

  Any thoughts?




I've not actually done it but it should be quite easy: something like using 
the ICALL instruction after setting the Z registers to the start of the jump 
table and adding the input value to ZL. It's actually more complicated than 
that, but you should get the idea.

Leon
--
Leon Heller
http://www.geocities.com/leon_heller

Re: [AVR-Chat] Jumptable

2005-05-17 by Zack Widup

On Tue, 17 May 2005, Leon Heller wrote:

>   All,
> 
>   Is it possible to impliment a jump table based on the value read from an IO 
>   port?
>   What I want is to have a 8 routines, and when the value from a port is read 
>   (3 bit value) it jumps to the appropriate routine, I want to avoid CMP and 
>   BREQ if possible as I need a constant length for this, using multiple 
>   CMP/BREQs would result in a variable excution time.
> 
>   Oh, I'm doing this in assembler....
> 
>   Any thoughts?
> 
> 
> 
> 
> I've not actually done it but it should be quite easy: something like 
> using the ICALL instruction after setting the Z registers to the start 
> of the jump table and adding the input value to ZL. It's actually more 
> complicated than that, but you should get the idea.
> 
> Leon
> --

Yes, I've done it that way (in assembler).  I'll have to dig for the 
sample code if you want it.  One thing to do is to make sure you mask off 
all but the 3 bits you're going to add to the ZL register.  Otherwise it's 
possible to end up some place you have no idea where.

Zack

Re: [AVR-Chat] Jumptable

2005-05-17 by Paul Maddox

Zack,

> Yes, I've done it that way (in assembler).  I'll have to dig for the
> sample code if you want it.

i'd like to see it, if you don't mind, thanks.

> One thing to do is to make sure you mask off
> all but the 3 bits you're going to add to the ZL register.  Otherwise it's
> possible to end up some place you have no idea where.

hehe, that seems to happen to me a lot :-)

Paul

Re: Jumptable

2005-05-17 by leon_heller

--- In AVR-Chat@yahoogroups.com, "Paul Maddox" <P.Maddox@s...> wrote:
> Leon,
> 
> Thanks, I hadn't spotted that in the instruction set.
> Just looking at IJMP, it may be simpler to use, no pushing/pulling 
from the 
> stack and its 1 less clock cycle (speed is king)...

I've just written a simple jump table program using ICALL:

  .include "tn2313def.inc"

     .def	temp=r16


     .cseg
	 .org	0
	 rjmp	reset

reset:
	ldi		temp,low(RAMEND)
	out		spl,temp
	ldi		temp,$03


loop:
	rol		temp
	ldi		zl,low(jump_table)
	ldi		zh,high(jump_table)
	add		zl,temp
	icall
	rjmp	loop


jump_table:
	rcall	zero
	ret
	rcall	one
	ret
	rcall	two
	ret
	rcall	three
	ret

zero:
	ret

one:
	ret

two:
	ret

three:
	ret


Change temp within the loop using the simulator to check that it 
works.

Leon

Re: Jumptable

2005-05-18 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "leon_heller" <leon.heller@d...> 
wrote:
> I've just written a simple jump table program using ICALL:

Your jump table would be better if it consisted only of addresses as 
opposed to the call/return.  That saves both time and space.  I use 
the GNU assembler (comes with gcc) but the idea is the same.  You'll 
just have to convert to the Atmel way of doing things.

Also, unless you can guarantee that the table doesn't cross a 256-byte 
boundary you need to propagate the carry to the high byte.

Depending on what registers you have available, this code can be made 
shorter and more efficient.  This is written using gcc register 
conventions.  In particular, r0 is a temporary register and r1 is 
always zero.  This code also assumes that the index value (in r24) is 
never more than 127.

  ldi  r30, lo8(jmpTable)
  ldi  r31, hi8(jmpTable)
  add  r24, r24
  add  r30, r24
  adc  r31, r1
  ld   r0, Z+
  ld   r31, Z
  mov  r30, r0
  icall

; this table contains the program memory addresses of the specified 
labels
jmpTable:
  .word	pm(one)
  .word pm(two)
  .word pm(three)
  ...
  .word pm(eight)

IAR - Anyone ?

2005-05-18 by Lasse Madsen

Hi All,

I'm trying out IAR's embedded workbench version 3.2A for the first time 
and I've stumbled upon some questions which i hope you can help me with.

1)
when you write:

printf("Hello World");

It seems (or so i think) that IAR stores the string in RAM rather
than 
in flash why is this and how can it be changed ?


2)
How do you store variables in flash ?

writing: 

const char buffer[]="Hello World";   // is this stored in flash ?
__flash char buffer[]="Hello World"; // this is stored in flash


3)
If I make a long (1024 bytes) string (array) in flash:

__flash char string[1024]={...alot of data...};

And I want to print this to the serial port I do this:

printf("\r\n%s",string);

But it does not work...

So I though I needed a pointer to it... 


__flash char string[1024]={...alot of data...};
char __flash *ptr;

ptr=&string[0];
printf("\r\n%s",ptr);

This didn't work either !?

4)
It seems that in the manual there's a function called:

printf_P for printing from flash but which file must I include to use 
this printf function ? I cant seem to find it?

Best Regards
Lasse Madsen

Re: IAR - Anyone ?

2005-05-19 by John Mann

Lasse;

I am new to the group, but fimiliar with the IAR EWB.  I currently 
have a system I am working on in which I have placed data in both 
the FLASH and EEPROM on an MEGA128. If you look at the manual and 
help file for the IAR compiler, they describe multiple ways of 
forcing data to either the FLASH (ie code) memory or the EEPROM if 
there.

Example __flash char Hello {"Hello World"};

The above example should put the constant string into flash memory.

Have a nice day.
John


--- In AVR-Chat@yahoogroups.com, "Lasse Madsen" <lasse.madsen@e...> 
wrote:
> 
> Hi All,
> 
> I'm trying out IAR's embedded workbench version 3.2A for the first 
time 
> and I've stumbled upon some questions which i hope you can help me 
with.
> 
> 1)
> when you write:
> 
> printf("Hello World");
> 
> It seems (or so i think) that IAR stores the string in RAM rather
> than 
> in flash why is this and how can it be changed ?
> 
> 
> 2)
> How do you store variables in flash ?
> 
> writing: 
> 
> const char buffer[]="Hello World";   // is this stored in flash ?
> __flash char buffer[]="Hello World"; // this is stored in flash
> 
> 
> 3)
> If I make a long (1024 bytes) string (array) in flash:
> 
> __flash char string[1024]={...alot of data...};
> 
> And I want to print this to the serial port I do this:
> 
> printf("\r\n%s",string);
> 
> But it does not work...
> 
> So I though I needed a pointer to it... 
> 
> 
> __flash char string[1024]={...alot of data...};
> char __flash *ptr;
> 
> ptr=&string[0];
> printf("\r\n%s",ptr);
> 
> This didn't work either !?
> 
> 4)
> It seems that in the manual there's a function called:
> 
> printf_P for printing from flash but which file must I include to 
use 
Show quoted textHide quoted text
> this printf function ? I cant seem to find it?
> 
> Best Regards
> Lasse Madsen
> 
>

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.