Reputation: 1
I've been trying to print my sum in ARMv8 but I can't seem to get it to work. I can compile and run but no output is showing.
This is my code:
.balign 4
.global main
main:
stp x29, x30, [sp, -16]!
mov x29, sp
mov x19, 1
mov x20, 2
add x21, x20, x19
mov w0, 0
ldp x29, x30, [sp], 16
ret
Upvotes: 0
Views: 1537
Reputation: 822
As indicated by @Michael, you are not using any instructions to "print" your sum to the screen. You may use syscalls or printf. The sample ARMv8 code below uses printf and some simple simple macros; which are not necessary.
May I suggest you study ARMv7 since there are plenty of tutorials out there then review the ARMv8 Instruction Set Overview and the ARM Procedure Call Standard for AArch64.
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
Upvotes: 1