summaryrefslogtreecommitdiff
path: root/x86_64/mul_by_add.s
blob: 3e8c360f4a2a936088187790d294c0bd0bce8612 (plain)
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
# Do a multiplication without using mulq, resulting in a * b
.section .text
.globl _start

.set OP, 1	# Set here the numbers to
.set OP2, 1	# be multiplied

_start:
	movq	$OP2, %rcx
	movq	$0, %rax

	# We can't rely on loopq to drop exit the loop in case OP2
	# is 0, because the first iteraction will cause %rcx to be -1
	cmpq	$OP2, %rax
	je	exit


addloop:
	addq	$OP, %rax
	loopq addloop

exit:
	movq	%rax, %rdi
	movq	$60, %rax
	syscall