I was asking about this yesterday. Had a chance to sit with the professor today and we couldn't figure this out. When running in the debugger, I get the following after calling scanf in read_int_new.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7a6c742 in _IO_vfscanf_internal (s=<optimized out>,
format=<optimized out>, argptr=argptr@entry=0x7fffffffdde0,
errp=errp@entry=0x0) at vfscanf.c:1857
1857 vfscanf.c: No such file or directory.
He says it appears to be set up correctly. I've been stuck on this for a while.
the code:
bits 64
global main
extern puts
extern printf
extern scanf
extern get_kb
section.data
errormsg: db 'Invalid Input. Enter N,F, or X',0x0D,0x0a,0
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
enterintmsg: db "Enter and integer 0-20: ",0
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,0
value: dq 0
.code
main:
menu:
;print menu
mov edi, menuprompt
call puts ;display menu
mov edi,choicemsg
;mov eax, 0
;call printf ;display "Your choice:"
call puts
call get_kb
mov bl, al
cmp bl, 'N' ;N
je read_int_new
cmp bl, 'F' ;F
je fib
cmp bl, 'X' ;X
je correct
;else
jmp menu
;print success!! for debugging purposes
correct:
mov edi, LC9
mov eax,0
call printf
jmp menu
entered_n:
call read_int_new
jmp menu
read_int_new:
mov edi, enterintmsg ;display "Enter an integer 0-20: "
mov eax, 0
call printf
;lea rax, [value]
;mov rsi, rax
;mov rax, value
;mov rdi, LC5
;mov eax, 0
;call scanf ;get user input
mov rdi, LC5
;lea rsi, [value]
mov rax, [value]
;mov eax,0
call scanf
;ERROR OCCURS HERE!!!!!!!!!!!!!!!!!!!
mov edi, LC9 ;test to see if it got here
mov eax, 0
call printf
;test ebx, ebx ;compare to 0 (eax-eax=0)
;js L9
;mov edi, LC9 ;test to see if it got here
;mov eax, 0
;call printf
;mov ebx, DWORD [rbp-4]
;cmp ebx, 20 ;jump if greater than 20
;jg L9
;mov edi, LC9 ;test to see if it got here
;mov eax, 0
;call printf
;mov ebx, DWORD [rbp-4] ;else, jump to L10
;mov edi, LC9 ;test to see if it got here
;mov eax, 0
;call printf
;jmp L10
;leave
;ret
jmp menu
fib:
;mov esi, [value]
mov edi, LC9
mov eax,0
;mov eax, LC5
;push [eax]
;push value
;push LC5
call printf
jmp menu