News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

how to input an integer from keyboard ???

Started by m7xtuf, February 10, 2010, 07:20:18 PM

Previous topic - Next topic

m7xtuf

Hi there,

   I am looking for a function to get input from keyboard ...

   I know "invoke crt__getch" which I can read a "key" to AX ... but I want a function which get an integer to AX ... (i.e. enter a number then hit ENTER).

   Thanx for all your wonderful help so far

   

   

Neil

Have a look at the getkey macro in macros.asm

m7xtuf


Magicle

Quote from: m7xtuf on February 10, 2010, 07:34:59 PM
Where can I get that file "masm.asm" ???

Ctrl+F (Search for macros.asm) on your \masm32\ folder.  :wink
[Or just go in \masm32\macros\ ]

m7xtuf

Did I need to include any library to use those macros ???  I try to assemble and I have a link error ...

Thanx

Magicle

Well, did you '#include' it?
In order to use already defined functions from other files, you have the necessity to include them in the header of the program.

Neil


Magicle

Just like Neil said.
If you get additional errors, make sure you post them here and we'll do our best to help.  :U

m7xtuf

Sorry I must be very stupid ... I am new to assembly programming ...

I include the file at the top "include     \masm32\macros\macros.asm" but I got a lot of error when assembling ...

e.g. undefined symbol ret_key


this is what I put at the top

include     \masm32\include\msvcrt.inc
includelib  \masm32\lib\msvcrt.lib

include     \masm32\macros\macros.asm





Magicle

First of all, don't beat yourself up. Everyone has to start somewhere and even I am new to assembly, so no worries - everyone has to learn.  :wink

You should check the parameters in the actual macros.asm file.
Open it up and search for 'getkey' , you will see the parameters needed for the function.
If that's not the case, please post the output you get in cmd.

Neil

I assume you are programming a console application. Use these headers :-

    include \masm32\include\masm32rt.inc
    include \masm32\macros\macros.asm

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

Magicle

Ah, just saw this is getkey:

;; ---------------------------------------------------
    ;; wait for a keystroke and return its scancode in EAX
    ;; ---------------------------------------------------
    getkey MACRO
      call ret_key
    ENDM


So I see no reason why that would give errors itself (Unless something is erroneous in your code).
Try what Neil wrote.

Neil

Once you get it to work you can do something like this :-



keypress:
    getkey                  ;wait for & get keypress

SWITCH eax

    case "1"
        jmp somewhere or do something
    case "2"
        jmp somewhere or do something 
    case "3"
        jmp somewhere or do something
    case "4"
        jmp somewhere or do something
    case "5"
        jmp somewhere or do something
    case "6"
        jmp somewhere or do something 
    case "7"
        jmp somewhere or do something
       
DEFAULT
    jmp keypress

ENDSW

m7xtuf

Thanx for all the help ...

I can assemble now with the "getkey" macro, but I need to read a number to AX directly.

Now I can only read in ONE character at a time ... I want a integer input ...

Is there any library I can use using "invoke" ???

Thanx

oex

mov eax, sval(input("Enter Number: "))
print str$(eax)
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv