Question: Question 2: Stack and subroutines -Solve this question by writing subroutines which get parameters and return value via the stack! -Explain the purpose of each

Question 2: Stack and subroutines

-Solve this question by writing subroutines which get parameters and return value via the stack!

-Explain the purpose of each instruction!

a) Write a 32-bits addition subroutine that gets two operands from the stack and returns the sum. Each operand must be a 32-bits integer.

b) A recursive subroutine that computes fib(n) = fib(n-1)+fib(n-2), fib(0) = 0, fib(1) = 1 .

SUBROUTINE:

Similar to functions in C

Starts with label

Ends with RET

Example: Question 2: Stack and subroutines -Solve this question by writing subroutines which

Subroutine Example RESET: mov.w bis.b bic.b #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer #0x2A, &P2DIR ; Make ports 2.1, 2.3 and 2.5 Output #0x2A, &P2OUT ; Turn off all three LEDs loop: ; Make port 2.I ON, RED bis.b call bic.b #0x02, &P2OUT #delay #0x02, &P2OUT ; Make port 2.I OFF, RED ; Make port 2.3 ON, GREEN bis.b call bic.b #Ox04, &P2OUT #delay #0x04, &P2OUT ; Make port 2.3 OFF, GREEN ; Make port 2.5 ON, BLUE bis.b call bic.b #0x20,&P2OUT #delay #0x20,&P2OUT ; Make port 2.5 OFF, BLUE jmp loop ; Count down starts at 0 ; delay subroutine delay: mov.w dloop: sub.w jne ret #0,r15 #1, r15 dloop ; Continue delay until back to zero

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!