正如@邁克爾表示,不使用任何指令來「打印」您的款項到屏幕上。你可以使用系統調用或者printf。下面的示例ARMv8代碼使用printf和一些簡單的簡單宏;這不是必需的。
我可以建議你學習ARMv7嗎?因爲這裏有很多教程,然後查看ARMv8指令集概述和AArch64的ARM過程調用標準。
1 /*
2 David @InfinitelyManic
3 http://stackoverflow.com/questions/39845288/cant-print-sum-in-armv8-assembly
4 $ uname -a
5 Linux alarm 3.10.65-4-pine64-longsleep #16 SMP PREEMPT Sun Apr 3 10:56:40 CEST 2016 aarch64 GNU/Linux
6 $ cat /etc/os-release
7 NAME="Arch Linux ARM"
8 gcc -g print_sum.s -o print_sum
9 */
10 .bss
11 .data
12 fmt: .asciz "%d + %d = %d\n"
13 .text
14 .global main
15
16 // macros
17 // push2
18 .macro push2, xreg1, xreg2
19 .push2\@:
20 stp \xreg1, \xreg2, [sp, #-16]!
21 .endm
22
23 // pop2
24 .macro pop2, xreg1, xreg2
25 .pop2\@:
26 ldp \xreg1, \xreg2, [sp], #16
27 .endm
28
29 // exit
30 .macro _exit
31 .exit\@:
32 mov x8, #93 // exit see /usr/include/asm-generic/unistd.h
33 svc 0
34 .endm
35
36 main:
37 mov x1, 1
38 mov x2, 2
39 add x3, x1, x2
40 bl write
41
42 _exit
43
44 write:
45 push2 x29, x30
46 ldr x0,=fmt
47 bl printf
48 pop2 x29, x30
49 ret
OUTPUT:
$./print_sum
1 + 2 = 3
你是如何運行的?您期望哪些說明導致某些內容被打印? – Michael