News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Console l/O in masm32

Started by Ravi Kiran, October 11, 2020, 09:38:27 PM

Previous topic - Next topic

Ravi Kiran

Anybody Please tell me how to pass strings and register values to
Win32 console just like formatted printf and scanf functions defined in C standard library. All I know about is to print a string located at particular address using



  mystring dB "Hello World",0

  INVOKE stdout addr mystring ;


statement in masm32. Also plz explain me how to accept strings   
and integer values from user input just like scanf function in C.

To be clear are there any functions in masm32 SDK which work exactly like printf and scanf in C. If so how are they defined. It may sound silly to many senior members of this forum but Im interested to know the assembly version of these functions.

Mikl__

Hi, Ravi Kiran!
Will look Examples for Win64 Iczelion tutorial
  • Win x64 Tutorial #38: Simple console application
  • Win x64 Tutorial #38a: Input and output of line of symbols in console application
  • Win x64 Tutorial #38b: Installation of color of symbols and background of the text of the  console application
  • Win x64 Tutorial #38c: Processing of mouse messages
  • Win x64 Tutorial #38d: Installation of color of symbols and background of the text of the  console application (yet another variant)
  • Win x64 Tutorial #38e: Simple  console application (yet another variant)
  • etc.

Ravi Kiran

Quote from: Mikl__ on October 11, 2020, 09:57:08 PM
Hi, Ravi Kiran!
Will see Examples for Win64 Iczelion tutorial
  • Win x64 Tutorial #38: Simple console application
  • Win x64 Tutorial #38a: Input and output of line of symbols in console application
  • Win x64 Tutorial #38b: Installation of color of symbols and background of the text of the  console application
  • Win x64 Tutorial #38c: Processing of mouse messages
  • Win x64 Tutorial #38d: Installation of color of symbols and background of the text of the  console application (yet another variant)
  • Win x64 Tutorial #38e: Simple  console application (yet another variant)
  • etc.
Sir I'm beginning 32-bit MASM Assembly and I'm very far from learning x64 Assembly. Let me learn this x86 assembly first then after
a long time we can think of x64. Please help me with x86 assembly examples

Mikl__

Just look at the program text, it is also suitable for 32-bit programming

Vortex

Hi Ravi,

Here is an example :

include     \masm32\include\masm32rt.inc

.data

str1        db 'What is your name?',13,10,0
str2        db '%s',0
str3        db 13,10,'Hello %s , nice to meet you.',0

.data?

buffer      db 64 dup(?)

.code

start:

    invoke  crt_printf,ADDR str1
    invoke  crt_scanf,ADDR str2,ADDR buffer
    invoke  crt_printf,ADDR str3,ADDR buffer
    invoke  ExitProcess,0

END start

jj2007

Vortex already gave you a good example, here is another one:
include \masm32\include\masm32rt.inc

.data
HelloW$ db "Hello World", 0
buffer db 1000 dup(?)
myInteger dd ?
myDouble REAL8 ?
.code
start:
  cls
  print addr HelloW$, 13, 10 ; CrLf
  print "type any text: "
  invoke crt_scanf, chr$("%s"), addr buffer
  print "this is what you typed: "
  print addr buffer, 13, 10
  print "type an integer: "
  invoke crt_scanf, chr$("%d"), addr myInteger
  print str$(myInteger), 9, "is your integer", 13, 10
  print "type a double: "
  invoke crt_scanf, chr$("%lf"), addr myDouble
  print real8$(myDouble), 9, "is your double", 13, 10
  inkey "That was easy, right?"
  exit

end start


\Masm32\help\*.chm is highly recommended, fascinating lecture :cool:

Ravi Kiran

Quote from: jj2007 on October 11, 2020, 10:19:05 PM
Vortex already gave you a good example, here is another one:
include \masm32\include\masm32rt.inc

.data
HelloW$ db "Hello World", 0
buffer db 1000 dup(?)
myInteger dd ?
myDouble REAL8 ?
.code
start:
  cls
  print addr HelloW$, 13, 10 ; CrLf
  print "type any text: "
  invoke crt_scanf, chr$("%s"), addr buffer
  print "this is what you typed: "
  print addr buffer, 13, 10
  print "type an integer: "
  invoke crt_scanf, chr$("%d"), addr myInteger
  print str$(myInteger), 9, "is your integer", 13, 10
  print "type a double: "
  invoke crt_scanf, chr$("%lf"), addr myDouble
  print real8$(myDouble), 9, "is your double", 13, 10
  inkey "That was easy, right?"
  exit

end start


\Masm32\help\*.chm is highly recommended, fascinating lecture :cool:

Thank you sir it worked in winasm IDE. But when I type
.model flat, stdcall assembler flags an error saying .model directive
used twice. It assembled w/o errors when I omit the .model directive.

Also why can't we use [stdout] and [ stdin] functions instead of crt_printf and crt_scanf functions you have said. This looks more like
HLL to me.

hutch--

Its obvious that you don't read the help files, StdOut and StdIn are modules in the masm32 library.

Vortex

Hi Ravi,

    invoke  [StdOut],ADDR str1

The brackets does not have any effects here.

guga

Quote from: Ravi Kiran on October 11, 2020, 10:02:01 PM
Sir I'm beginning 32-bit MASM Assembly and I'm very far from learning x64 Assembly. Let me learn this x86 assembly first then after
a long time we can think of x64. Please help me with x86 assembly examples

Hi Ravi

Here is the Iczelion tutorials for 32 bits (CHM made by  Edgar Hanson - aka: Donkey)

http://www.website.masmforum.com/tutorials/index.htm
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com