The MASM Forum

General => The Campus => Topic started by: radarblue on February 18, 2015, 09:42:17 AM

Title: Newbie
Post by: radarblue on February 18, 2015, 09:42:17 AM
good day.

I work with electricity and want to learn Assembly. Mostly because we get into PLC automation and BCD chips in the "computer chapters". Always loved Amiga and the old stuff, or rather machine logic. Picked up a book called "X86 Assembly and C fundamentals" and having fun with binary arithmetic. However trying to code is a disaster. I cant even get a C compiler to run proper and feel completely lost . And the Visual Express c++ is not exatly working for me. A friend told me to use GCC.

I also have the MASM installed, but I dont get much out of it ...
My goal is to learn Assembly and insert the "inlines" to C.

well cheers.
Title: Re: Newbie
Post by: dedndave on February 18, 2015, 10:49:19 AM
i worked with PLC's a little bit - nothing like assembler, unfortunately - lol
i didn't care for the "ladder logic" languages
i know electronics and assembler - and they didn't make sense   :lol:

if you have installed the masm32 package...
you can examine some of the examples in the masm32\examples folder to get some ideas
Title: Re: Newbie
Post by: rrr314159 on February 18, 2015, 12:37:03 PM
Welcome radarblue,

a supplement to dedndave's advice,
Quoteif you have installed the masm32 package...
If you haven't: do so! I was in exactly the same boat as you until I ran into masm32, played with the examples - best environment around, IMHO. Any questions, just ask, somebody (for newbie q's, probably everybody) knows the answer
Title: Re: Newbie
Post by: Gunther on February 18, 2015, 09:02:31 PM
Hi  radarblue,

welcome to the forum.

Gunther
Title: Re: Newbie
Post by: Siekmanski on February 19, 2015, 06:57:43 AM
radarblue, welcome to the forum.
Title: Re: Newbie
Post by: Vortex on February 19, 2015, 07:09:17 AM
Hello radarblue,

Welcome to the Masm Forum.
Title: Re: Newbie
Post by: radarblue on February 20, 2015, 02:01:44 AM
Thanks
The MASM32 is installed. And thats about it .
And looking into some examples and "how to`s..".
Its an enormous amount of read .

And I who thought, this was going to be easy  ;)
Title: Re: Newbie
Post by: radarblue on February 20, 2015, 06:01:53 AM
Installing.
I install MASM32 once again. I get some errors similar to this :
http://masm32.com/board/index.php?topic=1110.0

incl2Exe
1. The ordinal 200 could not be located in the dynamic link liberary
C:\windows\appPatch\AcGenral.DLL

2. the ordinal 202 could not be located in the dynamic link liberary
C:\windows\appPatch\AcLayers.dll

And so on, maybe 20 errors on a row, at the end of the installer.
I have a windows 8 on a PC dual core 2.

Q1 . Will the MASM editor perform as expected without therse DLL`s?


The forum says Hutch :
Try something unusual, if you have a much later version of ML.EXE and LINK.EXE, place them in the BIN directory then run the batch file. There should not be anything in INC2L.EXE that triggers this problem but it repeatedly calls ML.EXE and LINK.EXE.

Q2 : I dont understand. Put the installer file on a special place before installing ?
Title: Re: Newbie
Post by: radarblue on February 20, 2015, 06:25:03 AM
I found a file called "hello" text file and loaded into Qeditor . masm32\tutorial\console\demo1.
I got the OBJ.file and the .EXE file without errors. However the .EXE file will not run or display anything .

Question : why ?

However running the original hello.exe file provided in the tutorial folder, it blinks the text " hey this actually works" for a brief second .

Title: Re: Newbie
Post by: jj2007 on February 20, 2015, 07:04:22 AM
1. Did you use "console build all"?
2. If yes, run the exe from a command prompt (as qEditor does not recognise that the console window needs to be kept open).
Title: Re: Newbie
Post by: radarblue on February 20, 2015, 08:22:45 AM
 :biggrin:
No I didnt. I used "Project>Build all".
But when I use "Project>Console Build all". It comes up like expected .
THANKS !

Q : How do I make the "progam" stay on screen and not disappear in a instant ?
Title: Re: Newbie
Post by: dedndave on February 20, 2015, 04:22:14 PM
for console mode programs, we often use the "inkey" macro before exit
this displays "Press any key to continue...", and waits for the user to press a key

; program code

    inkey
    exit     ;or INVOKE ExitProcess,0
Title: Re: Newbie
Post by: rrr314159 on February 20, 2015, 09:26:31 PM
Hello radarblue,

Here's how I dealt with those issues; probably not the normal way, but works for me. IF you're familiar with the DOS command prompt it will work for you too, otherwise maybe not.

Anyway, in qEditor hit "CTRL-D" to bring up the DOS window. Type "hello" at the prompt (or, hello.exe), hit enter, the program runs in the command window and the results stay there; no need for inkey.

You can just use that simple trick, but if you're familiar with the DOS cmd window (or, are willing to become so) read on.

I use the cmd window most of the time, instead of the qEditor menus. It's actually easier (for me) and gives me more control. Here is a simple "makefile" batch file:
@echo off

if exist "%1.obj" del "%1.obj"

\masm32\bin\ml /c /coff "%1.asm"
if errorlevel 1 goto theend

if exist "%1.exe" del "%1.exe"

\masm32\bin\link /nologo /subsystem:console  /OPT:NOREF %1.obj
if errorlevel 1 goto theend

%1

:theend


If you're not OK with batch files this might not help you. Anyway, (if you want) copy this into a file "do.bat" and put in your directory. Then, in the cmd window, type "do hello" and it will assemble, link and run your hello sample program. Again, the results stay on the screen.

Get any other sample program, put in your directory, type "do MySample", it will work.

Use the up-arrow key, in the DOS window, to bring back the last-typed line. So, I modify the .asm file using qEditor, then hit up-arrow / Enter to quickly re-compile/link/run. This way I retain a history of what I've done ... and, can modify the batch file to change ml and linker options, link multiple files, etc ... I just find this approach gives more control and is actually quicker.

Your mileage may vary! If you don't want to get involved with this method, at least the ctrl-D trick allows you to run "hello" without inkey.

Good luck, c u later! ..
Title: Re: Newbie
Post by: jj2007 on February 20, 2015, 10:32:13 PM
Quote from: radarblue on February 20, 2015, 08:22:45 AM
Q : How do I make the "progam" stay on screen and not disappear in a instant ?

There is rrr314159's way to do it from the commandline, or Dave's proposal to insert an inkey. The latter needs a minor modification, though:
    print chr$("Hey, this actually works.",13,10)
    uselib msvcrt
    inkey chr$("Hey, this actually works.",13,10)

Finally, there is RichMasm (http://masm32.com/board/index.php?topic=94.0), an editor that autodetects if a program is GUI or console mode (and builds the app accordingly); it keeps the console window open in the latter case (unless it detects 'inkey' in the source - in this case it doesn't keep the window open, because it knows that the app will do that).
Title: Re: Newbie
Post by: rrr314159 on February 20, 2015, 10:38:49 PM
Wow - RichMasm checks for inkey and behaves accordingly? A minor point, but I have to say, that's impressive; you put a lot of thought into that program!
Title: Re: Newbie
Post by: jj2007 on February 20, 2015, 11:41:45 PM
Quote from: rrr314159 on February 20, 2015, 10:38:49 PM
Wow - RichMasm checks for inkey and behaves accordingly? A minor point, but I have to say, that's impressive; you put a lot of thought into that program!

Thanks, but it's not so much thought but rather a necessity: If you have to see a window flash and disappear a dozen times, you logically say "I must teach that bloody editor what a console app is". And sometimes I need an inkey at the end, e.g. for posting snippets for noobs here, and then I couldn't stand hitting a key twice.

And of course, it was a bit of a challenge to find a reliable way to determine if it's subsystem:console or subsystem:windows.
C print
C inkey
W SendMessage
W CreateWindow
...
but then, MsgBox or MessageBox may appear in both. Even SendMessage can be used in console apps.

Anyway, it works. Another goodie:

... code ...
int 3
... code ...
RichMasm will launch \Masm32\OllyDbg\ollydbg.exe MyApp.exe With Some Args If Necessary

... code ...
; int 3
... code ...

RichMasm will not launch Olly ;-)