0

I have this code that I am trying to get a message from the user and then display. I am getting segmentation fault right now. I am not sure what is happening. Also when it prompts to get the message it keeps waiting for a second line.

extern printf, scanf    

global _start

section .data

format db '%d',0    
format2 db "%s",10,"%s",10,"%s",10,"%s",10,0
format3 db "%s ",0  

message0:     db "Menu",10,0      
message1:     db "1. Input New Message",10,0        
message2:     db "2. Shift Encrypt",10,0 
message3:     db "3. Display Unencrypted Message",10,0         
message4:     db "4. Quit",10,0 
message5:     db "Enter a number(1-4):",10,0 


section .bss
getMessage: resq 1
choice      resq 1

len:  equ  $ - getMessage

section .text
        global  main


main:   
    
    mov rsi, message0
    call messages

    call menu

    mov rsi, message5
    call messages
    
    call scanChoice

    mov rsi, message1
        call messages

    call scanMessage

    mov rsi, getMessage
        call messages
    ret

; end main


scanChoice:         ;getting the year from user
   mov rdi, format
        mov rsi, choice        
        mov rax, 0      ;no xmm registers 
        call scanf      ;calling c function to get input from user
    ret

scanMessage:                     ;getting the year from user                                                                                                                                                 
   mov rdi, format3
        mov rsi, getMessage
        mov rax, 0              ;no xmm registers                                                                                                                                                           
        call scanf              ;calling c function to get input from user                                                                                                                                  
        ret

    
menu:       ;showing message if is a leap year
    mov rdi,format2 ;first argument                                                                      
        mov rsi,message1  ;second argument                                                                      
        mov rdx, message2 ;third argument                                                                    
        mov rcx, message3    ;fourth argument
        mov r8, message4     ;fifth argument
        mov rax,0
        call printf     ;call the C function                                                                
    ret

messages
    mov rdi,format3
    mov rdx,rsi
    mov rax,0
    call printf
    ret


What is showing:

Menu

  1. Input New Message

  2. Shift Encrypt

  3. Display Unencrypted Message

  4. Quit

Enter a number(1-4): 2

  1. Input New Message hey need to type something again Segmentation fault (core dumped)
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
prxx20
  • 39
  • 5
  • 1
    You need to reserve more space for `getMessage`. – Michael May 04 '21 at 19:18
  • @prxx20 - Sorry your [other question](https://stackoverflow.com/questions/67393805/) was unceremoniously closed. Q: What platform are you running on? Windows? Linux? Other? Q: What C compiler do you use? – paulsm4 May 05 '21 at 15:45
  • @paulsm4 I am running on linux. I will try to post again with the error that I am getting. – prxx20 May 05 '21 at 18:58
  • And you're using GCC (for C) and nasm (for assembly), correct? And yes, please: *ALWAYS* copy/paste the exact error message whenever you post a question :) – paulsm4 May 05 '21 at 21:32

0 Answers0