in following, i'm trying user's choice , use call other functions. i'm pushing choice onto stack, pushing format line, calling scanf, can't seem able use entered.
;nasm -f elf64 fib.asm -o fib.o ;gcc -s -masm=intel fib.c -o fib.s ;./fib bits 64 global main extern puts extern printf extern scanf 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 enter integer 0 20',0x0d,0x0a,'enter f display first n+1 numbers (beginning zero) on console',0x0d,0x0a,'enter x quit program',0x0d,0x0a,0 choicemsg: db "your choice: ",0 lc5: db "%s",0 enterintmsg: db "enter , integer 0-20: ",0 enternummsg: db 'enter valid number between 0 , 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 0 section',0x0d, value: dw 0 choice: dw 0 .code main: menu: push rbp mov rbp, rsp sub rsp, 16 mov edi, menuprompt call puts ;display menu mov edi,choicemsg mov eax, 0 call printf ;display "your choice: " ;call getn push choice push lc5 ;string format call scanf ;stores input in choice ;getlint [choice] mov ebx, choice cmp ebx, 78 je correct correct: mov edi, ebx mov eax,0 call printf
you using wrong convention. know should do, since had no problem calling printf. should use same convention calling scanf - stack argument passing used 32 bit convention, 64 bit uses registers. this:
lea rdi, [lc5] ; 1st arg = format lea rsi, [choice] ; 2nd arg = address of buffer xor eax, eax ; no xmm registers call scanf ; stores input in choice by way, using unconstrained %s 2 bytes of space bad idea.
also, frank said, ie. load byte (mov bl, [choice]) when want process input.
Comments
Post a Comment