G
G
Grandma Luda2022-03-07 22:00:10
assembler
Grandma Luda, 2022-03-07 22:00:10

Why does scanf not work correctly in FASM?

The scanf function crashes the program

format PE console

entry start

include 'win32a.inc'

section '.code' code readable executable
        strC db 'Col-vo numder: ', 0
        strN db 'Number: ', 0

        colvo db ' %d', 0
        number db '%d', 0

        numderA rd 1

section '.data' code readable writable
        start:
                push strC
                call [printf]

                push numderA
                push colvo
                call [scanf]

                push numderA
                call [printf]

                call [getch]
                call [ExitProcess]



section '.idata' import data readable
        library kernel , 'kernel32.dll',\
                msvcrt, 'msvcrt.dll'

        import kernel,\
                ExitProcess, 'ExitProcess'

        import msvcrt,\
               printf, 'printf',\
               getch, '_getch',\
               scanf, 'scanf'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2022-03-07
@KirasiH

The scanf function crashes the program

Most likely you are mistaken, and this is what "destroys the program":
push numderA
call [printf]

printf expects a format string as its first parameter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question