Q: How to properly return to the main function after calling a function? I'm trying to get the following to jump back to main, which prints a menu. 
In another function (that works correctly) I used the jmp main command. However, that function only prints a message indicating that it got to that function before printing the menu again. 
If I use just one of the last three lines, I get a seg fault error. Same if I use leave and return together. I'm assuming it has something to do with calling scanf. 
read_int:
    mov    edi, enterintmsg
    mov    eax,0
    call   printf           
    lea    rdi, [LC5]
    lea    rsi, [value]
    xor    eax,eax
    call   scanf
    mov    cl, [value]
    jmp    main
    ;leave
    ;ret    

Current code:
bits 64
global  main
    extern  puts
extern  printf
extern  scanf   
extern  get_kb



section.data
 ;LC0
errormsg:   db  'Invalid Input. Enter N,F, or X',0x0D,0x0a,0

;LC1
numequalsmsg:   db  'Number equals: '

LC2:    db  "%d",0


menuprompt: db  0x0D,0x0a,'Enter N to enter an integer from 0 to 20',0x0D,0x0a,'Enter F to display the first N+1 numbers (beginning with zero) on the console',0x0D,0x0a,'Enter X to quit the program',0x0D,0x0a,0


choicemsg:  db  "Your Choice: ",0

LC5:    db  "%d",0

;LC6
enterintmsg:    db  "Enter and integer 0-20: ",0

;LC7
enternummsg:    db  'Enter a valid number between 0 and 20',0x0D,0x0a,0


LC8:    db  " , ",0
LC9:    db  'Success!',0x0D,0x0a,0
LC10:   db  'In L10!',0x0D,0x0a,0       
LC11:   db  'In L12!',0x0D,0x0a,0 
LC13:   db  'In compare to zero section',0x0D, 
value:  db  0
choice: db  1


.code
main:
    ;function setup 
    push    rbp
    mov rbp, rsp
    sub rsp, 16

menu:
    ;print menu 
    mov edi, menuprompt
    call    puts            ;display menu
    mov edi,choicemsg
    ;mov    eax, 0
    ;call   printf          ;display "Your choice:" 
    call puts
    ;call   getn    
    ;push choice
    ;push LC5       ;string format
    ;call scanf     ;stores input in choice
    ;GetLInt     [choice]
    ;mov    ebx, choice
    ;lea    rdi, [LC5]
    ;lea    rsi, [choice]
    ;xor    eax,eax
    ;call scanf
    ;mov    bl, [choice]
    call    get_kb
    mov bl, al
    cmp bl, 'N' ;N
    je  entered_n
    cmp bl, 'F' ;F
    je  correct
    cmp bl, 'X' ;X
    je  correct
    ;leave
    ;ret

    jmp menu
    ;ret

correct:
    mov edi, LC9
    mov eax,0
    call    printf
    jmp     menu
    ;leave  
    ;ret 

entered_n:
    call    read_int
    ;jmp    menu
    ;leave
    jmp menu

read_int:
    mov edi, enterintmsg
    mov eax,0
    call    printf          

    lea rdi, [LC5]
    lea rsi, [value]
    xor eax,eax

    ;add    esp,4       ;remove parameters
    push    rsi
    push    rdi 
    call scanf
    mov cl, [value]
    ;jmp    menu
    ;leave
    ret


     ;leave 


A: To return a function you need to use the RET instruction. For the RET instruction to work the the return address, the location the instruction should jump to, needs to be at the top of the stack. Normally this return address is pushed on the stack by the CALL instruction, however you didn't use the CALL instruction to call the function. Instead you used JE read_int. This means your function has no idea where it was called from and so a RET instruction can't resume executing the previous function where it left off.
The solution is to change the code that calls read_int to something like this:
     cmp bl, 'N'
     jne not_n

     call read_int
     ; read_int returns here so put whatever code 
     ; that needs to be executed afterwards here

not_n:
     ; code handling the case when BL != 'N'

You can then change read_int to use RET, and only RET, to return from the function.
Using JMP main to return the main function doesn't work, because it does exactly what it says it does. It jumps to the address of main which is the first instruction in of the main function. This causes your main function to be executed again from the start.
You don't want to use the LEAVE instruction unless you set up a stack frame. Your read_int function doesn't set up stack frame, so using it will likely causes your code to crash.
