News:

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

Where do I start learning Assembly?

Started by Walkingtheunwalked, August 18, 2009, 01:11:02 PM

Previous topic - Next topic

Walkingtheunwalked

2-B-chip, the program with your modification triggers an error message when trying to assemble in sol_asm. It has already been pointed that the two code variants are equivalent, so there's nothing else I can add as a comment on it.

I have downloaded masm32 hoping it has a good help file and documentation, and I will have a through look at them tomorrow.

Quote from: BogdanOntanu on August 19, 2009, 08:35:16 PM
Hence if you intend to ask questions here then it is much better to learn and use MASM syntax. For Sol_asm syntax questions I do recommend Sol_Asm's forums.

Hi Bogdan and glad to see your reply,

Yes, I had the intention to open this subject on the Sol_ASm forum too. Will keep in mind your suggestion.
Quote
However while you learn you have a better chance here because I am known to be harsh
When I have opened this thread, I have decided to take a risk. I feel vulnerable: while talking openly and not trying to hide what I don't know and not trying to appear to know what I don't, I am exposing myself to the risk of being ridiculed and the questions I ask to be considered silly by some (see hutch's reply).

I for myself am convinced that many more have trouble getting started with ASM, because they can't find answers to their basic and logical questions in the available books and tutorials (which means the documentaions available at the moment aren't sufficiently good), and am sure that some of the more experienced users here, too, have things they are unclear of in ASM programming.

QuoteIn order to  output a number value instead of a string you will have to:
a) convert the value/number to a string with a procedure you write or by using a library function. Among many other such functions MASM32 has a dwtoa procedure in it's includes ... if I recall correctly.
b) Output the resulting string.
Thank you!

What I had in mind when I asked this was that I wanted to start familiarising with the general instructions and I needed to be able to output the content of registers/memory locations in order to check what I'm doing.

I will try to figure out myself how to output this. Still, the fact that none of the other users wrote how to do this before makes me wonder if this doesn't prove what I said before: that even the more experienced users have an unclear understanding of how ASM works...

Quote
If you write your own OS or use DOS/emulator you will anyway end up creating and using a set of common functions. 
Such a set is already provided by most operating systems API.
Quote
I had realized that, eventually. But have also seen that almost all of the Windows programs use loads of "import func", which gives me a feel that it's not actually the programmer who creates the program, but rather those ready-made functions do the hard job... and the Windows/Linux programmer's task is reduced to combining the use of those functions!

BogdanOntanu

Quote from: Walkingtheunwalked on August 20, 2009, 09:05:30 PM
2-B-chip, the program with your modification triggers an error message when trying to assemble in sol_asm. It has already been pointed that the two code variants are equivalent, so there's nothing else I can add as a comment on it.

You have to understand that people here are not familiar and not concerned with Sol_Asm syntax. This is a forum dedicated to MASM/MASM32. yes you did mention sol_asm in your post but you will get answers that are pertinent to MASM and it is your task to convert them to sol_asm syntax if you wish to.

Each assembler has it's own syntax and this can be a problem when you are learning the basics.

Quote
I have downloaded masm32 hoping it has a good help file and documentation, and I will have a through look at them tomorrow.

There is some documentation but as Hutch mentioned it is not targeted at beginners that have no experience with programming. In this case you will have to compensate (a lot) by your own efforts and understanding and of course by asking questions.


Quote
When I have opened this thread, I have decided to take a risk. I feel vulnerable: while talking openly and not trying to hide what I don't know and not trying to appear to know what I don't, I am exposing myself to the risk of being ridiculed and the questions I ask to be considered silly by some (see hutch's reply).

You will be protected a little here in the Campus sub-forums. However you must no be very "sensible". ASM is for people that can stand up on their own feet/mind many times against common people concepts.

Hutch expressed his own opinion that it is hard to learn ASM when you have not mastered another high level programming language first. His intentions are good and experience here shows that very often he is correct.

I do have a different opinion since I consider that I can teach somebody ASM in a few hours and it takes only a few weeks until one becomes a master in ASM if he/she works honestly.

However my opinion is based on my own experience when I do teach face to face and hands on because it can observe people's reactions and anticipate their needs... in forums and on the internet ... things might go differently.

It is OK to ask questions when you do not understand something. If you ask then you are "vulnerable" and "exposed" for  5 minutes or until the answer arrives or until you understand. However if you do not dare to ask the question (even to yourself) then you will be "stupid" for the rest of time.

It is also important that you do understand the answers correctly and perform personal understanding and efforts. It gets relatively annoying when some characters here keep asking the same kind of questions repetitively or ask new questions that clearly show that thy did no understood the previous answers and repeat this kind of behavior for many years :D

Anyway people here are usually kind and somebody will be there to answer you with patience. occasionally there will be somebody to answer harshly (maybe me). Just do not get into flamewars or arguments or in the Colloseum sub-forums of because there is "blood on the walls" in there :D

Quote
I for myself am convinced that many more have trouble getting started with ASM, because they can't find answers to their basic and logical questions in the available books and tutorials (which means the documentaions available at the moment aren't sufficiently good),

maybe they did not serach corectly. There are many tutorials and documentations on the internet but ASM is one of those programming languages that are harder to grasp by tutorials or documentation. Then each assembler has its own syntax and quirks that mean nothing to the "other" assembler and you find tutorials in many different syntaxes.

Because of this you need to be able to understand things by yourself.

As a method: parse all info in fast forward mode. Skip any complicated things that you do not understand at first. Establish a set of basic concepts that you can understand and collect information and new concepts around this core kernel that you understand until it will enlarge and "engulf" and "light" the darker areas that you did not understand at first.

Very often people become stuck or obsessed into some concept they can not grasp at some point in time and either loose a lot of time with it or get frustrated and abandon.

Instead one should move forward and do repetitive passes over the available docs and concepts improving his knowledge base incrementally.

Quote
and am sure that some of the more experienced users here, too, have things they are unclear of in ASM programming.

A huge error of beginners is assuming something about other people. Assume nothing!

I, for one  have nothing unclear about ASM. There are differences in opinions in between me and other experienced ASM programmers ... some times very harsh differences... but that is all. 

Then there there are beginners that are too fast in assuming that they understand something when in fact they do not. Also sometimes the more experienced ASM programmers will not answer because they are busy with real life and you will get answers form intermediate or newbies.

Or sometimes I just smile at a question and not answer it on purpose.... silence is sometimes a much more powerful answer than information feeding.

Assume that answers can and will be wrong at times but this is ok because the learning process is 2 way: while you learn others will learn also.

Quote
What I had in mind when I asked this was that I wanted to start familiarising with the general instructions and I needed to be able to output the content of registers/memory locations in order to check what I'm doing.

You can also use OllyDbg version 1.10 for this (a well known debugger). You can see each instruction as it is executed step by step and you can see the values of the registers and flags as they change.

Quote
I will try to figure out myself how to output this.

You should... after all it is basic info. You have that sample above that does write a string to the console. All you have to do it to find a procedure or function that converts an register or generally a number into a string in a certain base/format and then print that string. I guess MASM32 package has a lot of such samples/examples and available functions. You just need to search and find them.


Quote
Still, the fact that none of the other users wrote how to do this before makes me wonder if this doesn't prove what I said before: that even the more experienced users have an unclear understanding of how ASM works...

Well maybe you did not ask the correct question. Many times the people that answer will answer the way they want to and not the way you want them to because they can not read your mind. You need to be extraordinary clear and exact in your questions.  After all it is their time and their knowledge they expose and if the question is unclear they might simply skip or answer vaguely.

Many other times newbies will answer fast but wrong. You need to filter this and to learn how to ask questions the smart way in order to obtain your answer.

For example that fact that you mentioned Sol_Asm and used Sol_Asm syntax on an MASM forums is not very "polite" and as you can see it did generated a few relatively "wrong" answers. However in this process I guess that 2-Chip did learn that you can not double indirect on x86 with mov [my_var],eax ... hence learning was served even if you did not get your answer fast.

Quote
I had realized that, eventually. But have also seen that almost all of the Windows programs use loads of "import func", which gives me a feel that it's not actually the programmer who creates the program, but rather those ready-made functions do the hard job... and the Windows/Linux programmer's task is reduced to combining the use of those functions!

Wrong.

Yes you do have to interface with the target OS. Sometimes there is a lot of interface (in GUI applications) and other times there is less interface (as in console applications)  but it is not this interface that is the essence or core of an application unless it is just a sample about how to use that imported function or a GUI/interface element.

The core algorithms are the essence of an application and those are usually written in your own functions/procedures that have little or no interaction with the OS. Of course that when your program does nothing or very little (like in tests or samples) then you can get such a wrong conclusion but that is superficially thinking.

Those functions that you "import" are either utility functions that you could have eventually written yourself (but most people do not bother with doing it because they are already done by the OS ...) or are functions needed to interface with the OS API and are mandatory but not of the essence.

The algorithm behind your interfaces is of the essence and it does not matter if you write it in ASM or C or C++ or Pascal other HLL. But beware that on those forums we do prefer to write it in ASM and consider this to be more simple ;)

The rest is glue code that can be annoying at times ... until you write your own OS and you become annoying to others :D
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

mitchi

Like hutch said, learning assembly can be very difficult for some, this is why very few bother to learn it. I consider myself pretty good at assembly programming and yet I feel much more comfortable programming the bulk of my work in C.

There is a lot of documentation out there, from various sources. I've seen much more documentation on learning the various tricks of Assembly then with C. With C, it's always about the basic if/else and pointers. C tutorials always focus on teaching you the pointers because it's really harder to understand them with C.

With Assembly language you will really learn what a pointer and an address is. And then you'll see how the concept of variable in C is interesting because it's not a register nor memory, it can be both.

Good luck at learning assembly, get Ollydbg and start writing small ASM programming exercises. The type of exercises you would do in first year of programming at school.

hutch--

Walk,

I may sound a little blunt with my comments but it comes from many years of experience dealing with people learning assembler programming. With 32 bit Windows you are fighting 3 classes of knowledge, the Windowes API functions and architecture, the complete Intel instruction set and processor architecture and general programming skills in terms of methods, algorithm design and just doing the basic things like getting a program up and running.

You need at the minimum the basic programming experience with a high level language, a good grasp of the architecture of Windows, experience in the Windows API functions, at least some grasp of the Intel instruction set and preferrably some experience in writing assembler and unless you have a background something like this you have almost no chance of succeeding at writing 32 bit Windows software in assembler.

MASM and similar assemblers are an advanced subject that assume a lot of experience and unless you have that experience you will be far better served by starting with a compiler like basic or C or Pascal until you have learnt enough to start writing advanced code like assembler.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ecube

http://www.masm32.com/board/index.php?board=45.0

The GeneSys Development System
An exciting new system being developed by Paul Brennick and Vortex that is directly targeted at beginner assembler programmers learning MASM.

Walkingtheunwalked

I have appreciated all of the new replies and found the information extremly useful! I started to use Genesys to write short programs and I'm happy with it. For checking what I'm doing, I use OllyDbg which I like as well, and because my objective to see the values of the registers and memory locations is fulfilled this way, I haven't searched the dll-s for a ready-made function to output these on the console. I have a few things I'm not celar of regarding OllySbg, but will write about them in a future post, not in this one.

Now, what I'd like to know is how to address specific memory locations. I have looked into several documentations, including Iczelion's, masm's and genesys' tutorials and examples and didn't find the information I wanted. Let's say I want to move the value stored in eax into a memory location or vice-versa. The way to do it that I found in masm's help file, is something like: mov [ebx+ecx*4+33],eax where the expression in the brackets (including the brackets I suppose) is a pointer to a location. Now, how can I calculate which location is this exactly, if I can't use the direct address? And more than this, I want to find out more information about how my computer's 1GB ram memory is organized and "mapped": which are the areas (from where to where) and what each of them can be used for.

I would like to give an example of what I've done at the course (I'm a student) relating to ASM programming and my memory map question, and also write this as a reply to hutch's posts, detailing a little more about my experience with programming. We have been taught ASM programming of the Motorola 6811/6812 microprocessors, having this book - follow the link for the preface of the book - as a support for the class. We have been taught to write programs like this one, in which we would configure the microprocessor's I/O ports - in the program that I've put the link for, you can see in the line PTT  equ $0240 that the memory is addressed directly; this line associates label "PTT" to the 0240 memoty location .  As an assigment for this class I was able to make this microprocessor+it's attached memory to receive inputs from a keyboard and display them on a monitor, and all this just by configuring and initialising the ports, and not by using any imported ready-made functions and libraries at all. We were given the technical sheets of the memory map and ports information provided by Motorola (the manufacturer).

So, what I'd like is to be able to do similar things with my laptop's resources as I did with the Motorola microprocessor and the memory and keyboard and display that we attached to it. But I'm having a hard time trying to transfer my understanding of the Motorola micro to my laptop's in order to understand better the second and I'm not even clear WHY I find it so hard!

Sorry for the long paragraph above, I have now got back to the memory addressing and memory mapping questions and invite the readers to share with me their knowledge and and comments.

Ah, and before I press the send button, I'd like to stress once again that I don't feel interest for programming Windows (or any other OS's) applications and don't want to spend time with studying Windows' API functions, but want to do the things myself and remove Windows from my laptop as soon as I'll be able.

Walkingtheunwalked

Quote from: mitchi on August 21, 2009, 02:23:09 PM
With Assembly language you will really learn what a pointer and an address is.
As I was rereading the replies, this sentence of yours drew my attention (again!). Could you go into more detail?

hutch--

Walk,

> mov [ebx+ecx*4+33],eax

Here is a little hint for you, anything in square brackets in MASM notation is a memory operand, this means information stored at a memory address.

Now if you break down the notation within the square brackets you are dealing with Intel's complex addressing mode and while it looks a bit complicated, it is very clear in what it does.

EBX = the BASE address.
ECX = the INDEX for array addressing.
"*4* = the MULTIPLIER for the indexx
+33 = additional DISPLACEMENT from the base address + index.

It all adds up as follows, the BASE ADDRESS in ebx PLUS the INDEX multiplied by the MULTIPLIER PLUS the displacement in BYTES.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Walkingtheunwalked

Hutch,

Ebx and Ecx in the memory operand, are they registers or to they have anything to do with the registers with the same name and the values stored in them? Or are they just notations that I can substitute with numeric values?

The assembler assembles a program successfully even if I don't put numeric values instead of Ebx and Ecx, although I suspect this doesn't make real sense, unless it uses some values stored in these registers. And it does assemble  if I put arbitrary numeric values instead of EBX and ECX, as well.

hutch--

Probably a good read of the Intel architecture manuals would be good for you to get the very basics, on x86 hardware in 32 bit you have 8 general purpose registers, (MMX ST,XMM are different) and they are different operand types to memory or immediate numbers.


mov eax, ecx    ; copy ECX into EAX
mov eax, [ecx]  ; copy data at the memory address in ECX into EAX
mov eax, 1234  ; copy immediate number into EAX


In response to you earlier question about notation within square brackets, you can load the address into a register and then get the contents AT THAT ADDRESS by enclosing the register in square brackets. A register enclosed in square brackets ecomes a memory operande.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ghandi

#25
Quote
And it does assemble  if I put arbitrary numeric values instead of EBX and ECX, as well.

But if you look at the disassembled code from the following two lines, you will notice a difference:


MOV EAX, DWORD PTR [12345678+0ABCDEF10h*4+32]
MOV [EBX+ECX*4+32],EAX

assembles to:

00401000           B8 AE1DF4AF       MOV EAX,AFF41DAE
00401005           89448B 21         MOV DWORD PTR [EBX+ECX*4+20],EAX

NOTE: The disassembled code is using base 16 (hex) and the MASM code is using base 10 (decimal) as well, which explains the differences in the displacement value.
HR,
Ghandi