spo600:64-bit_assembly_language_lab
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
spo600:64-bit_assembly_language_lab [2024/02/02 15:26] – [Optional Investigation] chris | spo600:64-bit_assembly_language_lab [2025/02/11 12:26] (current) – chris | ||
---|---|---|---|
Line 5: | Line 5: | ||
Perform this lab on [[SPO600 Servers]] (you may use your own systems if they are of the right architecture and appropriately configured). | Perform this lab on [[SPO600 Servers]] (you may use your own systems if they are of the right architecture and appropriately configured). | ||
- | ===== Lab 3 ===== | + | ===== Lab 5 ===== |
==== Code Examples | ==== Code Examples | ||
Line 30: | Line 30: | ||
| | ||
| | ||
+ | |||
+ | **Reminder: | ||
Throughout this lab, take advantage of //[[make and Makefiles|make]]// | Throughout this lab, take advantage of //[[make and Makefiles|make]]// | ||
Line 41: | Line 43: | ||
==== Optional Investigation | ==== Optional Investigation | ||
- | These steps were performed in the lecture class. | + | **These steps were performed in the lecture class.** |
- | 1. Build and run the three C versions | + | 1. Build and run the C version(s) |
2. Use the '' | 2. Use the '' | ||
- | 3. Review, build, and run the x86_64 | + | 3. Compare the disassembled output from step 2 above with the assembly language |
- | 4. Build and run the assembly language | + | 3. Review, build, and and run the aarch64 |
- | ==== Lab Tasks ==== | + | 4. Review, build, and run the x86_64 assembly language programs using '' |
- | 1. Review, build, and run the aarch64 assembly language programs. Take a look at the code using '' | ||
- | 2. Here is a basic loop in AArch64 assembler - this loops from 0 to 9, using r19 as the index (loop control) counter: | + | ==== AArch64 (Complete this part in your in-class breakout group, if possible) |
+ | |||
+ | The steps in the previous section were demonstrated in the class. | ||
+ | |||
+ | Perform these steps in your breakout group using the "mob programming" | ||
+ | |||
+ | 0. Have the group driver share their screen, log into the [[SPO600 Servers|aarch64 server]], and unpack the archive (above). | ||
+ | |||
+ | 1. Review, build, and run the aarch64 assembly language programs. Take a look at the code using '' | ||
+ | |||
+ | 2. Here is a basic loop in AArch64 assembler - this loops from 0 to 5, using r19 as the index (loop control) counter: | ||
< | < | ||
Line 61: | Line 72: | ||
| | ||
min = 0 /* starting value for the loop index; **note that this is a symbol (constant)**, | min = 0 /* starting value for the loop index; **note that this is a symbol (constant)**, | ||
- | max = 10 /* loop exits when the index hits this number (loop condition is i<max) */ | + | max = 6 /* loop exits when the index hits this number (loop condition is i<max) */ |
| | ||
| | ||
loop: | loop: | ||
- | /* **... body of the loop ... do something useful here ...** */ | + | |
- | | + | /* ... body of the loop ... do something useful here ... */ |
- | | + | |
- | | + | |
- | | + | |
+ | | ||
+ | |||
+ | | ||
| | ||
| | ||
Line 76: | Line 90: | ||
< | < | ||
- | Loop | ||
- | Loop | ||
- | Loop | ||
- | Loop | ||
Loop | Loop | ||
Loop | Loop | ||
Line 95: | Line 105: | ||
Loop: 3 | Loop: 3 | ||
Loop: 4 | Loop: 4 | ||
- | Loop: 5 | + | Loop: 5</ |
- | Loop: 6 | + | |
- | Loop: 7 | + | |
- | Loop: 8 | + | |
- | Loop: 9</ | + | |
Character conversion tip: In order to print the loop index value, you will need to convert from an integer to digit character. In ASCII/ | Character conversion tip: In order to print the loop index value, you will need to convert from an integer to digit character. In ASCII/ | ||
Line 105: | Line 111: | ||
For reference, here is a [[6502 Counting Loop Example|6502 implementation of this loop]]. | For reference, here is a [[6502 Counting Loop Example|6502 implementation of this loop]]. | ||
- | 3. Repeat the previous | + | 3. Extend the AArch64 code to loop from 00-32, printing each value as a 2-digit decimal number. |
+ | |||
+ | 2-Digit Conversion tip: You will need to take the loop index and convert it into separate digits by dividing by 10; the quotient will be the first digit and the remainder will be the second digit. For example, if the loop index value is 25 in decimal, dividing by 10 will yield a quotient of 2 and a remainder of 5. You will then need to convert each digit into a character (using the same approach used in the single-digit loop). Read the description of the division instruction carefully. On x86_64, you need to set up specific registers before performing a division. On AArch64, you will need to use a second instruction to find the remainder after a division. | ||
+ | |||
+ | 4. Change the code as needed to suppress the leading zero (printing 0-32 instead of 00-32). To do this, you'll need to add a conditional into your code (the equivalent of an " | ||
+ | |||
+ | 5. Make a copy of the code and change it to output in hexadecimal (0-20) instead of decimal (0-32). | ||
+ | |||
+ | ==== x86 (Complete this part after class) ==== | ||
+ | |||
+ | 5. Repeat the previous | ||
For reference, here is the loop code in x86_64 assembler: | For reference, here is the loop code in x86_64 assembler: | ||
Line 113: | Line 129: | ||
| | ||
min = 0 /* starting value for the loop index; **note that this is a symbol (constant)**, | min = 0 /* starting value for the loop index; **note that this is a symbol (constant)**, | ||
- | max = 10 /* loop exits when the index hits this number (loop condition is i<max) */ | + | max = 5 /* loop exits when the index hits this number (loop condition is i<max) */ |
| | ||
| | ||
loop: | loop: | ||
- | /* **... body of the loop ... do something useful here ...** */ | + | /* ... body of the loop ... do something useful here ... */ |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | | |
- | 4. Extend the AArch64 code to loop from 00-30, printing each value as a 2-digit decimal number. | + | |
- | + | ||
- | 2-Digit Conversion tip: You will need to take the loop index and convert it to a 2-digit decimal number by dividing by 10. Read the description of the division instruction carefully. On x86_64, you need to set up specific registers before performing a division. On AArch64, you will need to use a second instruction to find the remainder after a division. | + | |
- | 5. Change the code as needed to suppress the leading zero (printing 0-30 instead of 00-30). | ||
- | 5. Repeat | + | **Note:** The x86 division instruction is quite a bit different from the aarch64 division instructions. Read the documentation |
==== Deliverables | ==== Deliverables | ||
- | 1. Complete the lab section, above. | + | 1. Complete the lab sections, above. |
- | 2. Blog about the programs you've written. Describe the experience of writing and debugging in assembler, as compared to writing in other languages. Contrast x86_64 | + | 2. Blog about the programs you've written. Describe the experience of writing and debugging in assembler, as compared to writing in other languages. Contrast |
==== Optional Challenge | ==== Optional Challenge | ||
Line 164: | Line 176: | ||
4 x 2 = 8 | 4 x 2 = 8 | ||
5 x 2 = 10 | 5 x 2 = 10 | ||
- | ** //...lines snipped for space...// ** | + | ** ...lines snipped for space... ** |
11 x 12 = 132 | 11 x 12 = 132 | ||
| |
spo600/64-bit_assembly_language_lab.1706887606.txt.gz · Last modified: 2024/04/16 18:10 (external edit)