## 4 Proposed Implementation Techniques
### Application of Inline PTX Assembly Codes  
Assembly language is a programming language that is one level up from machine language and belongs to low level languages along with machine language. Writing code in the C language is a high-level language, and assembly language is located between the machine language and the high-level language, making it easier to understand machine languages that are difficult to understand. Because assembly language has a small binary size and the program is fast, we can also consider how to write existing code in assembly language when trying to optimize. An inline assembly technique was developed to use common code and assembly language together, and inline assembly can now be used in GPU, called inline PTX. The functions used in inline PTX are similar in form and usage to functions used in inline assembly.  
Here is how to use inline PTX function using CUDA library in C programming language. We can specify the use of inline PTX by using the \(asm()\) command at the place where inline PTX is used in the general coding area. The inline PTX code declared as \(asm()\) is divided into three areas: the instruction part, the input part, and the output part. The instruction part written with several functions such as \(xor.b32\) is executed by selecting the input register and the output register for the command. The \(n\%\) to the right of the instruction means a register, and the input part and output part under the instruction part are combined and pointed in order from 0%. For example, \"+r\" (x) at the bottom of Figure 9 becomes 0%, \"+r\" (y) is 1%, \"+r\" (z) is 2%, and \"+r\" (w) becomes 3%, which points to the output register. The following variables \"r\" (x), \"r\" (y),..., \"r\" (rk[7]) become 4%, 5%,..., 15%, respectively, which point to the input register. Each output register and input register is called through an inline PTX function to perform the operation.  
Figure 8: Asynchronous execution.  
In this study, encryption operation was performed using inline PTX. We implemented the optimization to store counter value in a register through inline PTX and reduce unnecessary operations using assembly language. For example, one of the main operations of CHAM and LEA, the ROTATE operation was originally a function consisting of two-bit SHIFT operations, one bit OR operation, and one minus operation, but it was implemented to be processed in a register with one instruction using inline PTX.  
In addition, in the case of CHAM and LEA that do not use a table, it is possible to obtain very fast performance by moving all values necessary for encryption to a register and then performing simple operations only. Moreover, since the word rotate process existing in the CHAM encryption operation can be performed by changing only the parameters of the corresponding data register, the number of operations required for encryption can be further reduced. Figures 9 and 10 show the inline PTX code of the CHAM and LEA round function implemented in the actual C language. In the figure, only the first two rounds in CHAM and the first round in LEA are counted, but, in the actual implementation, the code up to 112/24 rounds operates as a single inline PTX function without repetition. Normally, the output is read-only, written as \({}^{\prime\prime}=r^{\prime\prime}\), or \({}^{\prime\prime}+r^{\prime\prime}\) as read-write. Looking at the inline PTX operation, \(reg\) is a register variable declaration, and \(shf.l.clamp\), \(shf.r.clamp\) is a bit ROTATE. \(xor.b32\) is 32-bit XOR operation, add.cc.u32 is 32-bit ADD operation. Lightweight ciphers such as CHAM and LEA can be encrypted with only three commands in inline PTX because the operation consists of XOR, ADD, and ROTATE.