-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfadd-add-floats.s
52 lines (40 loc) · 1.22 KB
/
fadd-add-floats.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// ------------------------------------------------
// Porting Raspberry Pi ARM code to Apple Silicon
// 2023-01-09
// Jds
// ------------------------------------------------
// FADD -- Add two floating point numbers and print
//
// RELATED COMMANDS:
// FADD = add two floats
// FSUB = subtract two floats
// FMUL = multiply two floats
// FDIV = divide two floats
// FABS = absolute value
// FSQR = square root
//
// COMPILE --> make
// RUN --> ./filename
// ------------------------------------------------
.global main
.align 4
main:
ADRP X1, num_1@PAGE // Load the address of num_1
ADD X1, X1, num_1@PAGEOFF
LDR D1, [X1] // Store the contents of X1 to D1
ADRP X2, num_2@PAGE // Load the address of num_2
ADD X2, X2, num_2@PAGEOFF
LDR D2, [X2] // Store the contents of X1 to D1
FADD D0, D1, D2 // Add the floats (D0 = D1 + D2)
prepare_to_print:
STR D0, [SP, #-16]! // Store the result onto the stack
ADRP X0, format@PAGE // Load the address of our printf format string
ADD X0, X0, format@PAGEOFF
end:
BL _printf // print -- reads string from X0 and data from stack
MOV X16, #1
SVC 0
.data
num_1: .double 1.234567
num_2: .double 1.111111
format: .asciz "1.2345 + 1.1111 = %f \n"