News:

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

Need help to get started in ASM

Started by Jaime, April 05, 2007, 07:26:56 AM

Previous topic - Next topic

Jaime

Hi to you all from Belém - Brazil

I've been writing apps in VB and VBA for some time now; the last couple of years especially Access VBA, creating database applications for small and medium businesses. I also started to get my feet wet in DotNet lately. The reason for this post is that after having more or less mastered these high level languages, I still have the uncomfortable feeling that a lot what goes under the hood is plain mystery to me and I do not feel like I'm a "real" programmer yet. My resulting quests and inquiries led me to take a look at Assembly and I started by collecting some tuts from the web and started studying. I'm aware you don't learn ASM overnight and I'm willing to spend the necessary time, whenever I can, to seriously study the subject, but given that the material I could lay hands on date from the 80's and 90's, I'm afraid to engage in studying obsolete (ASM) techniques. I'm also not sure if there's still any practical need for ASM today (apart from Reverse Engineering).

So I'd like you ASM veterans to help me get started out, if you can:
1)What would be the kind of "updated" tutorials or books I should go hunting for?
2)Is there a way to learn ASM by making parallels with VB/VBA? I mean given a piece of code in VB,  it would be very ilustrative for me to find the equivalent in ASM, and my learning curve would be less exhausting, at least that's what I imagine.
3)"My" tuts mention a variety of archaic sounding tools, some of them even require DOS or are related to prehistoric terms like "16 bit"... what would be the necessary tools for WinXP?
4)After having spent all the time and effort to learn ASM, what real life (modern-day) apps, would I be able to create with it? Database apps maybe? Would you be able to indicate some actual working apps written in ASM?

Thanks in advance for your attention

Jaime

Draakie

WELCOME !

In Answer :

1) http://website.masm32.com/  --> see especially Iczelion Tuts - You'll be happy to see Database Access examples. :bg
2) Assembler is commonly interfaced with high-level languages - there's examples all over the place.(this forum -> search)
   More to the point - the use of assembler is much more varied than you might think - and is still a proper language all on
   it's own aswell!  :dance:
3) 16 bit = Yes = old DOS based programming - but much of the logic sets still apply in 32-bit. Bit and register manipulations etc.
4) You can code ANYTHING !!!! - VB, C++, JAVA etc. might have limitations - ASM does'nt.

There are many-many fully working applications published on this forum - my own humble one at
http://www.masm32.com/board/index.php?topic=5880.0 . Suggested tools - MASM32 package V9 & service pack/ RADASM / win32.hlp
                                                                                                            OllyDbg and loads of patience with enquiring mind... :bg

Draakie

PS: Be sure to read and understand the Forum  "Introduction" and "Rules of the Forum" on the Main Page. Obvious Q&A is covered
there. The best resource in learning to program in Assembler can be found right here in the forum!
Does this code make me look bloated ? (wink)

dsouza123

#2
A very simple assembly program using a few API calls
GetTickCount,wsprintf, MessageBox, ExitProcess.


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

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

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

.data
   ticks     dd 0                 ; dword to hold ticks alternative syntax    ticks   dword 0
   szCaption db "Ticks (milliseconds) since Windows startup",0
   szMessage db 256 dup (0)
   szFormat  db "%lu ticks",0

.code
start:
  invoke GetTickCount
  mov ticks, eax

  invoke wsprintf, addr szMessage, addr szFormat, ticks    ; convert dword to decimal string

  invoke MessageBox, 0, addr szMessage, addr szCaption, MB_OK
 
  invoke ExitProcess,0
end start


Most of the assembly code as the equivalent VB code, though the following code wasn't tested,

dword is the equivalent of long in VB, may really be sdword but dword is far more frequently used.


Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long

    Dim lngTicks   As Long
    Dim strCaption As String

    strCaption = "Ticks (milliseconds) since Windows startup"    '  very similar to MASM
   
    lngTicks = GetTickCount()
   
    MsgBox CStr(lngTicks) + " ticks",vbOKOnly,strCaption


There may be alternatives for the VB such as

MsgBox  lngTicks & " ticks", vbOKOnly,strCaption

and

Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long

depending on VB versions and default behaviors.

[attachment deleted by admin]

dsouza123

#3
From what I could determine Long from VB6 becomes Int32 in VB.NET

One version of the declaration for the MessageBox API call in VB is

Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hWnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long


For MASM, MessageBoxA and MessageBox are

MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
MessageBox equ <MessageBoxA>

and for the wide character version

MessageBoxW PROTO :DWORD,:DWORD,:DWORD,:DWORD

they are part of windows.inc, if it wasn't included then they would have to be
placed in the Ticks.asm file.


To show a more revealing comparison with the VB code,
a version of Ticks.asm with the API prototypes listed in the assembly file.


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


MB_OK equ 0h


GetTickCount PROTO

wsprintfA PROTO C :DWORD,:VARARG
wsprintf equ <wsprintfA>

MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
MessageBox equ <MessageBoxA>

ExitProcess PROTO :DWORD

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

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

.data
   ticks     dd 0
   szCaption db "Ticks (milliseconds) since Windows startup",0
   szMessage db 256 dup (0)
   szFormat  db "%lu ticks",0

.code
start:
  invoke GetTickCount
  mov ticks, eax

  invoke wsprintf, addr szMessage, addr szFormat, ticks

  invoke MessageBox, 0, addr szMessage, addr szCaption, MB_OK
 
  invoke ExitProcess,0
end start

[attachment deleted by admin]

dsouza123

Just updated the displayed code of my previous two posts, used addr one too many times, :red
had

addr ticks

should have had just

ticks

it was showing the address of ticks instead of the number of ticks,
it made time stand still.  ::)

Jaime

Hi Guys, thanks for the quick responses... I'm checking out the leads.

Draakie, I downloaded the Izcelion Tuts like u suggested, then guess what?

The first thing Izcelion says is:
"You must already know some basics about assembly language".

Then at the start of Tut 1:
"This tutorial assumes that the reader knows how to use MASM. If you're not familiar with MASM, download win32asm.exe and study the text inside the package before going on with the tutorial".

Then at the download page for Masm32 (I assume MASM32 and win32asm.exe are the same??)  at www.website.masm32.com it says:
"MASM32 assumes that the programmers who will use it already have experience in 32 bit Windows API programming using compilers and have done some work in assembler. It is not designed as a beginners package and it does not have the support for beginners to learn the basic concepts about assembler."

So as you can I'm still turning in circles, lost like a blind man in the midst of a gang shoot-out.
Also, all the links, for sample files etc, in the Izcelion Tutorial seem to be dead now.

Thank u for your patience

Jaime

hutch--

Jaime,

The problem has always been what is the bottom line as an entry level. Assembler programming is not a programming beginners area as it is complex and abstract area combined with the need to understand the range of Windows API programming which in itself is a large and complex area. It means understanding a large instruction set in assembler as well as understanding the architecture of the Windows operating system.

When older programmers advise learners to start with a language they have a chance of learning, it is done so the learner does not waste their time taking on a task that they have little chance of succeeding with.

If the reference material appears to be too complicated for you, learn a simpler language like C or Pacal or Basic and when you think you know enough and you have a use for it, you can then start on assembler.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jaime

Hi Hutch, thanks for your suggestions.

Thing is I do have some programming experience as I pointed out in my first post at the top of this topic. I mean I have been coding in VB, VB.Net and VBA for some time now, and I'm quite capable of creating real working commercial apps for my clients. What I was really talking about in my last post is that the suggested entry-point material is not quite entry-point at all. It's like asking for a beginner's tut for C++ and being presented with one which starts out by saying "This tutorial assumes you have reasonable experience in coding C++".

I just wanted to know how to start learning Assembly language geared toward modern-day application building, without wasting time with obsolete techniques.

Jaime

hutch--

The path from VB and similar is not an easy one as you have not worked with memory addressing to any serious degree and you will have to get the swing of API coding which is much closer to C than VB.

Start with your Intel PIV manuals for the architecture and instructions, from your VB background you should know where to access the Windows API functions. Have a look at Randy Hyde's Art of Assembler for very basic operations but make sure you do not waste any time on 16 bit DOS assembler, most of it is useless for 32 bit and the emerging 64 bit. There are very few books worth having and the best you will find is on the internet.

Have a good look through the masm32 example code and don't be afraid to look around in other masm sources as there is a lot of good code around to learn from.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ramguru

Quote from: Jaime on April 07, 2007, 02:04:51 AM
So as you can I'm still turning in circles, lost like a blind man in the midst of a gang shoot-out.
Also, all the links, for sample files etc, in the Izcelion Tutorial seem to be dead now.

http://win32asm.cjb.net/ - dead for some time
http://win32assembly.online.fr/ is still available

you're right that (donkey's) chm file refers to dead links (use this instead http://win32assembly.online.fr/tutorials.html )

I suggest you stop reading for what audience these tuts are dedicated, better READ THEM, there is nothing special that you cannot understand (very basic assembly: mov with some high-level .if-endif)

Quote from: Jaime on April 07, 2007, 07:25:17 AM
I just wanted to know how to start learning Assembly language geared toward modern-day application building, without wasting time with obsolete techniques.

There is only two kinds of application (third is coming soon 64bit): 16bit and 32bit, no such thing as modern-day application, maybe this refers to 2^32 colors, GDI+,COM if so it's still 32bit application - not far from windows 95

Jaime

Hi guys, thanks again for all the leads, advises and suggestions.

After having checked out dozens of sites and tuts related to ASM, I finally found what I was looking for at http://www.jorgon.freeserve.co.uk/ from Jeremy Gordon. This might be of interest of others in a similar position like mine, cause it really allows one to enter the world of ASM painlessly and hassle-free. You just need to download 4 tiny apps: Assemble, Res Compiler, Linker and Debugger; just throw 'em in any folder on your XP machine... no need whatsoever for installs and configs.
After that you open notepad, copy the code from the tuts on the site, save, run the resulting exe and voilà! Jeremy Gordon's aim here is to put together a working windows app in a few seconds. He then sets out to explain what every line of code does, and then you're ready for the next level tut, and so on...

So I'll be wrestiling my way through these for now, and hopefully will only need to bother you guys again with questions that are not that fundamental as the ones in this topic. I of course will still be checking out this forum regularly, just to keep in touch and get more acquainted with the subject at hand.

Regards to all of you

Jaime

sebart7

Easy way of learning assembly with a help of VB

First, i will not agree here :
Quote
(...) I'm also not sure if there's still any practical need for ASM today (apart from Reverse Engineering).(...)
Computers will never be as fast as we want them to be. Each time when You will create more complex routine,
it will work more and more slow. (Im sure that You allready encountered this problem many times) ...Up to the place where You will think "no it have no point, thats way too slow i have to rewrite it somehow different way". Here assembler comes. You should think : "Yup, it cant be done efficient in this language, there is no way but use assembler here instead." And it do help. I say more. Procedure that was executing in VB for 5 hours, in assembly can finish in 0.2 seconds. And thats not a joke. Thats what assembly is about. Its not that comfortable like VB but its ONE and ONLY solution to make Your complex-routines as fast as possible. Also in assembly You can have easy access to many things that are under "skin". The things that You normally cant access or manipulate that "easy" from high-level languages. With assembly You can do all-these-tricks. Here, programming language is no more a limit of Your creativity. In assembly, only limit is You and Your own creativity.

If You allready coded something in high level languages then You do have allready idea what programing is about.
Programming is not realy about language You use. Its about special-way of programmer thinking, Ability to build a virtual alghoritms,
where programming language is used only to write it down and make it reality.
Thats why i think You have good start, because You do build these algoritms allready. All You have to do now is to expand
available to You ways of expressing (writing down) Your ideas, and as You can see its NOT a reverse engineering but creating a new things, without high level languages limits. (especially poor speed while You let Your imaginations fly too high)

I will agree with Hutch :
Quote
(...) The problem has always been what is the bottom line as an entry level. Assembler programming is not a programming beginners area as it is complex and abstract area combined with the need to understand the range of Windows API programming which in itself is a large and complex area. It means understanding a large instruction set in assembler as well as understanding the architecture of the Windows operating system. (...)
It is Extremely true that assembly language by alone is not just language itself, but deep knowledge and understanding of environment in which it executes. And Windows itself inside, is an area where You can dig for years and still be amazed each time when You will find new thing or a way to do "something better/different way". (Especialy while Microsoft like to hide "things" or be slow to provide technical documentation, related to not realy-clear-explained areas).

However, i believe that You can learn assembly language with help of Your actual knowledge, and go step by step more deep in time.

For a while, let VB care about "system-things" for You, while You will learn first about assembly itself.
You can interface Your VB program directly with assembly code by use of DLL modules.

In begining You should learn about what is memory and how data is stored in memory. I not meant all system stuff,
I meant just a simple memory model and data in it. Open any binary file with hex editor, and imagine that its a small virtual memory.
You can see many numbers stored in there. Thats data. In real, all that You/program/computer do is manipulating these numbers
in memory. All are numbers and memory. When You type in VB someString$ = "abcd", in real this "abcd" are 4 numbers that system store somewhere in memory. You can manipulate this string, make it uprcase, cut, expand ect. But still all that realy hapens is
manipulating fiew (here 4) bytes that are stored somewhere in memory. VB care for You, about where exacly it is stored, protects occupied by this data memory area so nothing can overwrite it, and all other things, but in assembly its You who must allocate some
memory space, put this data there and remember where it is. Also remember to free unused memory area when You no more need it.
So, basicaly program is a memory, some data in it (numbers), and a program that manipulates these data in memory. Thats all :)

Now more about data. You have to learn what are hex (and bin) numbers, because computer NOT use decimal values.
All data stored in memory are HEX values (exacly as HEX-Editor show). So, hows it that You see decimal values in program/game ect?
Because program/computer/(You) convert data to human readable form before show off. You can also learn about ASCII codes.

After You know what is memory, data stored in it, You can learn how to manipulate it by use of assembly language.

You allready know what are Procedures in VB. You can pass to them any data, process it inside and return some data.
We will do exacly same with that "small" diference where called procedure will be in assembly :)
Here You can experiment with manipulating data with assembly, while learning assembly mnemonix, syntax, rules, registers, ect.
After You will understand assembler itself and the way how it do-things, You can start to carefuly exploring windows
and the way it work "inside", by "leaving" Your "safe area" by calling windows API and accessing "outside-things" directly from inside Your assembly procedure.

All the rest are time, experience, and things You will need. When You create "something" try to not stop thinking "thats imposible" or "i dont know how to". Go a little beyoud Your knowledge, and when You encounter that point, search for salvation in technical documentation or invent it by Your self. After time You will see that You went more far than You was even imagine at begining.
------------------------------------------------------------------------------------------------------------


Here i atach sources pack that let You research and start assembly learning :
Its a simple VB6 aplication that call pure assembly code stored in DLL
(This will free You from worrying about windows/buttons/ect handling (VB will care about it for You)
while You can immediately concentrate on learning assembly in DLL framework.)

You need VB6 to open VB part of project (AsmExample.vbp)
And RadAsm IDE to open assembly part of project (vbdll_Example.rap)

While You allready know VB, You will have no problems in analysing the way of interfacing VB with assembly DLL
After this You can start to learn/research assembly language by analysing/changing/or even create Your own aditional procedures
directly in pure assembly and compile it as DLL.




[attachment deleted by admin]

Jaime

Well Sebart I thank u for the time u took to write me this "apology" of ASM, I really appreciate. I will of course be looking into your sample code and I'm sure I'll get a lot out of it. Like u said, it'll take some time, especially since I have rather little time left for study. But little by little we'll be getting there, I'm sure.

Regards
Jaime