From 96caf953fb9d851b2f949fcd52dd7194ee6b1bb2 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 17 Apr 2020 19:35:12 +0200 Subject: On the way, solved segv --- asm/jo_c_args.asm | 16 +++++++++++----- asm/jo_r_loop.asm | 10 ++++++++++ asm/jo_r_lowbat.asm | 22 ++-------------------- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/asm/jo_c_args.asm b/asm/jo_c_args.asm index c18fbf7..8c91e57 100644 --- a/asm/jo_c_args.asm +++ b/asm/jo_c_args.asm @@ -10,24 +10,30 @@ ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; returns 0 if args are invalid +;; returns 1 if args are valid + section .text extern strncmp global jo_c_args -jo_c_args: ; jo_c_args(argc: rdi, *argv[]: rdi) +jo_c_args: ; jo_c_args(argc: rdi, *argv[]: rsi) cmp rdi, 0x2 jle no_args + mov rax, [rsi + 0x8 * 0x2] + cmp byte [rax + 0x0], 0x0 + je no_args push rdi - mov rdi, [rsi + 8 * 1] + mov rdi, [rsi + 0x8 * 0x1] push rsi mov rsi, reference - mov rdx, len + mov rdx, reflen call strncmp pop rsi pop rdi cmp rax, 0x0 jne no_args - mov rax, [rsi + 8 * 2] + mov rax, 0x1 retq no_args: @@ -36,4 +42,4 @@ no_args: section .data reference: db "--say", 0x0 - len: equ $ - reference ; reference len + reflen: equ $ - reference ; reference len diff --git a/asm/jo_r_loop.asm b/asm/jo_r_loop.asm index 02753f5..736b3a6 100644 --- a/asm/jo_r_loop.asm +++ b/asm/jo_r_loop.asm @@ -11,7 +11,17 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; section .text + extern jo_n_speak global jo_r_loop jo_r_loop: + cmp rdi, 0x1 + je speak1 + +next: retq + +speak1: + mov rdi, [rsi + 8 * 2] + call jo_n_speak + jmp next diff --git a/asm/jo_r_lowbat.asm b/asm/jo_r_lowbat.asm index 6fadc86..53d56fa 100644 --- a/asm/jo_r_lowbat.asm +++ b/asm/jo_r_lowbat.asm @@ -18,30 +18,12 @@ ;; c: check section .text - extern puts - ;; extern stoa extern jo_c_args extern jo_r_loop global jo_r_lowbat jo_r_lowbat: - ;; call stoa - push rdi + call jo_c_args mov rdi, rax - call puts - pop rdi + call jo_r_loop ; jo_r_loop(speak: 0-1, *argv[]) retq - -;; call jo_c_args -;; mov bl, byte [rax + 0x0] -;; cmp bl, 0x0 -;; jne joprint -;; call jo_r_loop ; jo_r_loop(speak: 0-1, *argv[]) -;; xor rax, rax -;; retq - -;; joprint: -;; push rdi -;; mov rdi, rax -;; call puts -;; pop rdi -- cgit v1.2.3