-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.s
54 lines (41 loc) · 764 Bytes
/
math.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
53
54
.section .data
.include "linux.s"
.include "ascii.s"
.include "logic.s"
.include "numbers.s"
.section .bss
.section .text
# FUNCTION: base_to_power
#
# Calculate BASE**POWER.
#
# PARAMETERS
#
# %rdi - BASE
# %rsi - POWER
#
# LOCAL VARIABLES
#
# %rax - ongoing calculation of result
#
# RETURN
#
# Integer result of BASE**POWER
#
.globl base_to_power
.type base_to_power, @function
base_to_power:
cmpq $0, %rsi
je to_power_zero
movq %rdi, %rax
dec %rsi
loop_base_to_power:
cmpq $0, %rsi
je exit_base_to_power
mul %rdi # implicitly mul %rdi, %rax
dec %rsi
jmp loop_base_to_power
to_power_zero:
movq $1, %rax
exit_base_to_power:
ret