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 problems

Started by daydreamer, August 31, 2019, 06:18:20 AM

Previous topic - Next topic

daydreamer

Hi
found several programming exercises,decided to go my own interpretation of them using masm console
print works,cannot find macro for input string/floats /number /keypresses
so I am going thru some C++ exercises and start with one simple and move from switch/case and other typical C++ solutions to more typical jumptable masm solutions
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

Vortex

Hi daydreamer,

Did you check the Console Mode Functions section in masmlib.chm?

\masm32\help\masmlib.chm :
Quote
Console Mode Functions

ClearScreen
locate
StdIn
StdOut
StripLF
StdErr 

Function receiving keyboard input :

QuoteStdIn :

StdIn proc lpszBuffer:DWORD,bLen:DWORD

Description

StdIn receives text input from the console and places it in the buffer required as a parameter. The function terminates when Enter is pressed.

daydreamer

thanks vortex,I invoke stdin,but nothing happens,print macro works,its some macro that uses stdout
what I found working while searching input is a keypress proc
yes the first one is make a calculator exercise

main proc

    cls
    print "mycalculator",13,10
    invoke StdIn,buffer2,128

    print "A.addition +",13,10
    print "B.subtraction -",13,10
    print "C.multiplication *",13,10
    print "D.division /",13,10
   
    @@:
        call wait_key
        mov thechar, al
        invoke crt_printf, ADDR format, ADDR thechar
        call jtable
    jmp @B
   ;invoke StdIn,buffer,20
     
   
    inkey

    ret

main endp

main proc

    cls
    print "mycalculator",13,10
    invoke StdIn,buffer2,128

    print "A.addition +",13,10
    print "B.subtraction -",13,10
    print "C.multiplication *",13,10
    print "D.division /",13,10
   
    @@:
        call wait_key
        mov thechar, al
        invoke crt_printf, ADDR format, ADDR thechar
        call jtable
    jmp @B
   ;invoke StdIn,buffer,20
     
    movss xmm0,x
    inkey

    ret

main endp
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

Vortex

Hi daydreamer,

Here is a quick StdIn example :

.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     \masm32\include\masm32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\masm32.lib

.data

str1        db 'Please type your name :',13,10,0
str2        db 'Nice to meet you %s. '
            db 'Have a nice day.',13,10,0

.data?

buffer      db 64 dup(?)
buffer2     db 128 dup(?)

.code

start:

    invoke  StdOut,ADDR str1

    invoke  StdIn,ADDR buffer,64
   
    invoke  wsprintf,ADDR buffer2,\
            ADDR str2,ADDR buffer
           
    invoke  StdOut,ADDR buffer2

    invoke  ExitProcess,0

END start

daydreamer

Quote from: Vortex on September 01, 2019, 06:21:14 AM
Hi daydreamer,

Here is a quick StdIn example :

.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     \masm32\include\masm32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\masm32.lib

.data

str1        db 'Please type your name :',13,10,0
str2        db 'Nice to meet you %s. '
            db 'Have a nice day.',13,10,0

.data?

buffer      db 64 dup(?)
buffer2     db 128 dup(?)

.code

start:

    invoke  StdOut,ADDR str1

    invoke  StdIn,ADDR buffer,64
   
    invoke  wsprintf,ADDR buffer2,\
            ADDR str2,ADDR buffer
           
    invoke  StdOut,ADDR buffer2

    invoke  ExitProcess,0

END start

thanks very much Erol :thumbsup:
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

daydreamer

jumptable works now
I am working on 25+buttons version
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

daydreamer

is it possible to make this simpler with L1:,L2:,L3: labels or am I forced to use this method with:

      L1 PROTO
      L2 PROTO

.data
      jtable dd L1,L2




jmptable proc
mov eax,choice
mov eax,[eax*4+jtable]
jmp (eax)
ret
L1 proc
;place code and ret here
L1 endp
L2 proc
;place code for second choice +ret here
L2 endp

was thinking let masm do the job for me,safer than self run code thru debugger to figure out adresses and a way for more flexible sizes,for example a division and reciprocal needs added code to for error handling to check for div by zero
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding