did some things idk
This commit is contained in:
parent
d0cbf26c4a
commit
e1c8d1f740
5 changed files with 124 additions and 19 deletions
|
@ -21,4 +21,4 @@ add_executable(length length.asm)
|
|||
add_executable(yes yes.asm)
|
||||
add_executable(case case.asm)
|
||||
add_executable(diff diff.asm)
|
||||
add_executable(3x+1 3x+1.asm)
|
||||
#add_executable(3x+1 3x+1.asm)
|
||||
|
|
82
inc/atoi_func.inc
Normal file
82
inc/atoi_func.inc
Normal file
|
@ -0,0 +1,82 @@
|
|||
%include "../inc/length_func.inc"
|
||||
atoi_func:
|
||||
|
||||
mov r8, rdi
|
||||
|
||||
|
||||
|
||||
mov r8, text ;loop setup
|
||||
|
||||
xor r9, r9
|
||||
|
||||
_loopasd23:
|
||||
|
||||
mov r9b, [r8]
|
||||
|
||||
cmp r9, 0 ;check and see if we have reached the end of the string
|
||||
jz _exitloopasd12
|
||||
|
||||
sub r9, 48
|
||||
|
||||
mov [r8], r9b
|
||||
inc r8
|
||||
jmp _loopasd23
|
||||
|
||||
_exitloopasd12:
|
||||
|
||||
|
||||
|
||||
call length_func
|
||||
mov r8, rax
|
||||
mov r11, rax
|
||||
|
||||
add r8, rdi
|
||||
|
||||
|
||||
mov rcx, 1
|
||||
_loop2asd12:
|
||||
dec r8
|
||||
mov al, [r8]
|
||||
|
||||
|
||||
mul rcx
|
||||
mov [r8], al
|
||||
|
||||
|
||||
mov rax, rcx
|
||||
mov r10, 10
|
||||
mul r10
|
||||
mov rcx, rax
|
||||
|
||||
cmp r8, rdi
|
||||
je _exitloop2asd12
|
||||
jmp _loop2asd12
|
||||
_exitloop2asd12:
|
||||
|
||||
mov r8, rdi
|
||||
mov r9, rdi
|
||||
inc r9
|
||||
|
||||
_loop3asd12:
|
||||
|
||||
mov r11b, [r9]
|
||||
mov r10b, [r8]
|
||||
cmp r11, 0
|
||||
jz _endasdasd23123
|
||||
|
||||
add r11, r10
|
||||
|
||||
mov [r9], r11b
|
||||
mov [r8], r10b
|
||||
|
||||
|
||||
inc r8
|
||||
inc r9
|
||||
|
||||
jmp _loop3asd12
|
||||
|
||||
|
||||
_endasdasd23123:
|
||||
mov rax, [r8]
|
||||
ret
|
||||
|
|
@ -2,10 +2,11 @@
|
|||
length_func:
|
||||
|
||||
mov r10, rdi
|
||||
xor r9, r9
|
||||
_loop67865432:
|
||||
|
||||
mov r9b, [rdi]
|
||||
cmp r9b, 0
|
||||
mov r9, [rdi]
|
||||
cmp r9, 0
|
||||
jz _exitloop4323567
|
||||
inc rdi
|
||||
|
||||
|
|
|
@ -1,17 +1,28 @@
|
|||
extern puts
|
||||
|
||||
%include "../inc/atoi_func.inc"
|
||||
|
||||
section .data
|
||||
text db "Number reaches 1",0
|
||||
even db "even",0
|
||||
odd db "odd",0
|
||||
number dq 7
|
||||
number db "42",0
|
||||
tempstore db 0
|
||||
section .text
|
||||
global main
|
||||
|
||||
main:
|
||||
sub rsp, 8
|
||||
|
||||
mov r8, [number]
|
||||
add rsi, 8
|
||||
mov r8, [rsi]
|
||||
mov r9, [r8]
|
||||
mov [tempstore], r9
|
||||
|
||||
mov rdi, number
|
||||
call atoi_func
|
||||
mov r8, rax
|
||||
|
||||
_loop:
|
||||
cmp r8, 1 ;if number is 1 then end
|
||||
je _printstupid
|
|
@ -11,21 +11,24 @@ main:
|
|||
sub rsp, 8
|
||||
|
||||
|
||||
mov r8, text
|
||||
mov rdi, text
|
||||
call length_func
|
||||
mov r9, rax
|
||||
mov r11, r9
|
||||
|
||||
mov r8, text
|
||||
|
||||
xor r10, r10
|
||||
xor r11, r11
|
||||
_loop:
|
||||
mov r10b, [r8]
|
||||
cmp r10b, 0
|
||||
mov r10, [r8]
|
||||
cmp r10, 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
|
||||
mov r10, [r8]
|
||||
sub r10, 48 ; change "0" into 0
|
||||
mov [r8], r10
|
||||
|
||||
|
||||
add r8, 1
|
||||
|
@ -40,13 +43,21 @@ _exitloop:
|
|||
|
||||
|
||||
|
||||
mov r10b [r9]
|
||||
mul r10b, rcx
|
||||
mov [r9], r10b
|
||||
mov r10, r9
|
||||
|
||||
mov rax, r10
|
||||
mul rcx
|
||||
mov r10, rax
|
||||
|
||||
mov [r9], r10
|
||||
|
||||
sub r9, 1
|
||||
mul rcx, 10
|
||||
|
||||
mov rdi, 10
|
||||
mov rax, rcx
|
||||
mul rdi
|
||||
mov rcx, rax
|
||||
|
||||
jmp _exitloop
|
||||
|
||||
add r9, 1
|
||||
|
@ -55,10 +66,10 @@ _addvalues:
|
|||
je _end
|
||||
|
||||
|
||||
mov r10b, [r8]
|
||||
mov r11b, [r9]
|
||||
add r11b, r10b
|
||||
mov [r9], r11b
|
||||
mov r10, [r8]
|
||||
mov r11, [r9]
|
||||
add r11, r10
|
||||
mov [r9], r11
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue