» »

[Assembler] scanf How-To

[Assembler] scanf How-To

c0dehunter ::

Zdravo, zanima me kako uporabiti scanf funkcijo za branje v zbirniku?
Po moji logiki bi moral ukaz call scanf shraniti prebrano vrednost na akumulator, ampak očitno ne gre tak. Google (oz. zadetki) so glede problema zelo skopi.

Trenutno imam tak:
; osnovne nastavitve 
bits 32
extern _scanf 
extern _printf
global _main

section .data
	sporocilo db "Vnesi stevilo: ",10,0
	
; program
section .text
_main:
	pushad       ;shranimo vsebine registrov na sklad
	push sporocilo
	call _printf ;DELUJE, IZPISE SPOROCILO IN PROGRAM SE ZAKLJUCI, NE PREBERE NIC VEC
	add esp, 4
	call _scanf  ;
	call _printf
	popad
	ret
I do not agree with what you have to say,
but I'll defend to the death your right to say it.

fiction ::

Na akumulator?! EAX register tukaj ne igra nobene vloge.

Pri scanf bi pričakoval vsaj še kakšen "%s" format string. V stilu "push naslov" (oz. najbrz lahko kar "push sporocilo"), "push formatstr", "call _scanf", "add esp, 8". Oz glede na to, da hočeš tisto kar je bilo prebrano takoj spet izpisati najbrž lahko narediš kar brez tega in direktno pokličeš printf s "%s" in naslov.

Če daš "add esp, 4" in pokličeš le printf s sporočilom od uporabnika si ranljiv na format string napade. Druga stvar je pa preveč vpisanih znakov pri scanf (buffer overflow), ampak to lahko rešiš npr. z uporabo "%10s".

Zgodovina sprememb…

  • spremenil: fiction ()

whatever ::

Mislim, da scanf shrani v EBX.

http://www.drpaulcarter.com/pcasm/pcasm...

Tu not ti piše, nekje okrog 300. strani tam nek.
Veliko jih je notri, še več jih je pa zunaj.
Bilijarde v šole! - Ivan Kramberger
Abnormal behaviour of abnormal brain makes me normal.

Zgodovina sprememb…

  • spremenilo: whatever ()

whatever ::

One great advantage of interfacing C and assembly is that allows as-
sembly code to access the large C library and user-written functions. For
example, what if one wanted to call the scanf function to read in an integer
from the keyboard? Figure 4.14 shows code to do this. One very important
point to remember is that scanf follows the C calling standard to the letter.
This means that it preserves the values of the EBX, ESI and EDI registers;
however, the EAX, ECX and EDX registers may be modified! In fact, EAX
will definitely be changed, as it will contain the return value of the scanf
call. For other examples of using interfacing with C, look at the code in
asm io.asm which was used to create asm io.obj.


Torej v EAX shrani.
Veliko jih je notri, še več jih je pa zunaj.
Bilijarde v šole! - Ivan Kramberger
Abnormal behaviour of abnormal brain makes me normal.

Zgodovina sprememb…

  • spremenilo: whatever ()

whatever ::

http://forum.feri.uni-mb.si/Default.asp...

Na teh linkih imaš dovolj materiala. Jaz sem ven iz tega že 5 let, ampak vem, da sem imel isti problem kot ti in še kdo in mi je ta quote iz te knjige pomagal. BTW, takrat sem prebral celo.
Veliko jih je notri, še več jih je pa zunaj.
Bilijarde v šole! - Ivan Kramberger
Abnormal behaviour of abnormal brain makes me normal.

Zgodovina sprememb…

  • spremenilo: whatever ()

fiction ::

whatever je izjavil:

One great advantage of interfacing C and assembly is that allows as-
sembly code to access the large C library and user-written functions. For
example, what if one wanted to call the scanf function to read in an integer
from the keyboard? Figure 4.14 shows code to do this. One very important
point to remember is that scanf follows the C calling standard to the letter.
This means that it preserves the values of the EBX, ESI and EDI registers;
however, the EAX, ECX and EDX registers may be modified! In fact, EAX
will definitely be changed, as it will contain the return value of the scanf
call. For other examples of using interfacing with C, look at the code in
asm io.asm which was used to create asm io.obj.


Torej v EAX shrani.
Ok to že - EAX je ponavadi za return value, odvisno od načina klica. Se popravljam, ni tako da EAX ne bi igral nobene vloge. Samo kaj shrani tja scanf()...

Return Value
On success, the function returns the number of items succesfully read. This count can match the expected number of readings or fewer, even zero, if a matching failure happens.
In the case of an input failure before any data could be successfully read, EOF is returned.

To pa najbrž ni tisto, kar te zanima.

c0dehunter ::

Aha, bom pregledal podano snov in se oglasil nazaj, ko predelam.. Lp
I do not agree with what you have to say,
but I'll defend to the death your right to say it.


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

C programiranje (strani: 1 2 3 )

Oddelek: Programiranje
14127717 (18013) amacar
»

[ASM] Pomoč, ne najdem napake

Oddelek: Programiranje
51094 (970) c0dehunter
»

asm - vnos stevilk s tipkovnice

Oddelek: Programiranje
51276 (1132) scarymovie
»

[nasm] scanf

Oddelek: Programiranje
272894 (2621) Brane2
»

[NALOGA][NASM] problem pri povezovanju s C-jevskimi funkcijami

Oddelek: Programiranje
61379 (1237) c00L3r

Več podobnih tem