aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-27 02:13:47 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-27 02:13:47 +0200
commit04df2697e1e6e72eeeec298fa5377e494dc98473 (patch)
tree9cc641d6c9a3c4dbd8d44db93f8f54a46bd04e5a
parentRewrite started (diff)
downloadlowbat-bsd-04df2697e1e6e72eeeec298fa5377e494dc98473.tar.gz
lowbat-bsd-04df2697e1e6e72eeeec298fa5377e494dc98473.tar.bz2
lowbat-bsd-04df2697e1e6e72eeeec298fa5377e494dc98473.tar.xz
lowbat-bsd-04df2697e1e6e72eeeec298fa5377e494dc98473.tar.zst
lowbat-bsd-04df2697e1e6e72eeeec298fa5377e494dc98473.zip
First file translated
-rw-r--r--asm/c_args.asm95
1 files changed, 69 insertions, 26 deletions
diff --git a/asm/c_args.asm b/asm/c_args.asm
index dcca5d3..c8178d4 100644
--- a/asm/c_args.asm
+++ b/asm/c_args.asm
@@ -10,38 +10,81 @@
/* */
/* ************************************************************************************ */
-;; jo_c_args(argc: rdi, *argv[]: rsi)
-;; ----------------------------------
-;; returns 0 if args are invalid
-;; returns 1 if args are valid
+/* ******************************* */
+/* c_args(argc: rdi, *argv[]: rsi) */
+/* ------------------------------- */
+/* returns 0 if args are invalid */
+/* returns 1 if args are valid */
+/* ******************************* */
-section .text
- extern strncmp
- global jo_c_args
+.text
+ .extern strncmp
+ .globl c_args
-jo_c_args:
- cmp rdi, 0x2
+c_args:
+ cmp $0x2, %rdi
jle no_args
- mov rax, [rsi + 0x8 * 0x2]
- cmp byte [rax + 0x0], 0x0
+ xorq %rax, %rax
+ pushq %rcx
+ xorq %rcx, %rcx
+ movb $0x8, %cl
+ movq (%rsi, %rcx, 2), %rax
+ cmpb $0x0, (%rax)
je no_args
- push rdi
- mov rdi, [rsi + 0x8 * 0x1]
- push rsi
- mov rsi, reference
- mov rdx, reflen
- call strncmp
- pop rsi
- pop rdi
- cmp rax, 0x0
+ pushq %rdi
+ movq (%rsi, %rcx, 1), %rdi
+ pushq %rsi
+ movq $reference, %rsi
+ pushq %rdx
+ xorq %rdx, %rdx
+ movb $0x6, %dl
+ callq strncmp
+ popq %rdx
+ popq %rsi
+ popq %rdi
+ popq %rcx
+ cmp $0x0, %rax
jne no_args
- mov rax, 0x1
- retq
+ xorq %rax, %rax
+ movb $0x1, %al
+ jmp return
no_args:
- xor rax, rax
+ xorq %rax, %rax
+
+return:
retq
-section .data
- reference: db "--say", 0x0
- reflen: equ $ - reference
+.data
+ reference: .asciz "--say"
+
+/* ;; section .text */
+/* ;; extern strncmp */
+/* ;; global jo_c_args */
+/* */
+/* ;; jo_c_args: */
+/* ;; cmp rdi, 0x2 */
+ /* ;; jle no_args */
+ /* ;; mov rax, [rsi + 0x8 * 0x2] */
+ /* ;; cmp byte [rax + 0x0], 0x0 */
+ /* ;; je no_args */
+ /* ;; push rdi */
+ /* ;; mov rdi, [rsi + 0x8 * 0x1] */
+ /* ;; push rsi */
+ /* ;; mov rsi, reference */
+ /* ;; mov rdx, reflen */
+ /* ;; call strncmp */
+ /* ;; pop rsi */
+ /* ;; pop rdi */
+ /* ;; cmp rax, 0x0 */
+ /* ;; jne no_args */
+ /* ;; mov rax, 0x1 */
+ /* ;; retq */
+/* */
+/* ;; no_args: */
+/* ;; xor rax, rax */
+/* ;; retq */
+/* */
+/* ;; section .data */
+/* ;; reference: db "--say", 0x0 */
+/* ;; reflen: equ $ - reference */