list p=12c671 include org 0h ; reset vector reset goto start org 5h start ; this is where execution begins ;; This program calls the PIC assembly routine nextnum 10 times. ;; As specified in the assignment nextnum receives its argument ;; in register 20h and returns its result in register 20h. ;; It stores the following information in registers A0h to A4h ;; A0 -- number being passed to the nextnum ;; A1 -- number returned by the nextnum ;; A2 -- number that *should* be returned by nextnum ;; A3 -- number of times nextnum has called ;; A4 -- number of times nextnum returned the right value ;; These register may be checked at the instruction chkpnt. ;; Because CSCI 255 student are told not to examine registers ;; above 7Fh, we assume they will not be modifying A0 to A4 ;; Clear A3 and A4 movlw H'A3' movwf FSR clrf INDF ; A3h <- 0 incf FSR,F clrf INDF ; A4h <- 0 mloop movlw H'A3' movwf FSR movf INDF,W ; W <- A3h sublw D'10' ; W <- 10 - W btfsc STATUS,Z ; skip next instruction if W is zero tloop goto tloop ; while (1) ; movlw H'A3' movwf FSR movf INDF,W ; W <- A3h call retval movwf H'20' ; 20h <- retval movlw H'A2' movwf FSR movf H'20',W movwf INDF ; A2 <- retval movlw H'A3' movwf FSR movf INDF,W ; W <- A3h call callval movwf H'20' ; 20h <- callval movlw H'A0' movwf FSR movf H'20',W movwf INDF ; A0 <- callval call nextnum movlw H'A1' movwf FSR movf H'20',W movwf INDF ; A1h <- nextnum incf FSR,F subwf INDF,W btfss STATUS,Z goto nocount movlw H'A4' movwf FSR incf INDF,F ; A4h <- A4h + 1 nocount movlw H'A3' movwf FSR incf INDF,F ; A3h <- A3h + 1 chkpnt goto mloop callval addwf PCL,F retlw D'1' retlw D'2' retlw D'4' retlw D'30' retlw D'32' retlw D'5' retlw D'10' retlw D'17' retlw D'33' retlw D'75' retval addwf PCL,F retlw D'4' retlw D'1' retlw D'2' retlw D'15' retlw D'16' retlw D'16' retlw D'5' retlw D'52' retlw D'100' retlw D'226' ;; You should modify nothing before this line. ;; Your function goes here. ;; This versino of nextnum always returns 16. ;; It gives the right answer twice nextnum movlw D'16' movwf H'20' return end