flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > Collecting console user input

Author
Thread Post new topic Reply to topic
Mondragon



Joined: 02 Jul 2017
Posts: 2

Collecting console user input

Hi all, I'm new here and to fasm. Can someone let me know what I'm doing wrong here? Note that I actually am trying to do this with no direct WinAPI calls, but I wanted to try and use ExitProcess to also test that I can invoke Win API functions too in the same file. However, I am getting that ExitProcess doesn't exist which I find strange because it appears that I've properly imported it, no? Also, just FYI - I've confirmed that the Windows header files are working because I've included this exact file and also used ExitProcess in another program. Thanks.

Code:

format pe console
include 'WIN32AX.INC'
include 'macro/import32.inc'

 
section ".data" data readable writeable
        bufsize = 4
        byteswritten dd ?
        buff dd ?
section ".code" code readable executable
main:

       invoke  scanf"%s",buff
       invoke printfbuff,0
       invoke  ExitProcess,0


section '.idata' import data readable
library msvcrt,'msvcrt.dll'kernel32'KERNEL32.DLL'
import msvcrt,\                         ;from that specified library Notice how msvcrt is used to reference the previous declared library msvcrt as .dll
printf,'printf',\
scanf'scanf'
import KERNEL32,\
ExitProcess'ExitProcess'

[/code]

_________________
-Mondragon
Post 02 Jul 2017, 06:51
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671

'KERNEL32.DLL' should be 'kernel32.dll'. Use lowe-case.
Post 02 Jul 2017, 07:25
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 901

'KERNEL32.DLL' is perfectly fine as Windows is case insensitive.

What's wrong is

Code:
import KERNEL32

that one should be lowercase, because that's an internal token used by FASM, not a string used by Windows. And FASM is case sensitive.
Post 02 Jul 2017, 10:47
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 680
Location: Adelaide

I think using C calling convention needs cinvoke rather than invoke as well.
Post 02 Jul 2017, 11:09
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1211
Location: Greece

also, reserve some local memory for the buffer.


Code:
 buff db 256 dup ?

Post 02 Jul 2017, 11:30
View user's profile Send private message Reply with quote
Mondragon



Joined: 02 Jul 2017
Posts: 2

Thanks

You guys are heroes. I think I've got enough to just go down the fasm docs and hopefully figure some more out.

ASM is definitely something else, but it's so much fun!

By the way, is using C funcs or API calls like this the way most assembly programmers would handle this sort of thing or is there a better way?
Post 04 Jul 2017, 08:28
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 671

For new ASM programmers, access to APIs or 3rd party libraries is required as a tool of proofs only. C funcs are not requirement but to see what you've done to the registers, you need something like "printf" to confirm the effects of instructions that you composing. Some people prefer the debuggers.

My personal opinion is that ASM is best used if you want to talk to / interface the CPU directly albeit the noises coming from the OS's 'protectionism', calling conventions and other high-level stuff that have nothing to do with the instructions and the real CPU works. I'll leave that to high-level languages if I want to make 'apps' and projects.

ASM is something different, requires different set of thinking, skills and approach. You'll understand HLL much much better if you see it from ASM point of view. ASM builds strong characters Very Happy. FASM's own design is reflecting that exactly. But be warned, FASM board is extremely low-level (as in machine) and comes with colorful languages, too!

Keep practicing, young padawan and welcome aboard Very Happy
Post 04 Jul 2017, 10:43
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 901


system error wrote:
You'll understand HLL much much better if you see it from ASM point of view.

I agree. In fact, I've only really understood pointers in C(++) after learning basic asm. Mind you, this is because when I started to seriously "learn" programming, I started with HLL books of course (I think I was 10 or so). And guess what? HLL books are full of bullshit analogies to describe pointers (as a child of course, you think of it that way must be true).

It sickens me to see HLL advocates teach "newbies" abstractions and all sorts of this kind of bullshit, no wonder so many people cannot understand pointers or find them "complicated" to use and prefer to "abstract" them away with crappy classes in C++. It's not even about asm vs HLL, but about the mindset.

The flat memory model (what pointers are in C/C++) is really simple by itself, and since everyone is taught arrays before pointers, it is even easier to understand. But of course, this is why HLL morons suck at teaching anything. Instead of "keeping it simple" they start with bullshit like phone addresses or other crap! WTF just tell them it's a fucking number in a RAM array.

Oh I forgot some people think that not teaching about bits to new programmers is a "good" way of teaching, because bit manipulations are placed at the end (building blocks of everything) of the course cause they're "omg complex for newbies". Pathetic to me.
Post 04 Jul 2017, 11:43
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2017, Tomasz Grysztar.