The problem I am facing right now is reversing my stack.
I was able to change symbols that I wanted but I'm stuck on reversing my stack.
This is my code so far:
section .text
global do_Str
extern printf
do_Str:
push rbp
mov rbp, rsp
mov rcx, rdi
mov rbx, rdi
mov rdx, rcx
mov r10, 0
mov r9, 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:
_push_loop:
mov al,[rdx]
cmp al, 0
jz _pop_loop
push ax
inc rdx
jmp _push_loop
_pop_loop:
mov al,[rbx]
cmp al,0
jz _done
pop ax
mov [rdx], al
inc rbx
jmp _push_loop
_done:
inc r10
inc rcx
cmp byte [rcx], 0
jnz label
sub r10, r9
mov rax, r10
mov rsp, rbp
pop rbp
ret
I have tried changing my registers and pointers use but all of them resulted to the same error:
Segmentation fault (core dumped)
I am not allowed to create a new function in my C file
This is my C code :
#include <stdio.h>
#define MAX_LEN 100
extern int do_Str (char*);
int main(void){
char str_Buf[MAX_LEN];
int counter = 0;
fgets(str_Buf,MAX_LEN, stdin);
counter = do_Str (str_Buf);
printf("%s%d\n",str_Buf,counter);
return 0;
}
I have searched it on Stack Overflow and didn't find a solution for my problem.
The full assignment was : 1. change lower case letters to uppercase from the input 2. count how many chars are not letters 3.reverse the input - I am stuck here and I think I don’t fully realize the flow of the stack.