A. Introduction:
- In this lab, we will begin to use assembly language for architecture AArch64 and x86-64
- To view the code for AArch64, please visit this pastebin link
- Before you go on, I must say that this is similar to the AArch64 version. The only difference is where the remainder and quotient are stored in the memory
B. Code explanation:
I. Program sections and flows:
- In assembly, there are different sections that serve a sole purpose. For example, the
text
section is used to store your code while thedata
andbss
sections are used to declare variables - In the
text
section, there is a_start
label that declare the start of the program
II. Constants and variables:
- First, we need to have the maximum of loops we want to perform or it will be an infinite loop. For this program, we will be using 2 constants for the minimum and maximum loop. However, these are not variables, they are just constants
- In the
data
section, we have 2 variables to store the message and the length of the message
III. Index checking:
- As the index increasing, we need to check whether the index is single or double digit before we display it
- To do so, we need to find the quotient and remainder by divide the index with 10
- The remainder will be the digit on the right while the quotient will be the digit on the left
- However, the quotient is stored in the ‘al’ register while the remainder is stored in the ‘dx’ register
- Then, we check if the quotient is0 or not. If the quotient is 0 then the index only has one digit
- Finally, after the digit are checked out, we will load them into the position after the “Loop: ” message
IV. Printing:
- To print the message, we need to use specific values for the system call
- The values including the address of the message, the length of the message, which operation and stream to use
- In this case, the operation will be writing and the stream will be standard output