User Tools

Site Tools


spo600:64-bit_assembly_language_lab

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
spo600:64-bit_assembly_language_lab [2025/02/11 11:57] chrisspo600:64-bit_assembly_language_lab [2025/02/11 12:26] (current) chris
Line 1: Line 1:
-** IMPORTANT! - This lab has is being been updated for Winter 2025 -- DO NOT USE YET! ** 
- 
 =====  64-Bit Assembly Language Lab  ===== =====  64-Bit Assembly Language Lab  =====
  
Line 45: 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 C version(s) of the program for x86_64 and aarch64, using ''make''. Take a look at the differences in the code. 1. Build and run the C version(s) of the program for x86_64 and aarch64, using ''make''. Take a look at the differences in the code.
  
 2. Use the ''objdump -d'' command to dump (print) the object code (machine code) and disassemble it into assembler for each of the binaries. Find the ''<nowiki><main></nowiki>'' section and take a look at the code. Also notice the total amount of code. 2. Use the ''objdump -d'' command to dump (print) the object code (machine code) and disassemble it into assembler for each of the binaries. Find the ''<nowiki><main></nowiki>'' section and take a look at the code. Also notice the total amount of code.
 +
 +3. Compare the disassembled output from step 2 above with the assembly language output of the C compiler, produced by running ''gcc'' with the ''-S'' option.
  
 3. Review, build, and and run the aarch64 assembly language program (on the [[SPO600 Servers|aarch64 class server]]) using ''make'', taking note of the commands that are executed to assemble and link the code. Verify that you can disassemble the object code in the ELF binary using ''objdump -d //objectfile//'' and take a look at the code. 3. Review, build, and and run the aarch64 assembly language program (on the [[SPO600 Servers|aarch64 class server]]) using ''make'', taking note of the commands that are executed to assemble and link the code. Verify that you can disassemble the object code in the ELF binary using ''objdump -d //objectfile//'' and take a look at the code.
Line 66: Line 66:
 1. Review, build, and run the aarch64 assembly language programs. Take a look at the code using ''objdump -d //objectfile//'' and compare it to the source code. 1. Review, build, and run the aarch64 assembly language programs. Take a look at the code using ''objdump -d //objectfile//'' and compare it to the source code.
  
-2. Here is a basic loop in AArch64 assembler - this loops from 0 to 9, using r19 as the index (loop control) counter:+2. Here is a basic loop in AArch64 assembler - this loops from 0 to 5, using r19 as the index (loop control) counter:
  
 <code> <code>
Line 72: Line 72:
  .globl _start  .globl _start
  min = 0                          /* starting value for the loop index; **note that this is a symbol (constant)**, not a variable */  min = 0                          /* starting value for the loop index; **note that this is a symbol (constant)**, not a variable */
- max = 10                         /* loop exits when the index hits this number (loop condition is i<max) */+ max =                         /* loop exits when the index hits this number (loop condition is i<max) */
  _start:  _start:
      mov     x19, min      mov     x19, min
Line 90: Line 90:
  
 <code> <code>
- Loop 
- Loop 
- Loop 
- Loop 
  Loop  Loop
  Loop  Loop
Line 109: Line 105:
  Loop: 3  Loop: 3
  Loop: 4  Loop: 4
- Loop: 5 + Loop: 5</code>
- Loop: 6 +
- Loop: 7 +
- Loop: 8 +
- Loop: 9</code>+
  
 Character conversion tip: In order to print the loop index value, you will need to convert from an integer to digit character. In ASCII/ISO-8859-1/Unicode UTF-8, the digit characters are in the range 48-57 (0x30-0x39). You will also need to assemble the message to be printed for each line - you can do this by writing the digit into the message buffer before outputting it to stdout, which is probably the best approach, or you can perform a sequence of writes for the thee parts of the message ('Loop: ', number, '\n'). You may want to refer to the manpage for ''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/ISO-8859-1/Unicode UTF-8, the digit characters are in the range 48-57 (0x30-0x39). You will also need to assemble the message to be printed for each line - you can do this by writing the digit into the message buffer before outputting it to stdout, which is probably the best approach, or you can perform a sequence of writes for the thee parts of the message ('Loop: ', number, '\n'). You may want to refer to the manpage for ''ascii''.
Line 119: 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. Extend the AArch64 code to loop from 00-30, printing each value as a 2-digit decimal number.+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. 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-30 instead of 00-30). To do this, you'll need to add a conditional into your code (the equivalent of an "if" statement, implemented as a compare followed by a conditional branch or conditional jump).+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 "if" statement, implemented as a compare followed by a conditional branch or conditional jump). 
 + 
 +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) ==== ==== x86 (Complete this part after class) ====
Line 135: Line 129:
  .globl    _start  .globl    _start
  min = 0                         /* starting value for the loop index; **note that this is a symbol (constant)**, not a variable */  min = 0                         /* starting value for the loop index; **note that this is a symbol (constant)**, not a variable */
- max = 10                        /* loop exits when the index hits this number (loop condition is i<max) */+ max =                        /* loop exits when the index hits this number (loop condition is i<max) */
  _start:  _start:
      mov     $min,%r15           /* loop index */      mov     $min,%r15           /* loop index */
Line 149: Line 143:
  
  
-**Note:** The x86 division instruction is quite a bit different from the aarch64 division instructions. Read the documentation for the instructions (either in the quick start notes or the reference manual) carefully.+**Note:** The x86 division instruction is quite a bit different from the aarch64 division instructions. Read the documentation for the instructions carefully (either in the quick start notes or the reference manual).
  
 ====  Deliverables  ==== ====  Deliverables  ====
spo600/64-bit_assembly_language_lab.1739275031.txt.gz · Last modified: 2025/02/11 11:57 by chris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki