#### Archived

This topic is now archived and is closed to further replies.

# Assembly language

This topic is 5430 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I have started to learn programming in c# and am getting quite far with it. The only other programming language experience i have before this is c. I am interested in learning how my code actually works and many people have suggested learning assembly language. I would like to start learning it but i dont know which assembler to choose. I was just reading a page with a book called " art of assembly language" and it teaches with an assembler called hla (High level assembler). The author wrote a page called which is the best assembler. After reading that I am persuaded to go with hla although the author is obviously biased towards it because he wrote hla. Are there any asm programmers here that could give me some advice? Any help would be greatly appreciated, Thanks

##### Share on other sites
My favorite assembler is NASM
and it''s open source !

Matt

##### Share on other sites
If we''re talking Windows assembler here, I''d say have a look at MASM32. It has plenty of macros to simplify some of the more mundane tasks in assembly (though you''re free not to use them). It comes with utilities that will even help you implement class structures in assembly (though I never used it other than a quick check out). Other than that it''s free and well documented.

##### Share on other sites
An assembler might not be the thing you want. Consider, if you''re interested in learning about how your code actually works, why not direct your compiler to dump a listing of assembly code generated from your C source? (and maybe your C# source too). Of course, you''ll still need to understand assembly language, to make sense of the listing, but you don''t need to compile assembler to read it.

AoA is a great assembler reference too, hla or no. Also download the 3 volumes of the "IA-32 Intel Architecture Software Developer’s
Manual" -

24319002.pdf - vol 1
24319102.pdf - vol 2
24319202.pdf - vol 3

##### Share on other sites
Thanks guys, I decided to go with hla, it is an assembly language that gets conveted to masm and masm does the rest. Masm seems like the best choice to learn if you want to be a pro asm guy but since i just want to learn how code works in higher level languages i think hla will be fine.

Anyway, there is something i dont get. If assembly language is code the machine can read directly, wouldn''t there be a different language for every different processor out there? Will asm code i write for windows work with all other versions of windows? I dont get it.

Also, can c# work with assembly? Say i had a program in c# that asked how to add 2+2 , could code i wrote in assembly and compiled to a dll calculate that and be called from c#?
Sorry if that sounds stupid, i am totally new to asm.

Thanks again

##### Share on other sites
assembly language is one step above something what is often called "machine" language, which is what the assembly gets turnd into, basically each assembly instruction gets turned into a binary opcode instructions which is native to the machine.(*)
so, yes, each machine has a different "language" but, similar types of machines all understand the same bits of language. so all 386,486,pentium,etc understand the 286 "language"

because windows is most commonly run on intel x86 machines, then as a general rule, your asm code will work with most other versions of windows.

I dont know about C#, but in C++ you can just make a __asm {} comment and write your inline assembly code there. I think this would be the easiest way to experiment with assembly.

(*)although this isn''t actually always true, its easier if you just believe it is.

##### Share on other sites
quote:
Original post by Elite19
Anyway, there is something i dont get. If assembly language is code the machine can read directly, wouldn't there be a different language for every different processor out there? Will asm code i write for windows work with all other versions of windows? I dont get it.

You absolutely do get it. Assembly is inherently non-portable and it is not only a different language for every different processor the syntax of the assembly for the same CPU can vary by platform and compiler. All a HLA can do, is teach you central concepts. Many people (jokingly) call C portable assembly.

One of the reasons Intel has captured so much market share, is because they have made all of thier CPUs backwards compatible for over twenty years now. 808086 programs can run on a Pentium 4.

Assembly describes a class of languages that are one level removed from machine code. Assembly must be compiled, using an Assembler - it is said that "The Assembler assembles the assembly." Modern assemblers are macro assemblers, meaning you can effectively write functions. Assembly consists of mnemonics that represent similar operation codes (op codes or machine instructions).

The assembly mnemonic is the same, mov, but the machine code is not:
assembly: mov eax, 2hex:      B8 02 00 00 00binary:   10111000 00000010 00000000 00000000 00000000 assembly: mov edx, eaxhex:      8B D0binary:   10001011 11010000 assembly: mov eax, edxhex:      8B C2binary:   10001011 11000010

You can (and people once did) program in machine code. You key in the program, one byte at a time. You have to figure out the addresses to jump to and remember at what offsets data is stored. You can do this right now on any DOS or Windows PC, by running 'command.com' then 'debug.exe' and start entering op codes in hexadecimal to create a .com file. The code starts at offset 0x100 (the first 256 bytes are used for the com file header).

quote:

Also, can c# work with assembly? Say i had a program in c# that asked how to add 2+2 , could code i wrote in assembly and compiled to a dll calculate that and be called from c#?
Sorry if that sounds stupid, i am totally new to asm.

I think you would write:
int x = 2 + 2;

But yes, you can create a dll using an assembler, or a C or C++ compiler and inject assembly instructions then call it in your .Net program – I think you would use p/invoke to do think.

[edited by - Magmai Kai Holmlor on November 7, 2003 2:50:08 AM]

##### Share on other sites
quote:
An assembler might not be the thing you want. Consider, if you''re interested in learning about how your code actually works, why not direct your compiler to dump a listing of assembly code generated from your C source? (and maybe your C# source too). Of course, you''ll still need to understand assembly language, to make sense of the listing, but you don''t need to compile assembler to read it.

AoA is a great assembler reference too, hla or no. Also download the 3 volumes of the "IA-32 Intel Architecture Software Developer’s
Manual" -

24319002.pdf - vol 1
24319102.pdf - vol 2
24319202.pdf - vol 3

I agree. Looking at my code through the debugger is always insightful. It may be better if the code dump is shown step by step, beginning to end.

==================
Benjamin Heath
==================

##### Share on other sites
Wow, thanks Magmai. That helped heaps. I am finding assembly very interesting. One thing i''m wondering about though is, do many people out there use it? I mean, it seems like the fastest code you can write is asm other than "machine code" itself. Is it still usefull knowledge to have and wil computers in the future make the asm of today obselete?

##### Share on other sites
Thanks Lessbread and Benjamin, I somehow totally missed your posts. That sounds like a good idea but i would still like to play around with asm just for fun(I''m such a nerd)
That just made me think of something else, if high level languages like c++ get conveted to assembly, why would they be slower than assembly programs if they become asm programs anyway? I mean, if you wrote a hello world program in c++ then compile it, it becomes just the same as if you would have wrote hello world in assembly to start with wouldn''t it?

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
16
5. 5

• 9
• 33
• 13
• 12
• 10
• ### Forum Statistics

• Total Topics
632575
• Total Posts
3007154

×