summaryrefslogtreecommitdiff
path: root/nextpow2.asm
diff options
context:
space:
mode:
Diffstat (limited to 'nextpow2.asm')
-rw-r--r--nextpow2.asm46
1 files changed, 46 insertions, 0 deletions
diff --git a/nextpow2.asm b/nextpow2.asm
new file mode 100644
index 0000000..b319d88
--- /dev/null
+++ b/nextpow2.asm
@@ -0,0 +1,46 @@
+format ELF64
+
+extrn printf
+extrn scanf
+extrn puts
+public main
+
+section '.text' executable
+
+main:
+ push rbp
+ mov rbp,rsp
+
+ mov edi,prompt
+ call puts
+
+ sub rsp,16
+
+ mov rsi,rsp
+ mov edi,readint
+ xor eax,eax
+ call scanf
+
+ mov r12,[rsp]
+
+ add rsp,16
+
+ mov rax,r12
+ bsr rcx,rax
+ mov eax,2
+ shl rax,cl
+
+ mov rdx,rax
+ mov rsi,r12
+ mov edi,msg
+ xor eax,eax
+ call printf
+
+ leave
+ ret
+
+section '.data' writable align 16
+
+msg db "Next power of %lu is %lu",0xA,0
+readint db "%lu",0
+prompt db "Enter an integer.",0