/* 
 * File:        addreal.s
 * Description: Adds two floating pointer numbers.
 */

        .arch   armv8-a

        .global main

        .text
        .align  2
main:
        stp     fp, lr, [sp,-16]!
        mov     fp, sp

        adr     x0, prompt
        bl      printf

        adr     x0, infmt               // Pass the input format in x0
        adr     x1, x                   // Pass the address of x in x1
        adr     x2, y                   // Pass the address of y in r2
        bl      scanf                   // Call scanf

        adr     x0, outfmt              // Pass the output format in x0
        adr     x1, x                   // Pass the contents of x in x1
        ldr     d0, [x1]
        adr     x2, y                   // Pass the contents of y in x2
        ldr     d1, [x2]
        fadd    d2, d0, d1              // Add x and y

        bl      printf
        
        mov     x0, #0
        ldp     fp, lr, [sp], 16
        ret
        
        .data                           // Start of data segment
        .align  3                       // Align on an address divisible by 8

x:      .quad   0                       // The first double
y:      .quad   0                       // The second double

        .section .rodata
        
prompt:   .string "Enter two reals: "
infmt:    .string "%lf %lf"
outfmt:   .string "%f + %f = %f\n"
