The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
June 04, 2023, 09:48:28 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Campus
| | |-+  Learning Assembly for fun
« previous next »
Pages: [1] 2 3 Print
Author Topic: Learning Assembly for fun  (Read 16933 times)
frktons
Member
*****
Gender: Male
Posts: 1048



Learning Assembly for fun
« on: February 15, 2010, 03:22:29 AM »

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
Logged

Mind is like a parachute. You know what to do in order to use it :-)
hutch--
Administrator
Member
*****
Posts: 12013


Mnemonic Driven API Grinder


Re: Learning Assembly for fun
« Reply #1 on: February 15, 2010, 03:29:28 AM »

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.
Logged

Regards,



Download site for MASM32
http://www.masm32.com
dedndave
Member
*****
Posts: 12523


Re: Learning Assembly for fun
« Reply #2 on: February 15, 2010, 04:13:56 AM »

welcome to the forum, Frank   ThumbsUp
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
Logged
frktons
Member
*****
Gender: Male
Posts: 1048



Re: Learning Assembly for fun
« Reply #3 on: February 15, 2010, 10:08:58 AM »

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  Cry, or I discover some interesting stuff  Cool
I'll be right back.

Enjoy   
Logged

Mind is like a parachute. You know what to do in order to use it :-)
Bill Cravener
Member
*****
Gender: Male
Posts: 1465



Re: Learning Assembly for fun
« Reply #4 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
Logged

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
Member
*****
Gender: Male
Posts: 1048



Re: Learning Assembly for fun
« Reply #5 on: February 15, 2010, 08:45:26 PM »

welcome to the forum, Frank   ThumbsUp
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  ThumbsUp and I'm happy to rejuvenate you with a PL1 subroutine  BigGrin

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  ThumbsUp

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.  BigGrin

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

Frank
Logged

Mind is like a parachute. You know what to do in order to use it :-)
jj2007
Member
*****
Gender: Male
Posts: 6011



Re: Learning Assembly for fun
« Reply #6 on: February 16, 2010, 02:27:17 AM »

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 ThumbsUp

Code:
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
Logged

BlackVortex
Member
*****
Posts: 983



Re: Learning Assembly for fun
« Reply #7 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.
Logged
dedndave
Member
*****
Posts: 12523


Re: Learning Assembly for fun
« Reply #8 on: February 16, 2010, 04:46:36 AM »

Quote
Oh 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   Tongue
Logged
jj2007
Member
*****
Gender: Male
Posts: 6011



Re: Learning Assembly for fun
« Reply #9 on: February 16, 2010, 07:55:37 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)
Logged

frktons
Member
*****
Gender: Male
Posts: 1048



Re: Learning Assembly for fun
« Reply #10 on: February 16, 2010, 12:48:03 PM »

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.  Cool
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
« Last Edit: February 17, 2010, 12:26:59 AM by frktons » Logged

Mind is like a parachute. You know what to do in order to use it :-)
BlackVortex
Member
*****
Posts: 983



Re: Learning Assembly for fun
« Reply #11 on: February 21, 2010, 03:39:45 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    BadGrin

wsprintf is easy !
Logged
jj2007
Member
*****
Gender: Male
Posts: 6011



Re: Learning Assembly for fun
« Reply #12 on: February 21, 2010, 08:22:53 AM »

Yeah, check out the newcomers getting their registers trashed by what appears to be a simple "print" macro    BadGrin

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).

Code:
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

Code:
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
Logged

BlackVortex
Member
*****
Posts: 983



Re: Learning Assembly for fun
« Reply #13 on: February 21, 2010, 09:05:28 AM »

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)

Code:
#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
Logged
hutch--
Administrator
Member
*****
Posts: 12013


Mnemonic Driven API Grinder


Re: Learning Assembly for fun
« Reply #14 on: February 21, 2010, 09:14:39 AM »

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.
Logged

Regards,



Download site for MASM32
http://www.masm32.com
Pages: [1] 2 3 Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!