From 86860c606fbbcfaf452c85d33f1c737130b0cfe5 Mon Sep 17 00:00:00 2001 From: zombie Date: Tue, 21 Sep 2021 15:35:23 -0400 Subject: [PATCH] added strnum its currently written in zombie proto asm... fix --- CMakeLists.txt | 2 ++ strnum.asm | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 strnum.asm diff --git a/CMakeLists.txt b/CMakeLists.txt index 8702b0a..d7d2a3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,3 +21,5 @@ add_executable(length length.asm) add_executable(yes yes.asm) add_executable(case case.asm) add_executable(diff diff.asm) +add_executable(strnum strnum.asm) + diff --git a/strnum.asm b/strnum.asm new file mode 100644 index 0000000..c634494 --- /dev/null +++ b/strnum.asm @@ -0,0 +1,85 @@ +extern puts + +%include "../inc/length_func.inc" + +section .data + text db "42",0 +section .text + global main + +main: + sub rsp, 8 + + + mov r8, text + call length_func + mov r9, rax + mov r11, r9 + + mov r8, text +_loop: + mov r10b, [r8] + cmp r10b, 0 + jz _exitloop ;if its zero we have reached the end of the string + + + mov r10b, [r8] + sub r10b, 48 ; change "0" into 0 + mov [r8], r10b + + + add r8, 1 + jmp _loop + + + xor rcx, rcx + add rcx, 1 +_exitloop: + cmp r9, r8 + je _addvalues + + + + mov r10b [r9] + mul r10b, rcx + mov [r9], r10b + + sub r9, 1 + mul rcx, 10 + + jmp _exitloop + + add r9, 1 +_addvalues: + cmp r9, r11 + je _end + + + mov r10b, [r8] + mov r11b, [r9] + add r11b, r10b + mov [r9], r11b + + + + add r8, 1 + add r9, 1 + + jmp _addvalues + ;this returns the r8 pointer + + + + ;mov rdi, text + ;cld + ;call puts ;this is the put s way of printing a string + +_end: + add rsp, 8 + ret + +; mov rax, 60 ; exit +; mov edi, 1 ; error 1 dont need the exit anymore beacue libc or somthing +; syscall + +