1 Objectives The goal of this exercise is to start to prepare you to write your own functions using assembly. Assembly h

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

1 Objectives The goal of this exercise is to start to prepare you to write your own functions using assembly. Assembly h

Post by answerhappygod »

1 Objectives The Goal Of This Exercise Is To Start To Prepare You To Write Your Own Functions Using Assembly Assembly H 1
1 Objectives The Goal Of This Exercise Is To Start To Prepare You To Write Your Own Functions Using Assembly Assembly H 1 (77.23 KiB) Viewed 37 times
1 Objectives The Goal Of This Exercise Is To Start To Prepare You To Write Your Own Functions Using Assembly Assembly H 2
1 Objectives The Goal Of This Exercise Is To Start To Prepare You To Write Your Own Functions Using Assembly Assembly H 2 (71.03 KiB) Viewed 37 times
1 Objectives The Goal Of This Exercise Is To Start To Prepare You To Write Your Own Functions Using Assembly Assembly H 3
1 Objectives The Goal Of This Exercise Is To Start To Prepare You To Write Your Own Functions Using Assembly Assembly H 3 (43.94 KiB) Viewed 37 times
1 Objectives The Goal Of This Exercise Is To Start To Prepare You To Write Your Own Functions Using Assembly Assembly H 4
1 Objectives The Goal Of This Exercise Is To Start To Prepare You To Write Your Own Functions Using Assembly Assembly H 4 (11.51 KiB) Viewed 37 times
1 Objectives The goal of this exercise is to start to prepare you to write your own functions using assembly. Assembly has a different vocabulary from C and Java (instructions on registers instead of expressions on variables), and a different structure (branches and labels instead of conditionals and blocks). This exercise is mostly about practicing the vocabulary of loads, compares, and branches, and about following the calling convention. It can be tricky to put together a working assembly function without knowing the useful instructions first. We will provide the high-level structure of some simple routines; all you have to do is fill in the actual instructions that accomplish the goal. In this exercise, we will fill in a template, one (or maybe two) instruction(s) at a time. It will be up to you to use the documentation and our in-class examples to find the appropriate assembly instructions and operands to perform the task described in the template. You can discuss this exercise with other classmates, but you may not exchange any code nor write code together. 2 Grading Criteria Your assignment grade will be determined with the following weights: Results of public tests 20 pts 3 Academic integrity statement Please carefully read the academic honesty section of the course syllabus. We take academic integrity matters seriously. Please do not post assignment solutions online (e.g., answers, github) where others can see your work. Posting code online can lead to an academic case where you will be reported to the Office of Student Conduct. 4 Context: Use of Assembly in Practice Assembly language is used in two key situations. First, when a machine first starts up, assembly language routines read in the operating system. You might call this the "boot loader". Second, when software needs to interact with hardware, it uses special instructions (in, out) or special registers that aren't exposed to C code. Here, we're working in the context of a C program, where these routines will be called from C, but we won't do anything the compiler couldn't. You'll also see "hand tuned" assembly called from C when a routine needs to be optimized for size, speed, or to ensure specific timing. Only extremely important or frequently used code gets this treatment, but on small microcontrollers without much memory for instructions, optimization for size is common.
5 Template Style You will fill in the code in a template that uses the following conventions. Comments led by three semicolons are descriptive background. They represent context, or show the prototype of the function as it will be called by C code. Comments led by two semicolons represent an instruction you're meant to fill in. Leave all template comments in your solution. You may add comments after the line of code using a single semicolon. Labels are already included. Labels represent the beginnings of functions and branch targets. Numeric la- 1 bels are branch targets and need not be unique because the assembler will find the nearest label having that number. For example, brge 1f will search "forward" for the next label "1". The "global" declarations tell the assembler that the label should be exported, which allows the linker to connect a function call in the C driver file to this function implementation. You can think of it like "extern" in C, but we've provided it for you in the template. We can use directives like these to declare global variables as well. In some cases, the comment describing what to do will require two related instructions (e.g., add/adc, cp/brge, clr/clr) to complete. It is permitted, but not recommended, to deviate somewhat from these instructions, or even to find one instruction that accomplishes two-comments-worth of the exercise. Assembly is generally formatted so that labels are flush-left and instructions are indented by a "tab". In- a literal tab character; dentation makes the labels more visible. The assembler, unlike make, does not ne indentation can be accomplished with spaces and indentation is optional to the language (unlike Python or Fortran). Emacs "assembler-mode" will try to help with this formatting; other editors may do the same.
1;;; Five 2 3 4 5 1 7 Functions 7.1 Five This function will return the value "5" as a 16-bit integer. You will need to figure out where the return value belongs and how to load an immediate (constant) into it. 8 1 2 Five: global Five 2 > Max: 4 5 6 7 ;;; uint16_t Five(): return 5 as a uint16_t :: load immediate ;; load immediate or clear return Note that until you fill in the return instruction, the processor will just keep going, kind of like a switch/case without a break in C. 7.2 Max This implementation of Max relies on the first parameter having the same location as the return value. 717 Max 1: global Maxi ;;; uint8_t max(uint8_t x, uint8_t y): return the greater of the arguments compare x to y ;; if x >y, branch 1f ;; copy y into return value / first param slot. ;; return 7.3 Strlen Note that the return value is a 16-bit integer and a pointer is a 16-bit value. It will sometimes take two instructions to alter values. ::: Strlen global Strlen Strlen: ::: uint16_t Strlen(char arg).
6 7 B 9 10 11 12 13 2: 1: :: copy argument to X (r27:26) pointer :: initialize return value to zero ::load X with post-increment :: if loaded value was zero, branch 1f (label 1, forward) ::increment return value :: jump 2b (label 2, backward) :: return
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply