I am trying to reverse a string that I get from a C function using assembly stack.
this is my attempt so far :
section .text
global do_Str
extern printf
do_Str:
push rbp
mov rbp, rsp
mov rcx, rdi
mov r10, 0
mov r9, 0
;mov r11, 0
;mov r13, 0
label:
cmp byte [rcx], 'a'
jl cont
cmp byte[rcx], 'z'
jg cont
and byte [rcx], 11011111b
cont:
cmp byte[rcx], '('
jne contP
mov byte[rcx], '<'
contP:
cmp byte[rcx], ')'
jne contR
mov byte[rcx], '>'
contR:
cmp byte[rcx],'A'
jl contL
cmp byte[rcx], 'Z'
jg contL
inc r9
contL:
inc r10
inc rcx
cmp byte [rcx], 0
jnz label
; mov r11, rdi
; add r11, r10
; dec r11
; _revrse:
; mov r13 , [r11]
; mov r11 , [rdi]
; mov rdi , [r13]
; shr r10, 00000001
; inc rdi
; dec r11
; cmp r11 , rdi
; jne _revse
done:
mov ecx, r10d
mov eax, esp
mov esi, eax ; esi points to start of string
add eax, ecx
mov edi, eax
dec edi ; edi points to end of string
shr ecx, 1 ; ecx is count (length/2)
jz done ; if string is 0 or 1 characters long, done
reverseLoop:
mov al, [esi] ; load characters
mov bl, [edi]
mov [esi], bl ; and swap
mov [edi], al
inc esi ; adjust pointers
dec edi
dec ecx ; and loop
jnz reverseLoop
sub r10, r9
mov rax, r10
mov rsp, rbp
pop rbp
ret
I am not allowed to add more functions. This assembly code does two other things : changes two symbols and counts how many chars are not letters.
I have tried to use rbp and rsi but I get a core dumped error.