86 lines
968 B
NASM
86 lines
968 B
NASM
|
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
|
||
|
|
||
|
|