summaryrefslogtreecommitdiffstats
path: root/print-repeat.asm
diff options
context:
space:
mode:
Diffstat (limited to 'print-repeat.asm')
-rw-r--r--print-repeat.asm40
1 files changed, 40 insertions, 0 deletions
diff --git a/print-repeat.asm b/print-repeat.asm
new file mode 100644
index 0000000..3856abd
--- /dev/null
+++ b/print-repeat.asm
@@ -0,0 +1,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