Add VFPU::Float (but it is broken)
[ipdf/code.git] / src / sub_digits_asm.s
1 .section .text
2 .globl sub_digits
3 .type sub_digits, @function
4
5 # Subtract two arrays of 64 bit digits, with carry, modifying the first argument
6 # Address at first argument %rdi is array to add and modify
7 # Address at second %rsi will be added (not modified)
8 # Third argument is counter of number of digits
9 # Result in %rax is the final result in the carry flag
10 # Exploits the fact that inc and dec do not affect the carry flag
11 sub_digits:
12         subq $0, %rax           # Reset the carry/borrow flag
13         loop:
14                 movq (%rsi), %rax # Temporarily store digit from second array
15                 sbbq %rax, (%rdi) # Subtract digits in second and first array, store in first
16                 dec %rdx # Decrement counter
17                 jz end_loop # We are done
18                 
19                 # Move to next element in the first array
20                 leaq 8(,%rdi,1), %rdi
21                 # Move to next element in the second array
22                 leaq 8(,%rsi,1), %rsi
23                 jmp loop # Repeat
24         end_loop:
25                 movq $0, %rax
26                 jnc end
27                 movq $1, %rax
28         end:
29                 ret # We are done

UCC git Repository :: git.ucc.asn.au