在这里呢,我要郑重感谢@米线YH的博文帮助,之前有好几个实验都不会写,"参考"了他的博文写了不少,哈哈.非常感谢.
他的ARM实验1我也"参考"写完了,但是后面的实验都没有了,我就自己借用相关工具来完成后续实验,也发布出来,给大家掌掌眼!
还是非常感谢@米线YH
(1)编写ARM64汇编语言实现如下功能:在给定的一组整数中查找最大数。
TypeScript
.section .data
numbers: .word 10, 20, 30, 5, 25
num_count: .word 5
print_format:
.string "The maximum number is: %d\n"
.section .text
.global main
main:
stp x29, x30, [sp, -16]!
ldr x0, =numbers
ldr x1, =num_count
ldr w1, [x1]
ldr w2, [x0]
find_max_loop:
subs w1, w1, #1
beq end_find_max
add x0, x0, #4
ldr w3, [x0]
cmp w3, w2
csel w2, w3, w2, gt
b find_max_loop
end_find_max:
mov x1, x2
ldr x0, =print_format
bl printf
mov w0, #0
ldp x29, x30, [sp], 16
ret
(2)编写ARM64汇编语言程序实现:复制字符串(C语言strcpy函数的功能)。
TypeScript
.section .data
src_str: .string "Hello, ARM64!"
dst_str: .space 20
.section .text
.global main
main:
stp x29, x30, [sp, -16]!
adr x0, src_str
adr x1, dst_str
copy_loop:
ldrb w2, [x0]
strb w2, [x1]
cmp w2, #0
beq end_copy
add x0, x0, #1
add x1, x1, #1
b copy_loop
end_copy:
adr x0, dst_str
bl dispmsg
bl dispcrlf
mov x0, 0
ldp x29, x30, [sp], 16
ret