added strnum
its currently written in zombie proto asm... fix
This commit is contained in:
parent
1ffb79454b
commit
86860c606f
2 changed files with 87 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
|
85
strnum.asm
Normal file
85
strnum.asm
Normal file
|
@ -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
|
||||
|
||||
|
Loading…
Reference in a new issue