News:

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

How to get user input

Started by Elvenmonk, November 18, 2011, 05:37:01 AM

Previous topic - Next topic

Elvenmonk

This is what the instructions are. I was working on STDIN macro when I came here.
Design and implement macros to do the following:
•Convert a signed BCD integer to a signed integer, allowing the programmer to determine the length of the resulting binary number (32, 16 or 8 bit). Remember that you need to handle BCD strings that are too large (or small) to convert successfully.
•Convert a signed integer (32, 16 or 8 bit) to a signed BCD integer suitable for printing.
•Print a string to STDOUT using the Standard C Library
•Read a string from STDIN using the Standard C Library

Before we were using inline assembly(with visual studios) for all I/O and variable declarations ( something else I'm still not 100% on in assembly)
currently reading all the docs you guys provided right now.

dedndave

that doesn't look too bad   :P

it looks like he wants you to incorporate printf and scanf into macros
however, he didn't say that the macros had to accomodate the full functionality of those functions

he seems to be misusing the term "BCD strings" - i think he means ASCII strings (e.g. "suitable for printing")

qWord

Quote from: dedndave on November 21, 2011, 01:02:10 AMhe seems to be misusing the term "BCD strings" - i think he means ASCII strings (e.g. "suitable for printing")
however, MASM can encode BCD numbers  (->TBYTE).
FPU in a trice: SmplMath
It's that simple!

MichaelW

The most recent description seems to use "BCD integer" and "BCD string" interchangeably, so I'm assuming that a BCD string is what I would call a decimal string. The description does not mention scanf or printf, and apparently you are not to use these or other CRT functions to do the integer to/from decimal string conversions. I think the intended CRT functions may be _cgets and _cputs.
eschew obfuscation

Elvenmonk

cgets and cputs?
As for the BCD we're supposed to read in 15chars of numbers plus a sign then remove the "3"s so like 12 would be "3132" and cut it down to "12".

Also, Michael when using your code I ran into an error. Whenever I would type in a string higher then 4 chars it would cut off the first 4 characters.
Edit, nevermind? It's odd when I typed it out, like you had it I was getting print errors. So I then copy your code and it worked 100%. So, I then compared it line by line with what I typed, but it was 100% exactly has you had typed. I have no idea why it was wigging out. Thank you so much.

dedndave

cgets - i'd use _cgets_s
Gets a character string from the console.
http://msdn.microsoft.com/en-us/library/tz00x758.aspx

although, you can use the simpler version _cgets
http://msdn.microsoft.com/en-us/library/3197776x.aspx

_cputs
Puts a string to the console.
http://msdn.microsoft.com/en-us/library/3w2s47z0.aspx

wrap them in macros and that part is done

the "hard" part is base conversion, which isn't all that hard
there are a few special cases to watch for...
8-bit signed values range from -128 to +127
16-bit signed values range from -32768 to +32767
32-bit signed values range from -2147483648 to +2147483647

so, except for the values -128, -32768, and -2147483648, you can NEGate negative values and convert them as positive
those values are special because they cannot be negated without overflow
in hex, they are 80h, 8000h, and 80000000h, respectively

dedndave

also...

you can use the CBW, CWD, CWDE, CDQ instructions to extend signed values in size
http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-1.html#HEADING1-226

this type of method may allow you to share the same code for conversions of all the required sizes