Hello. I'm starting to learn about assembly programming.
I need to write console programs, and want to know if anyone can tell me how to write and read from console.

I'm using masm, and I have gone through the pages of Iczelion's tutorial, but couldn't find anything about this.

If anyone has some time to help me out, I would appreciate it. :)

Regrets, Goteki45.

Ps. I came into assembly programming because I need to build a compiler for my Compiler I course from College.
Posted on 2003-07-30 01:02:04 by Goteki45
if use masm32 from hucth, find in m32lib ,to read masmlib.hlp for detail
Posted on 2003-07-30 01:20:39 by h4ng4m3
Thanx for the reply. I do use hutch's masm32, but there isn't a masmlib.hlp file in m32lib folder, nor on the help folder. :confused:

I've been told that there are libraries for doing so, but I don't know wich ones.
Posted on 2003-07-30 13:18:11 by Goteki45
Hi
I am probable the last person in this furum to reply to your question, coz I am new to assembly.

Anyway I'll post my first example :

Ex1:
; --------------Start------------------

; ------------------------------------------------------
;compile : ml /c /coff /Cp HelloWorld.asm
;link : link /SUBSYSTEM:CONSOLE /LIBPATH:c:\MASM32\lib HelloWorld.obj
; -----------------------------------------------------

.386
.model flat, stdcall
option casemap :none ; case sensitive

; ------------------------------------------------------

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

; --------------------------------------------------------
.data
prompt db 'Hello World',0dh,0ah,0

.data?

.code
start:
invoke StdOut,ADDR prompt ;print the string Prompt
invoke ExitProcess,0 ;return controll to OS
end start
;----------------End-------------------


Ex2
;------------------------START-------------------------
; -----------------------------------------------------
;compile : ml /c /coff /Cp arth.asm
;link : link /SUBSYSTEM:CONSOLE /LIBPATH:c:\MASM32\lib arth.obj
; ------------------------------------------------------

.386
.model flat, stdcall
option casemap :none ; case sensitive

; ------------------------------------------------------

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

include \masm32\include\masm32.inc

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

; ------------------------------------------------------
;----------------Initialized data------------------------
.data
nl db 0dh,0ah,0 ; new line

Prompt db "Let/'s do some Arthmetics",0dh,0ah,0

Value db "Now we will put 12 in eax & print it .... EAX = ",0

Addition db "Adding 12 + 12 = ",0

Subtraction db "Subtracting 12 - 10 = ",0

ShiftL db "Shifting 12 one step left = ",0

ShiftR db "Shifting 12 one step right = ",0

;----------------Uninitialized data------------------------
.data?

res dd ? ;Dubble

resstring db ? ;string

.code
start:

invoke StdOut,ADDR Prompt ; intro text

;----------------mov-------------------------------
mov eax,12 ; put 12 in eax
mov res,eax ; move it to memory res

invoke dwtoa, res, ADDR resstring ; convert it to String
invoke StdOut, ADDR Value ; print the string Value
invoke StdOut, ADDR resstring ; print the String
invoke StdOut, ADDR nl ; print a new line
;--------------------add------------------------------

mov eax,12 ; put 12 in eax
add eax,12 ; add 12 to eax
mov res,eax ; move it to memory res

invoke StdOut, ADDR Addition ; print the string Addition
invoke dwtoa, res, ADDR resstring ; convert it to String
invoke StdOut, ADDR resstring ; print the String
invoke StdOut, ADDR nl ; print a new line
;--------------------Sub------------------------------
mov eax,12 ; put 12 in eax
sub eax,10 ; add 12 to eax
mov res,eax ; move it to memory res

invoke StdOut, ADDR Subtraction ; print the string Subtraction
invoke dwtoa, res, ADDR resstring ; convert it to String
invoke StdOut, ADDR resstring ; print the String
invoke StdOut, ADDR nl ; print a new line
;---------------------shl------------------------------
mov eax,12 ; put 12 in eax
shl eax,1 ; shl 12 to eax
mov res,eax ; move it to memory res

invoke StdOut, ADDR ShiftL ; print the string ShiftL
invoke dwtoa, res, ADDR resstring ; convert it to String
invoke StdOut, ADDR resstring ; print the String
invoke StdOut, ADDR nl ; print a new line
;---------------------shr------------------------------
mov eax,12 ; put 12 in eax
shr eax,1 ; shl 12 to eax
mov res,eax ; move it to memory res

invoke StdOut, ADDR ShiftR ; print the string ShiftR
invoke dwtoa, res, ADDR resstring ; convert it to String
invoke StdOut, ADDR resstring ; print the String
invoke StdOut, ADDR nl ; print a new line
;---------------------------------------------------

invoke ExitProcess,0
end start
;----------------------END-------------------------

Not the best Example, but hee it works at least :).

PS:
You can get Masm32 from http://webster.cs.ucr.edu/Downloads.html with all the help files included.. Good luck m8.

Best Regards
Posted on 2003-08-01 07:34:13 by mistronr1
I've got some kind of adjusted program written in masm32. The purpose was to write procedures to use easily in console programs, because I test a lot of other procedures and don't really need the windows GUI. So on http://users.skynet.be/kurchakk you have to click download example and you just have to read how I did the adjustments. You find also other nice stuff there so if you still don't have them feel free to download it. Everything is freeware, so you don't have to bother yourself with "illegal software issues".

greetz
Raidu
Posted on 2003-08-01 20:19:11 by raidu
Hello again, and thanks for the replies.... :alright:

But I'm having a problem: I don't know why but masm32.lib isn't on my lib folder... I tryed re-building all the libs running makelibs again.... but it still doesn't build it... I think it thows an error...
Then I tryed rebuilding it manually, using the make.bat file in M32LIB folder, but it says the file "about.obj" is missing. So then I tryed assembling each of the asm files in that folder manually (all 87 of em'!!) but still, the .obj files were erased after running again make.bat, and it still threw the same error!!

Damn.... :mad: can someone send me the masm32.lib file for me please?? Or tell me what am I doing wrong!!!
:stupid: :grin:

Regrets, Goteki45.

And thanks mistronr for the examples.... I just wish I could try them...:(
Posted on 2003-08-02 03:22:44 by Goteki45
check my homepage http://users.skynet.be/kurchakk/index.htm . There you can download everything you need to start with.
Do the following:
- save all your projects to another location
- delete masm32 from your directory
- download masm32v8 from my webpage (or any other)
- unzip the download
- run install.exe

results: masm32v8 works again. I use masm32 with radasm (also on my webpage). All the other stuff you need to in fact. Those are helpfiles (put them in c:\masm32\help directory) and the two others are debugger disassemblers. with PEBrowseI you can run trough your code step by step. The other PEBrowse you can disassemble programs and dll's to view the opcodes. This last one is a static program, it only disassembles. The first (PEBrowseI) works interactivally (how do you write this word, for gods....). You can go step by step through your code or execute large blocks of code at once, to see how the program reacts. You have to play with that for a while then everything becomes more clear.

- DON'T PANIC - when something goes wrong redo it. Even if you have to install your entire operating system (but when you have to do that, try some easier programs)
- TRY TO REMEMBER the steps you made and are doing (easier for others to troubleshooting your problem
- DOCUMENTATE A LOT of your sourcecode.
- when writing large programs, try to cut it into pieces (called procedures). And check every piece separately.
(maybe you already know that but it's important in assembler to do so at the beginning. Later when you are familiar with assembly language your pieces will become larger and larger. But by this time you are much more expirienced with the stuff.)
If any questions -> mail me.

greetz
Raidu
Posted on 2003-08-02 03:49:43 by raidu
Hi Raidu

The link you posted is in French & Dutch, I don't know any of this languages.

I like you advices, vary nice set of advices, Masm32 is available at : http://webster.cs.ucr.edu/Downloads.html

Goteki45 follow Raidu's advices I think he knows what he is talking about :)

Best Regards
Posted on 2003-08-02 06:53:35 by mistronr1
yep, try http://users.skynet.be/kurchakk/index.html (i forgot the l behind htm),
sorry for that.

Raidu
Posted on 2003-08-02 07:16:53 by raidu
Note: I installed PEBrowse Interactive on my laptop running Windows 98se, but upon launching, it states it only runs on Windows NT versions. Couldn't add\remove it: had to delete the directory manually.
Posted on 2003-08-02 08:42:41 by Masmer
I will mention it on my homepage, thanks for notifiyng me.

greetz,
Posted on 2003-08-02 10:05:07 by raidu
Hey you guys there.

Maybe you know it already, but I've have encountered some difficulties by accessing the read procedures (for the console program) directly without calling any other write (to console) procedure. Maybe I've found the reason. When experimenting in the code, I've called the invoke Locate,0,0 procedure BEFORE doing anything else and the problem was resolved.

example:

main:
invoke ReadChar
mov DWORD PTR ,eax
invoke WriteChar,ADDR char
invoke NewLine
.
.
.

wouldn't work like this, the solution is (at least mine):
main:
invoke Locate,0,0

invoke ReadChar
mov DWORD PTR ,eax
invoke WriteChar,ADDR char
invoke NewLine
.
.
.

I've called that procedure InitConsole
( InitConsole proc
invoke Locate 0,0
InitConsole endp
)

So when you make a template or just want to start programming, keep in mind to use a sortlike procedure to initialize your screen. An empty console program with only a main and exitprocess invokation only opens a console display, the OS doesn't still know what to do with it. (At least what I believe)
I hope to be helpfull with it.

greetz
Posted on 2003-08-02 10:17:31 by raidu
Hello again.

Thanks raidu and mistronr1 for the advice, I'll try to follow it.... but I still have the last problem. I downloaded mams32v8 from the links you guys posted (I'm downloading radasm right now, I'll be trying it later), but it was the one I already had. I'm still missing masm32.lib... and I can't do anything without it!! Can't even try the examples mistronr1 posted!!
Someone please tell me where to find it or how to buil it!! I'll try re-installing masm once again... or maybe with radasm I could correct this.

Thanks again for the help. I apreciate it. :alright:

Regrets. Goteki45.
Posted on 2003-08-02 17:02:57 by Goteki45
strange, I searched it on my harddisk and everything is ok.
so: 1) You have downloaded masm32v8
2) you removed your own masm32 directory (WITHOUT YOUR OWN PROJECTS)
3) you unzipped the masm32v8 download
4) you did run install.exe (from the executable derived from masm32v8.zip
5) a silent installation has performed
6) you noticed a console screen wich asks to press a key to start the building of the libraries.
Then everything should be fine.
If this doesn't help (what I doubt) you can download masm32.lib from here and put it in the following directories (on my laptop it is so, so I suppose it have to be so: c:\masm32\lib and c:\masm32\m32lib

I hope I've helped you right now.

greetz
Posted on 2003-08-02 17:25:15 by raidu
Phew!! Finally.... :tongue:

Thanks Raidu for that attachment... I re-installed masm and still got the problem that the masm32.lib wasn't build... Saw an error while the installer was doing so that said that some .obj file was in use and could not be open. So I just copied the masm32.lib file in the attachment to the Lib folder and that resolved my problem.... Thanks a lot raidu... don't know what is causing the installer not to build this library...

mistronr1, I tryed your examples... Ex2 worked just fine... But Ex1 didn't. It did nothing. I just copied the code that you posted here and tryed builing it using Qeditor's "Build All" command. Don't know what's wrong, but it already gave me the idea how to do what I was trying to do when posted this topic....

Thanks for your help....

Regrets.
Posted on 2003-08-03 01:25:49 by Goteki45
Hi Goteki45
Glad I could help :),try to compile Ex1 from the command prompt it should work.

Best Regards
Posted on 2003-08-03 08:23:41 by mistronr1
Thanks mistronr1, it worked just fine now. :alright:

Regrets.
Posted on 2003-08-03 18:34:56 by Goteki45