Compare commits

..

No commits in common. "b5946dc3386243c8192d123eb28b1270d47b6bdb" and "e6d0d6aebcb11d87b1a343f530a83190f39a787f" have entirely different histories.

5 changed files with 15 additions and 198 deletions

View file

@ -22,6 +22,7 @@ add_executable(length length.asm)
add_executable(yes yes.asm) add_executable(yes yes.asm)
add_executable(case case.asm) add_executable(case case.asm)
add_executable(diff diff.asm) add_executable(diff diff.asm)
# add_executable(arg arg.asm)
target_link_libraries(length z) target_link_libraries(length z)
target_link_libraries(case z) target_link_libraries(case z)

View file

@ -1,82 +0,0 @@
%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

View file

@ -1,18 +0,0 @@
length_func:
mov r10, rdi
xor r9, r9
_loop67865432:
mov r9, [rdi]
cmp r9, 0
jz _exitloop4323567
inc rdi
jmp _loop67865432
_exitloop4323567:
sub rdi, r10
mov rax, rdi
ret

View file

@ -1,73 +0,0 @@
extern puts
%include "../inc/atoi_func.inc"
section .data
text db "Number reaches 1",0
even db "even",0
odd db "odd",0
number db "42",0
tempstore db 0
section .text
global main
main:
sub rsp, 8
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
test r8, 1 ;odd even check
jnz _odd
jz _even
_odd:
; mov rdi, odd
; cld
; call puts
mov rax, r8 ; gotta do this because mul only takes one argument
mov r9, 3
mul r9
add rax, 1
mov r8, rax
jmp _loop
_even:
; mov rdi, even
; cld
; call puts
xor rdx, rdx
mov rax, r8
mov rcx, 2
div rcx
mov r8, rax
jmp _loop
_printstupid:
mov rdi, text
cld
call puts ;this is the put s way of printing a string
_end:
add rsp, 8
ret

View file

@ -11,24 +11,21 @@ main:
sub rsp, 8 sub rsp, 8
mov rdi, text mov r8, text
call length_func call length_func
mov r9, rax mov r9, rax
mov r11, r9 mov r11, r9
mov r8, text mov r8, text
xor r10, r10
xor r11, r11
_loop: _loop:
mov r10, [r8] mov r10b, [r8]
cmp r10, 0 cmp r10b, 0
jz _exitloop ;if its zero we have reached the end of the string jz _exitloop ;if its zero we have reached the end of the string
mov r10, [r8] mov r10b, [r8]
sub r10, 48 ; change "0" into 0 sub r10b, 48 ; change "0" into 0
mov [r8], r10 mov [r8], r10b
add r8, 1 add r8, 1
@ -43,21 +40,13 @@ _exitloop:
mov r10, r9 mov r10b [r9]
mul r10b, rcx
mov rax, r10 mov [r9], r10b
mul rcx
mov r10, rax
mov [r9], r10
sub r9, 1 sub r9, 1
mul rcx, 10
mov rdi, 10
mov rax, rcx
mul rdi
mov rcx, rax
jmp _exitloop jmp _exitloop
add r9, 1 add r9, 1
@ -66,10 +55,10 @@ _addvalues:
je _end je _end
mov r10, [r8] mov r10b, [r8]
mov r11, [r9] mov r11b, [r9]
add r11, r10 add r11b, r10b
mov [r9], r11 mov [r9], r11b