summaryrefslogtreecommitdiff
path: root/curl_test.asm
diff options
context:
space:
mode:
Diffstat (limited to 'curl_test.asm')
-rw-r--r--curl_test.asm45
1 files changed, 45 insertions, 0 deletions
diff --git a/curl_test.asm b/curl_test.asm
new file mode 100644
index 0000000..159a520
--- /dev/null
+++ b/curl_test.asm
@@ -0,0 +1,45 @@
+global main
+
+extern curl_easy_init
+extern curl_easy_cleanup
+extern curl_easy_setopt
+extern curl_easy_perform
+
+section .data
+ url db "https://httpbin.org/get", 0
+
+section .text
+
+main:
+ sub rsp, 8
+ ; curl = curl_easy_init()
+ call curl_easy_init wrt ..plt ; puts cURL handle in rax
+ test rax, rax ; if rax == 0 (handle is NULL) it failed
+ jz .failed
+
+ mov [rsp], rax
+
+ ; curl_easy_setopt(curl, CURLOPT_URL, url)
+ mov rdi, [rsp] ; cURL handle (arg 1)
+ mov rsi, 10002 ; CURLOPT_URL
+ lea rdx, [rel url] ; put address of url in rdx
+ call curl_easy_setopt wrt ..plt ; set option CURLOPT_URL to url
+
+ ; curl_easy_perform()
+ mov rdi, [rsp] ; cURL handle
+ call curl_easy_perform wrt ..plt ; perform cURL
+
+ ; curl_easy_cleanup()
+ mov rdi, [rsp] ; RDI = first function argument, set first argument to rsp (cURL handle)
+ call curl_easy_cleanup wrt ..plt ; call curl_easy_cleanup with argument rdi (cURL handle)
+
+ ; return 0
+ mov eax, 0 ; eax for return code
+ mov qword [rsp], 0 ; zero the cURL pointer just in case because why not
+ add rsp, 8
+ ret
+
+.failed:
+ mov eax, 1 ; eax for return code
+ add rsp, 8
+ ret