subroutine, and how it is used with the call and return instructions.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

(a) Describe the term subroutine, and how it is used with the call and return instructions.

(b) Explain the term stack overflow and how it will happen in the PIC16F84A.

 

(c) Consider the following program in Figure 2, replacing the call shuffle up instruction with goto
shuffle up, leaving all else unchanged. Build, simulate and step through the program. Explain the
effect of replacing call with goto?

**...
:Fibonacci_SRS
;This program rewrites the Full Fibonacci progran to illustrate the use of
subroutines.
;Program intended for sinulation only, hence no input/output.
TJW 17.11.08
Tested by simulation 17.11.08
(initial program sections omitted)
forward movf fibl,0
addwf fib2,0
btfsc status,c
:test if we have overflowed 8-bit range
goto reverse
ihere if we have overflowed,
;hence reverse down the series
movwf fibtemp
incf counter,1
;latest number now placed in fibtemp
now shuffle numbers held, discarding the oldest
call shuffle_up
goto forward
z when reversing down, we will subtract fibo from fibl to form new fibo
reverse movf fib0,0
subwf fibl,0
movw! fibtemp
decf counter, 1
;now shuffle numbers held, discarding the oldest
call shuffle_down
;latest number now placed in fibtemp
;test if counter has reached 3, in which case return to forward
movf
counter,0
sublw 3
btfac status,z
goto
goto
forward
reverse
......
.....
:Subroutines
;Shuffles numbers in series, moving fibl to fibo, fib2 to fibl, fibtemp to fib2
shuffle_up movf fibl,0
ifirst move middle number, to overwrite oldest
movwf fib0
movf fib2,0
movwf fibl
movf fibtemp,0
movwt fib2
return
:Shuffles numbers in series, moving fibl to fib2, fibo to fibl, fibtemp to fibo
;first move middle number, to overwrite oldest
shuffle_down movf fibl,0
movwf fib2
movf fibo,0
movwf fibl
movf fibtemp,0
movwf fibo
return
end
Figure 2: Using subroutines in the Fibonacci program
Transcribed Image Text:**... :Fibonacci_SRS ;This program rewrites the Full Fibonacci progran to illustrate the use of subroutines. ;Program intended for sinulation only, hence no input/output. TJW 17.11.08 Tested by simulation 17.11.08 (initial program sections omitted) forward movf fibl,0 addwf fib2,0 btfsc status,c :test if we have overflowed 8-bit range goto reverse ihere if we have overflowed, ;hence reverse down the series movwf fibtemp incf counter,1 ;latest number now placed in fibtemp now shuffle numbers held, discarding the oldest call shuffle_up goto forward z when reversing down, we will subtract fibo from fibl to form new fibo reverse movf fib0,0 subwf fibl,0 movw! fibtemp decf counter, 1 ;now shuffle numbers held, discarding the oldest call shuffle_down ;latest number now placed in fibtemp ;test if counter has reached 3, in which case return to forward movf counter,0 sublw 3 btfac status,z goto goto forward reverse ...... ..... :Subroutines ;Shuffles numbers in series, moving fibl to fibo, fib2 to fibl, fibtemp to fib2 shuffle_up movf fibl,0 ifirst move middle number, to overwrite oldest movwf fib0 movf fib2,0 movwf fibl movf fibtemp,0 movwt fib2 return :Shuffles numbers in series, moving fibl to fib2, fibo to fibl, fibtemp to fibo ;first move middle number, to overwrite oldest shuffle_down movf fibl,0 movwf fib2 movf fibo,0 movwf fibl movf fibtemp,0 movwf fibo return end Figure 2: Using subroutines in the Fibonacci program
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY