Yahoo Groups archive

AVR-Chat

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

Message

Newbie rcall question

2004-12-03 by Geert De Pecker

Hi,

I am about to start with the fascinating world of AVR and, although
I do not have the STK500 for real tests, I'm playing around with the
AVR Studio.

I made a small test program to simulate, but run into the following 
problem: when I run it and the subroutine "doStep" comes at the "ret"
instruction, the program counter jumps back to the "main" label instead
of the instruction after the "rcall" instruction.

What am I doing wrong?

Regards,

Geert

.include "8515def.inc"
;
;       Stepper output ports and pins
;
.equ sPort = PORTB
.equ sVertStep = 0
.equ sVertDir = 1
.equ sHorStep = 2
.equ sHorDir = 3
;
;       Position registers
;
.def moveH = r18
.def moveL = r19
.def posVertL = r20
.def posVertH = r21
.def posHorL = r22
.def posHorH = r23
;
;       Steps per count
;
.equ stepsPerCount = 8

;
;       General vars
;
.def tmp1 = r10
.def tmp2 = r11
.def tmp3 = r12
;
;       Org
;
.org 0x0000
;
;       Interrupts
;
;rjmp   main
;--------------------------------------------------
;       Start of program
;
main:
;
;       Init counters
;
         ldi     posVertH, 0x00
         ldi     posVertL, 0x00
         ldi     posHorH, 0x00
         ldi     posHorL, 0x00
;
;       Test
;
         ldi moveH, 0x00
         ldi moveL, 0x0A
         rcall doStep
         ldi r17, 0x00
         ldi r17, 0x00
         ldi r17, 0x00
         ldi moveH, 0x01
         ldi moveL, 0x03
         rcall doStep
;--------------------------------------------------
;       doStep
;
doStep:
         cpi moveL, 0x00
         brne doStepLow
         cpi moveH, 0x00
         breq doStepEnd
         dec moveH
         ldi moveL, 0xFF
doStepLow:
         dec moveL
         rjmp doStep
doStepEnd:
         ldi r17, 0x00
         ret

Attachments

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.