Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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: image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago