How To Make Subroutines Callee

How To Make Subroutines Callee - push r5 push r6 push r7...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
How To Make Subroutines Callee-Save. .. Any register used by a subroutine MUST be saved and restored from the stack! The following routine illustrates this procedure: ;---------------------------------------------------------------------------- -- ; SUBROUTINE: GENERATES NEXT RANDOM NUMBER ; ; OUT: r12 = 0-32767 ; random seed updated ; rand16: push r4 ; save registers
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: push r5 push r6 push r7 mov.w RandSeed,r5 ; Prepare multiplication mov.w #MULT,r4 ; Prepare multiplication call #MPYU ; Call unsigned MPY (5.1.1) add.w #INC,r7 ; Add INC to low word of product mov.w r7,RandSeed ; Update RandSeed mov.w r7,r12 ; return in r12 swpb r12 pop r7 ; restore registers pop r6 pop r5 pop r4 ret ; Random number in Rndnum...
View Full Document

This document was uploaded on 02/08/2012.

Ask a homework question - tutors are online