ece3140 lab1 (1)

pdf

School

Cornell University *

*We aren’t endorsed by this school

Course

3140

Subject

Computer Science

Date

Apr 3, 2024

Type

pdf

Pages

3

Uploaded by tiwarivayun

Report
Vayun Tiwari ECE 3140 Feb 18 2024 Lab 1: Assembly Programming Introduction : This report outlines the three key assignments in Lab 1: morse code signaling, implementing morse code with ARM calling convention, and a recursive Fibonacci sequence. The goal of this lab was to gain experience with the ARM ISA and testing assembly code on the FRDM-KL46Z microcontroller. Design : Part 1/2 Morse Code: To implement the morse code functionality, I first implemented separate subroutines on top of the provided LEDON, LEDOFF, and LEDSETUP. First, I created two labels for a ‘short’ delay, delay_dot (0x001EB8490), and a ‘long’ delay, delay_dash (0x005B8D80) and saved them to R1 and R2 respectively. dot : Push R6 and LR to the stack. Branch with link to LEDON. Move R1 (dot delay) into R6. Branch with link to delay (keep the LED on for dot time). Branch with link to LEDOFF. Move R1 (dot delay) into R6. Branch with link to delay (keep the LED off after dot has been displayed for dot time). Finally pop R6 and PC. dash : Push R6 and LR to the stack. Branch with link to LEDON. Move R2 (dash delay) into R6. Branch with link to delay (keep LED on for dash time). Branch with link to LEDOFF. Move R1 (dot delay) into R6. Branch with link to delay (keep the LED off after dash has been displayed for dot time). Finally pop R6 and PC. delay : Subtract 1 from R6 (R6 has the time and acts as a decrementing counter). Compare R6 with 0 (since we do not have access to SUBS, we need to use CMP to update the flag). Branch if not equal to delay (loops along delay). Finally branch to link register. morse_digit: Push to LR, Branch with link to LEDSETUP and branch with link to LEDOFF (to ensure that LED is off when starting morse_digit operation). Move 0 to R3 (R3 acts as a counter). Compare R0 to 6 (since the digits 0-9 can be thought about in two halves , the first starting with dots, and the second starting with dashes, we calculate the ‘offset’ to determine which half the digit is in). Branch if greater than or equal to high_loop (if the digit is greater than or equal to 6 branches to high_loop). Otherwise, branch to low_dot_loop. low_dot_loop : Compare R3 to R0 (compare counter to digit to display). Branch if greater than or equal to dash_after_dots. Otherwise, branch with a link to dot to display one dot. Add 1 to R3 (increment counter). Branch to low_dot_loop (loop this function). In this function, if R0 = 0, it will immediately meet the branch condition and start making dashes with no dots. If R0 = 3, it will display 3 dots, and then meet the branch condition and goes to dash_after_dots loop.
dash_after_dots : Compare R3 to 5 (compare counter from low_doot_loop). Branch if greater than or equal to to end. Otherwise, branch with link to dash to display one dash. Add 1 to R3 (increment counter). Branch to dash_after_dots (loop this function) In this function, if R0 = 0, the counter would not have incremented in the low_dot_loop. It would then make 5 dashes before meeting the branch condition and ending the operation. high_loop : Subtract 5 from R0 (to put the digit offset into R0) high_dash_loop: this function follows the same logic as low_dot_loop, except with dashes. dots_after_dash: this function follows the same logic as dash_after_dots, except with dots. end: Pop to PC (morse LED operation completed) The only difference between part 1 and part 2 in my code is Pushing and popping R6 in the dot and dash operations. This is to adhere to ARM calling convention. Other than R6, I am only using registers 0-3. Part 3 Fibonacci: To implement fib functionality, I followed the outline provided on the lab handout. fib : Push R4 and LR to the stack. Compare R0 with 0, and branch if less than or equal to fib_zero. This is the first base case, if n <= 0, return 0. Compare R0 with 1, and branch if greater than or equal to fib_one. This is the second base case, if n == 1, return 1. fib_zero: Move 0 to R0, Pop R4, R5 and PC. fib_one: Move 1 to R0, Pop R4, R5 and PC. These functions put the return value into R0, and return to the outer fib function. Move R0 into R4 to save the value of n. Then subtract 1 from R0 and call fib. This will compute fib(n-1), and then move that value into R5. Subtract 2 from R4 (which had the old value of n) and put it into R0 and call fib. This computes fib(n-2). Move R0 into R4 (value of fib(n-2)) and then add R5 and R4 into R0. Lastly pop R4, R5, and PC. An image of the stack diagram is shown below for n = 2.
Figure 1: Stack diagram of recursive fib(2) call Code Review and Testing : While implementing part 1 and 2, I hard coded a value to R0 to test that the right combination of dashes and dots is displayed. To test all values, I created a loop that starts at 9 and displays morse digits from 9-0. In the submitted code, R0 is hard coded to a value to display a digit for grading. Part 1 displays 7, part 2 displays 3. While implementing part 3, I hard coded a value to R0 again to test that fib computes the right value (displayed with morse_digit). My test cases are hard coded to compute fib(1), fib(3), and fib(6). I think testing fib was the most difficult because morse_digit must work correctly to ensure that fib works correctly. I had made a change to my morse_digit code in part1/2 that I did not carry over into part 3 for fib, so I spent a lot of time rewriting and debugging fib while the issue was in morse_digit.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help