Re: input & output in assembly

From: John H. Guillory (johng_at_mlc-hosting.net)
Date: 01/24/04


Date: Sat, 24 Jan 2004 06:42:43 +0000 (UTC)

On Sat, 24 Jan 2004 00:33:38 +0000 (UTC), dpakch3r1an@fastmail.fm
(Dpak Cherian) wrote:

>in 16-bit assembly is there any way to accept numbers as input and display them.
>btw, is there anything like cin & cout in assembly

No way, there's no way of doing cin/cout in assembly. Once the
compiler generates machine instructions, there is no cin/cout.
Actually, in reality there's only one GIGANTIC factor we must know
here.... What OS????? Seeing as how you did cross-post this to
comp.lang.asm.x86, I can rule out any non-intel 16-bit processors,
hybrid 8/16-bit processors and such.... Considering that all forms of
UNIX and LINUX are 32-bit or 64-bit, I can rule out Linux as the OS,
and can rule out Windows/XP, Windows/NT.... Now I *think* I can make
it fairly safe to assume your either using GEOS Ensamble, Windows
3.1/3.0 (maybe 2.0 or 1.0), or a version of MS-DOS/compatible OS.
With that in mind, that narrows down the scope of your answer a bit.
GEOS on the PC I only know GeoBASIC, and I don't think they sell it
any more, so I'll just say you have to find some other fool to help
you there if that's what you want.... Windows 3.0/3.1 your really up a
creak without a paddle. What the compilers do when you have cin/cout
in windows is usually create a window and write out text to that
window. Doing so will mean creating a window, keeping track of the
cursor position, creating a new font, writing the text out, updating
the cursor position, etc... Don't ask me to explain/write that....
Besides there's much more qualified people for that.... Now to the OS
I'm most qualified as a God at.... MS-DOS Compatible... (Which I'm
hoping you meant anyway....)

All MS-DOS functions are handled through INT 21h. Grab a copy of
Ralph Brown's interrupt primer. In it, you'll see Function 9.

Eg.

CODE SEGMENT PUBLIC 'Me'
ASSUME CS:CODE,DS:CODE,SS:None
Start: MOV AX, CS
          MOV DS, AX ; DS=CS
                MOV AH, 9 ; DOS Print String
                MOV DX, OFFSET Data1 ; Our String
                INT 21h
                RET

Data1: DB 'This is our string.',13,10,'$'
CODE ENDS
            END Start

The string *MUST* be terminated with a $.

For Standard Input, use AH=0Ah, DS:DX points to your buffer, which is
as follows:

1st Byte is the Maximum # bytes your buffer holds
2nd Byte is the # bytes actually read (on return)
3rd Byte onward is the actual string the user typed in.... Including
carridge return

CIN/COUT refers to Console In/Out, which in some C compilers means
direct screen writes. For that, you get to do things the hard way....
You move the string to the screen where you want it and handle the
attribute yourself.... Some C compilers will use INT 10h and use the
character out, others will just use STDOUT.... Either way, I highly
recommend you pick up Ralph Brown's interrupt primer and read the
introduction carefully, perhaps grab A86 and read up on how the INT
instruction works and 16-bit memory is layed out... Everyone hates it
when I recommend A86 manual, but it really does have some great
information in it. The older Art of Assembly language I believe is
geared towards 16-bit DOS assembly, and has some libraries that
provide easier access to input/output routines, though grasping an
understanding of what the library is doing really helps....

>PS. I'm a complete newbie so plz excuse
Not knowing, but having a desire to learn is not a problem.... Wanting
us to do something for you is a problem. And ASSUMING (as an
instructor once said) makes an ASS out of U and ME.... So just try not
to ASSUME that we know you are referring to MS-DOS or Intel, or
Windows 16-bit assembly.... And if you meant 16-bit motorola and you
cross-posted it to comp.lang.asm.x86 because you where too lazy to
check your posting before you sent it.... All I can say is you earned
any flames you get ;-)



Relevant Pages

  • Re: input & output in assembly
    ... there's no way of doing cin/cout in assembly. ... it fairly safe to assume your either using GEOS Ensamble, Windows ... The string *MUST* be terminated with a $. ... which in some C compilers means ...
    (alt.lang.asm)
  • Re: Windows Compilation Madness
    ... another long thread like this with all the problems windows users ... There are plenty of prevalent compilers, ... If the build-chain isn't predictable then it is ... a build environment on each and every Windows box what if the ...
    (comp.lang.ruby)
  • Re: grid
    ... The notation was invented in the days before there was cross-boundary prototype checking ... in the C compilers. ... He says that the Windows group saw HN, ... compiler, the K&R compiler, that declared all field names as global names, because structs ...
    (microsoft.public.vc.mfc)
  • Compiler positions available for week ending September 16
    ... advertise a position having something to do with compilers and must also ... Software Design Engineer ... The Visual C++ team is working hand in hand with the Windows division ... on enhancing the appeal of Vista and Windows 7 for ISV developers and ...
    (comp.compilers)
  • Handling error/status messages by interface to C++ programs
    ... commercial C++ compilers, such as, for example, Borland compilers, like C++ Builder. ... They can also run either in the console or Windows mode, and send appropriate error and status messages. ... The interface would later display the messages in this or other way. ...
    (comp.object)