Atmel Tiny2313 return call.

Jun 02, 2005 6 Replies

I'm programming a atmel Tiny 2313, and have to use the "ret" statement. The problem is that ret simply jumps to the top of the program, not the location it was called from. I'm prorgramming in assembler (of course...).



Does anyone know how to "enable" ret call?


I don't know that device but... Do you have to put the program counter on the stack yourself before branching to the sub? If it is and you forgot then when you do the ret you might get 0000

make sure you cleaned up your stack. using the RET is simply popping things off the stack to generate a return address. overflow of the stack or writing 0's on the stack i guess could cause it also :_)

How did you call the routing containing the 'ret'?

You need to use a CALL (Intel) or JSR(Jump to subroutine)(Motorola) instruction - this will store the return address on the stack - the ret instruction pops that address from the stack, and puts it in the program counter. (I don't know Atmel's version of the "jump to subroutine" instruction).

A plain Jump or Branch instruction will not store the return address.

Peter Bennett VE7CEI email: peterbb4 (at) interchange.ubc.ca GPS and NMEA info and programs: http://vancouver-webpages.com/peter/index.html Newsgroup new user info: http://vancouver-webpages.com/nnq

and make sure you have the stack initialized

The 2313 stack grows from the top of sram downwards. You must initialise the stack pointer to a suitable address - probably 0x0df. The stack pointer must never become below 0x060 - which is where the I/O registers start. The SP is decremented by 1 for every PUSH and by 2 for every RCALL. So, the commonest mistakes are (1) not initialising the SP and (2) not matching PUSH and POP instructions, and not matching RCALL and RET.

Posted Via Nuthinbutnews.Com Premium Usenet Newsgroup Services

---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **

----------------------------------------------------------

formatting link

Ah, thank you :) This just solved my problem :) if you pass by, remind me I owe you a beer ;)

MVH, Vidar www.bitsex.net

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required