Lab3 - AArch64
Instruction
In this lab, I explored assembly language programming on both x86_64 and Aarch64 platforms. The objective was to understand the differences in assembly code generation between these architectures and to implement a simple loop in assembly for both platforms.
Connect AArch64 Server.
ssh username@aarch64-001.spo600.cdot.systems // replace username
Unpack example code.
once you connect to the server, unpack the example code with below command.
tar -xzvf spo600-assembler-lab-examples.tgz
Tasks
Task 1: Reviewing Assembly Language Programs
We used objdump -d
to disassemble the compiled binaries and compared the output to the original source code. This helped us understand how the source code translates into machine instructions for both x86_64 and Aarch64 architectures.
Disassemble the object Code:
objdump -d hello > hello_aarch64_disassembly.txt
Review the main section.
4005d8: a9bf7bfd stp x29, x30, [sp, #-16]!
4005dc: 910003fd mov x29, sp
4005e0: 90000000 adrp x0, 400000 <__abi_tag-0x278>
4005e4: 9118c000 add x0, x0, #0x630
4005e8: 97ffffb2 bl 4004b0 <printf@plt>
4005ec: 52800000 mov w0, #0x0 // #0
4005f0: a8c17bfd ldp x29, x30, [sp], #16
4005f4: d65f03c0 ret
.text
.globl _start
min = 0
max = 30
_start:
mov x19, min // Initialize counter value
loop:
mov x15, 10
// Calculate tens place
udiv x12, x19, x15 // x19 / 10
add x12, x12, '0' // Convert to ASCII
// Calculate units place
msub x13, x12, x15, x19 // x13 = x19 - (x12 * 10) (unit place)
add x13, x13, '0' // Convert to ASCII
adr x1, msg // Load the start address of the message into x1
mov x0, 1 // stdout
// Store tens place in the appropriate position of msg
strb w12, [x1, 6] // Tens place
// Store units place in the appropriate position of msg
strb w13, [x1, 7] // Units place
// Print the message
mov x2, len
mov x8, 64
svc 0
add x19, x19, 1 // Increment the counter
cmp x19, max
b.le loop
// Exit
mov x0, 0
mov x8, 93
svc 0
.data
msg: .ascii "Loop: 00\n"
len= . - msg
Output
[sshin36@aarch64-001 aarch64]$ ./loop
Loop: 0P
Loop: 0Q
Loop: 0R
Loop: 0S
Loop: 0T
Loop: 0U
Loop: 0V
Loop: 0W
Loop: 0X
Loop: 0Y
Loop: 1P
Loop: 1Q
Loop: 1R
Loop: 1S
Loop: 1T
Loop: 1U
Loop: 1V
Loop: 1W
Loop: 1X
Loop: 1Y
Loop: 2P
Loop: 2Q
Loop: 2R
Loop: 2S
Loop: 2T
Loop: 2U
Loop: 2V
Loop: 2W
Loop: 2X
Loop: 2Y
Loop: 3P
I tried to modify so that it print Loop: 01, Loop 02 ... Loop: 30. But even I convert unit place to ASCII but it still shows Alphabet instead of number.
Conclusion
This lab demonstrated the differences in assembly language programming between x86_64 and Aarch64 architectures. Writing a loop that prints numbers alongside a message proved to be straightforward in concept but challenging in execution, particularly when formatting the output correctly. The disassembly step provided valuable insights into how high-level code translates into machine instructions on different platforms.
댓글
댓글 쓰기