diff options
| -rw-r--r-- | .gitignore | 9 | ||||
| -rw-r--r-- | Makefile | 24 | ||||
| -rw-r--r-- | curl_test.asm | 45 | ||||
| -rw-r--r-- | loop.asm | 19 | ||||
| -rw-r--r-- | main.asm | 19 |
5 files changed, 116 insertions, 0 deletions
@@ -1,2 +1,11 @@ +<<<<<<< HEAD main.o main_i386 +======= +curl_test +curl_test.o +main.o +main +loop.o +loop +>>>>>>> 181d482 (Initial commit (i got too carried away with asm and forgot to commit)) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0b1c9ea --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +.PHONY: all clean + +all: main curl_test loop + +loop.o: + nasm -f elf64 loop.asm -o loop.o + +loop: loop.o + gcc loop.o -o loop + +main.o: + nasm -f elf64 main.asm -o main.o + +main: main.o + gcc main.o -o main + +curl_test.o: + nasm -f elf64 curl_test.asm -o curl_test.o + +curl_test: curl_test.o + gcc curl_test.o -lcurl -o curl_test + +clean: + rm curl_test.o curl_test main.o main loop.o loop 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 diff --git a/loop.asm b/loop.asm new file mode 100644 index 0000000..fd0ee0e --- /dev/null +++ b/loop.asm @@ -0,0 +1,19 @@ +global main + +extern printf + +section .data + msg db "cheese ", 0 + +section .text + +main: + sub rsp, 8 +.print + lea rdi, [rel msg] + call printf wrt ..plt + jmp .print + mov eax, 0 + add rsp, 8 + ret + @@ -1,3 +1,4 @@ +<<<<<<< HEAD global _start section .text @@ -10,3 +11,21 @@ label: cmp ecx, 0 ; compare ecx with 0 jg label ; jump if greater than label +======= +global main + +extern printf + +section .data + msg db "Hello, x86_64 Assembly!", 10, 0 + +section .text + +main: + sub rsp, 8 + lea rdi, [rel msg] + call printf wrt ..plt + mov eax, 0 + add rsp, 8 + ret +>>>>>>> 181d482 (Initial commit (i got too carried away with asm and forgot to commit)) |
