News:

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

Learning Assembly for fun

Started by frktons, February 15, 2010, 03:22:29 AM

Previous topic - Next topic

frktons

Hi everybody.

I just arrived at MASM forum.
Once upon a time I used to program in PL/1 on an IBM mainframe.
Now I'm almost a retired programmer, and "just for fun" I decided to learn a bit of MASM.
Could you suggest a path to follow, I mean a Step By Step introduction to the
language and the tools?
I've already installed the MASM32 package on my pc, and now I'm trying to start.

Thanks for your suggestions.

Frank
Mind is like a parachute. You know what to do in order to use it :-)

hutch--

Hi Frank,

Welcome on board. The stuff you need to get is the manuals from Intel and decent access at the Microsoft win API function set. The architecture of later Intel hardware is worth learning as it gives you a good idea of howe current operating systems use it. RE masm32, have a poke around the tutorials and the example code as well as the help files on the Help menu of the editor, that should get you started and if you have specifics don't be afraid to ask in here, its a script kiddie free zone with a lot of experienced programmers who help out as their time allows.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

welcome to the forum, Frank   :U
PL1, eh - i feel younger already

in the upper right corner of the forum is a link for Forum Links and Website
besides the intel references that Hutch mentioned, there is a link for Iczelion's tutorials - a good starter kit
also, in the masm32 folder, browse around in the Examples, Help, and Tutorials folders
of course, another good place to poke around is the forum, itself - the forum search tool will get you a lot of info

oh - here is a link i use quite often, also

http://www1.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-1.html

frktons

Thanks friends, I'll try poking around the c:\masm32 folder for examples and help files,
as time permits.

If I find something hard to digest, or I get lost  :'(, or I discover some interesting stuff  :8)
I'll be right back.

Enjoy   
Mind is like a parachute. You know what to do in order to use it :-)

Bill Cravener

Just never lose that word fun when approaching asm and the Windows API's and you'll do fine. :wink
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

frktons

Quote from: dedndave on February 15, 2010, 04:13:56 AM
welcome to the forum, Frank   :U
PL1, eh - i feel younger already

in the upper right corner of the forum is a link for Forum Links and Website
besides the intel references that Hutch mentioned, there is a link for Iczelion's tutorials - a good starter kit
also, in the masm32 folder, browse around in the Examples, Help, and Tutorials folders
of course, another good place to poke around is the forum, itself - the forum search tool will get you a lot of info

oh - here is a link i use quite often, also

http://www1.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-1.html

ah! Ah! It'll take months for me, not a native english speaker, to manage something different than
printing "Hello" on the screen, and that is very FUN-ny indeed  :lol

By the way I printed that infamous chapter 6  :U and I'm happy to rejuvenate you with a PL1 subroutine  :bg

Quote from: Bill Cravener on February 15, 2010, 05:57:52 PM
Just never lose that word fun when approaching asm and the Windows API's and you'll do fine. :wink

Yes Bill, you are right, and without FUN I can't do anything  :U

Just for FUN, I was thinking about the first project:

*) Reading a file with 10,000 records, sorting it and writing it back to the disk with a different name.
and to make even more FUN, I was dreaming about 3 different versions of the program, PBCC, C, and MASM.
This should give me enough stuff to work, learning some respected HIGH level languages for the Windows platform.
Once the programs are ready, I'll post them, one by one, with the elapsed time each version takes to do the job, hoping somebody can
help me optimize them and I can learn some interesting concepts. Well, Not all three versions here I mean.  :bg

See you with the first version in short time[?]

Frank
Mind is like a parachute. You know what to do in order to use it :-)

jj2007

Quote from: frktons on February 15, 2010, 08:45:26 PM
ah! Ah! It'll take months for me, not a native english speaker, to manage something different than
printing "Hello" on the screen, and that is very FUN-ny indeed  :lol

Hi Frank,
To get you started, here a Hello World skeleton.
Benvenuto al Forum :thumbu

include \masm32\include\masm32rt.inc

.data ; initialised variables
MyString db "Ciao", 13, 10, 0
MyReal4 REAL4 123.456
MyReal10 REAL10 123.456e-99

.data? ; non-initialised (i.e. zeroed) variables
NonInitDword dd ?

.code
hw db "Hello World at 1024 bytes", 13, 10, 0 ; with polink.exe
start:
MsgBox 0, offset hw, "Masm32 is easy!", MB_OK
exit ; short form of invoke ExitProcess, 0

end start

BlackVortex

Oh my god, what is that little msvcrt+macro infestation. That's not what you wanna show to a MASM newcomer ... use assembly ppl.

dedndave

QuoteOh my god, what is that little msvcrt+macro infestation.

lol @ "infestation"
you know Jochen - he loves his macros (and indentation)
i am starting to get the hang of reading macros
the indentation - i am mentally blocking (pun?) that, still   :P

jj2007

Quote from: BlackVortex on February 16, 2010, 04:16:32 AM
Oh my god, what is that little msvcrt+macro infestation. That's not what you wanna show to a MASM newcomer ... use assembly ppl.

Depends on whether you want to scare away the newcomer with "real" assembler, or whether you want to give him a chance to see his first mov eax, 123 in action. What I provide above is just a skeleton for adding TheRealThing(TM)

frktons

#10
Quote from: jj2007 on February 16, 2010, 07:55:37 AM
Quote from: BlackVortex on February 16, 2010, 04:16:32 AM
Oh my god, what is that little msvcrt+macro infestation. That's not what you wanna show to a MASM newcomer ... use assembly ppl.

Depends on whether you want to scare away the newcomer with "real" assembler, or whether you want to give him a chance to see his first mov eax, 123 in action. What I provide above is just a skeleton for adding TheRealThing(TM)

Thanks jj, a skeleton is always welcomed in my wardrobe  :lol
I'll make use of it as I get to the Asm job.

By the way I managed to realize the first part of the project [see my previous post] in PBCC
and the outcome is:

                             Start Prog Time =>13:41:19

                             End Prog time ==>13:41:21

                             Number of Records =>245,204

                             Max Lenght of Records => 28

                             Number of CPU cycles 4,029,689,037

Not too bad for a compiled program that took me about 2 hours to write and test.  :8)
This is because PL1 is much alike Basic Language, and I had some previous knowledge of the Basic as well.

Now I'm going for the C version, which could take a little longer, as I've almost no previous knowledge of
the language, libraries, tools, and so fort.  Well let's get Pelles-C stuff.

See you for the second version [not too soon I suppose]  :eek
Mind is like a parachute. You know what to do in order to use it :-)

BlackVortex

Quote from: jj2007 on February 16, 2010, 07:55:37 AM
Quote from: BlackVortex on February 16, 2010, 04:16:32 AM
Oh my god, what is that little msvcrt+macro infestation. That's not what you wanna show to a MASM newcomer ... use assembly ppl.

Depends on whether you want to scare away the newcomer with "real" assembler, or whether you want to give him a chance to see his first mov eax, 123 in action. What I provide above is just a skeleton for adding TheRealThing(TM)
Yeah, check out the newcomers getting their registers trashed by what appears to be a simple "print" macro    :bdg

wsprintf is easy !

jj2007

Quote from: BlackVortex on February 21, 2010, 03:39:45 AM
Yeah, check out the newcomers getting their registers trashed by what appears to be a simple "print" macro    :bdg

I am always willing to learn: Please explain why newcomers learn better about the trashing of eax from "real" rather than Macro Assember. Here are the examples (I apologise for having used C runtime calls in the "real" assembler example).

include \masm32\include\masm32rt.inc   ; Version A: "real" assembler

.data
hw db "Hello World", 13, 10, 0
errmsg db " is in eax, we expected 123", 13, 10, 0
pak db "Press any key", 13, 10, 0

.data?
NumBuffer db 20 dup (?)

.code
start:
mov eax, 123
invoke StdOut, addr hw
invoke dwtoa, eax, addr NumBuffer
invoke StdOut, addr NumBuffer
invoke StdOut, addr errmsg
invoke StdOut, addr pak
invoke GetStdHandle,STD_INPUT_HANDLE
invoke FlushConsoleInputBuffer, eax
@@: invoke Sleep, 1
call crt__kbhit
test eax, eax
jz @B
call crt__getch
invoke ExitProcess, 0

end start


include \masm32\include\masm32rt.inc  ; Version B: Macro assembler

.code
start:
mov eax, 123
print "Hello World", 13, 10
print str$(eax), " is in eax, we expected 123", 13, 10
inkey "Press any key", 13, 10
exit

end start

BlackVortex

You may be a better programmer than me, but seriously ... like I said in my previous post : wsprintf FTW !

Anyway, here is my approach, no macros, no runtimes, just pure winAPI asm. (goasm syntax, doesn't matter of course)

#dynamiclinkfile kernel32.dll user32.dll
#include windows.h

DATA SECTION

sz_1               db "Hello World, %d (decimal) is in eax",13,10,0
h_console_out      dd 0
buffer             db 128 dup 0
junk               dd 0

CODE SECTION
START:

invoke GetStdHandle, STD_OUTPUT_HANDLE
mov [h_console_out], eax

mov eax, 123
invoke wsprintf , addr buffer, addr sz_1, eax
invoke WriteConsole, [h_console_out], addr buffer , eax , addr junk, NULL

invoke ExitProcess, NULL

Noone would expect the eax to retain its value.

EDIT: nevermind,corrected it

hutch--

Frank,

Just a short history on what style of assembler you are "supposed" to write. The old brigade with crude mnemonic crunching as some notion of purity left assembler in a shambles, near abandoned and ridiculed in the programming community. The pseudo high level stuff in MASM resurrected it from the dead and made it a living language again. Most would not write C like they did in the middle 80s yet they expect you to write assembler in the way that people cobbled together a few DOS interrupts 25 years ago.

A macro assembler is in fact a very smart tool, it allows the assembler programmer the capacity to design and build their own language while losing nothjing to fast low level code. The other factor is modern assembler programming must use operating system functions to access memory, hardware and so on so these clapped out notions of purity cannot in fact be put in place.

Its as usual, pick what works for you be it high level emulation or bare mnemonics and over time you will set up whatever format does the job for you. Good assembler programming never went out of its way to do things the hard way, it went for efficiency and performance and using your own choice of available capacity.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php