summaryrefslogtreecommitdiffstats
path: root/print-repeat.asm
blob: 3856abd465cfd8b0cb6f9cc2d58caff89196e813 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
; Version	: 2.0
; Last update   : 3/1/2019
; Licence	: GPLv3
; Description   : Ever wanted to print something 10000 times really fast? Well, this program does exactly that. (This is ~4x faster than what gcc -O3 -march=native outputs from a normal C implementation)
section .data
Install:	db 'Install '		;The first 8 bytes of the message
Gentoo:		db 'Gentoo!', 0xA	;The second 8 bytes of the message

section .text
	global _start

_start:
xor ecx,ecx	;0 out the counter registor

ALIGN 16	;Align the stack to 16 bytes
loop: inc ecx	;increment the counter every loop

;;Push the message to the stack, (needs to be done in reverse)
push qword[Gentoo]
push qword[Install]

test ecx,8192	;test for most signficant 1 bit in 10,000
je loop

test ecx,1024	;test for next most signficant 1 bit in 10,000
je loop

cmp ecx,10000	;check for full number when both tests pass
jnz loop	;continue if number is not exact

;; e instead of r prefixes are used since that's faster. This is indeed a 64 bit syscall though. rsi=memory location to start printing, rdx=num of bytes to print
mov eax,1	;sys_write
mov edi,1	;fd = STDOUT_FILENO
mov edx,160000	;hardcoded num of bytes to print since we know how many times we print
mov rsi,rsp	;the value of rsp is the start of where the text is, so we mov that to rsi for syscall
syscall

exit:	mov eax,60 ;sys_exit
	xor edi,edi ;return 0
	syscall ;do sys_exit