Regarding For Assembly Language

Programming, for all ages and all languages.
ankitdixit
Posts: 1
Joined: Thu Sep 24, 2020 1:51 am

Regarding For Assembly Language

Post by ankitdixit »

Hello All, Can anyone help to find best assembly language tutorial in free or paid version? I am an intern and working on some online projects where i need to explore more about assembly language. Please suggest me.
FranchuFranchu
Posts: 8
Joined: Fri Jan 31, 2020 7:28 pm

Re: Regarding For Assembly Language

Post by FranchuFranchu »

Tutorialspoint has a good tutorial for x86 Linux assembly programming. It teaches basic NASM syntax and concepts. https://www.tutorialspoint.com/assembly_programming/
MikeOS (a real-mode x86 OS) has a tutorial for developing applications for it (maybe it's easier for you): http://mikeos.sourceforge.net/handbook-appdev-asm.html
MikeOS also has an introduction to make an real mode OS from scratch (again, in x86): http://mikeos.sourceforge.net/write-your-own-os.html

You might need a VM to follow the tutorialspoint tutorial, and it's a good idea to use VM for the MikeOS ones.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Regarding For Assembly Language

Post by bzt »

Hi,

I'd strongly suggest to take a look at flatassembler. It is one of the best assemblers out there, and its documentation has many useful examples and tutorials.
It also has a very friendly and helpful community, and they post tutorials regularly on their forum. You can find examples for literally everything, starting from a boot sector to a complete SDL game engine.

Cheers,
bzt
rdos
Member
Member
Posts: 3279
Joined: Wed Oct 01, 2008 1:55 pm

Re: Regarding For Assembly Language

Post by rdos »

The problem with these different syntaxes is that once you start to use them you cannot switch. So people get locked into assemblers, and when and if they are no longer developped, the code will become useless or hard to build.

I use the TASM ideal mode (actually WASM, but it is TASM compatible). I think memory references should use [] and that offset should be used to indicate that you will use the address rather than the data. In NASM, just using a variable will translate to using the address. I have kind of prepared for this problem by always using segment overrides on memory operations even when not necessary as this should trigger errors when expecting an address. This also overrides the assume directive in ideal mode which can give unpredicatable results.

So, I think all these assembler variants are quite unfortunate.
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: Regarding For Assembly Language

Post by PeterX »

rdos wrote:In NASM, just using a variable will translate to using the address.
I'm not sure if I understand you right.
I think

Code: Select all

mov rsi, label1
will put the offset of label1 into the register while

Code: Select all

mov rsi, [label1] 
will put the data at that offset into the register.

EDIT: Maybe you mean MASM/TASM?

Greetings
Peter
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Regarding For Assembly Language

Post by bzt »

rdos wrote:The problem with these different syntaxes is that once you start to use them you cannot switch.
I can only speak for myself, but for me this was never an issue.

I've started Assembly for x86 with MASM, then I switched to TASM. I've used that for a long time. Then when I migrated to Linux, I've played a bit with NASM, but that wasn't for my liking really. These days I'm using FASM (Intel-like) and GAS (AT&T) regularly in parallel, and I have no issues whatsoever with the different syntax (except that FASM's syntax is far more superior, I miss a lot in GAS, but I can always manage).
PeterX wrote:EDIT: Maybe you mean MASM/TASM?
Sounds more like GAS I think.

Cheers,
bzt
User avatar
bloodline
Member
Member
Posts: 264
Joined: Tue Sep 15, 2020 8:07 am
Location: London, UK

Re: Regarding For Assembly Language

Post by bloodline »

rdos wrote:The problem with these different syntaxes is that once you start to use them you cannot switch.
I kind of agree with this. The only assembler I’ve ever really done is on the 68000, and the convention there is opcode.size source, destination (linguistically it’s the imperative in English: Verb subject object - Add D0 to D1 ) so over the past month where I’ve been doing a lot of x86 I’ve found AT&T syntax much easier than Intel syntax. I only use GAS which supports both styles, but I find it so much slower to parse Intel syntax.
A good asm coder would have no problem reading either.
CuriOS: A single address space GUI based operating system built upon a fairly pure Microkernel/Nanokernel. Download latest bootable x86 Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip
Discord:https://discord.gg/zn2vV2Su
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: Regarding For Assembly Language

Post by PeterX »

bzt wrote:I'd strongly suggest to take a look at flatassembler. It is one of the best assemblers out there, and its documentation has many useful examples and tutorials.
It also has a very friendly and helpful community, and they post tutorials regularly on their forum. You can find examples for literally everything, starting from a boot sector to a complete SDL game engine.t
I had a look at it and it is impressing. For example they have a gtk GUI example. And many other examples.

rdos is probably right, because I still won't shift from Nasm to Fasm.
But it is possible to understand different Assemblers and different syntaxes. I can read AT&T syntax despite being a Nasm user/fan. I can recommend the method I mentioned elsewhere: Try very hard to understand the different syntax (and fail) and then put it aside for two weeks or whatever. Then try to understand it again. You will probably notice that your brain is more ready for the topic than it was before. Maybe you need more than two tries, but in the end it works (for you, too, I hope). So I learned to read Lisp. And I must say first Lisp was a kind of parenthesis hell for me...!

Greetings
Peter
User avatar
eekee
Member
Member
Posts: 872
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: Regarding For Assembly Language

Post by eekee »

bzt wrote:I'd strongly suggest to take a look at flatassembler. It is one of the best assemblers out there, and its documentation has many useful examples and tutorials.
It also has a very friendly and helpful community, and they post tutorials regularly on their forum. You can find examples for literally everything, starting from a boot sector to a complete SDL game engine.
I may very well do that myself. I like things about Nasm and it's very widely praised, but Nasm's forum is practially dead, probably because it requires completion of a painful captcha for every post. Besides, I've heard Fasm (the common name of flatassembler) has some technical advantages.
rdos wrote:The problem with these different syntaxes is that once you start to use them you cannot switch.
Switching anything you use daily is an interesting topic with neurological and psychological aspects. I had trouble with keyboards. Occasionally I still do. To some extent it's possible to improve your switching skills, but mostly I think that's just a case of learning not to confuse the separate... muscle memories. We need a term for things which are exactly like muscle memory but not related to actual muscles.
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: Regarding For Assembly Language

Post by PeterX »

eekee wrote:
rdos wrote:The problem with these different syntaxes is that once you start to use them you cannot switch.
Switching anything you use daily is an interesting topic with neurological and psychological aspects. I had trouble with keyboards. Occasionally I still do. To some extent it's possible to improve your switching skills, but mostly I think that's just a case of learning not to confuse the separate... muscle memories. We need a term for things which are exactly like muscle memory but not related to actual muscles.
I could name it reflexes or instincts. But you probably mean the unconscious, the automatisms.

All I can say is: The human mind can learn many things. And it seems to me that there are four rewards when you are programming:
(a) Learning new things and (b) achieving results. And maybe (c) the process of coding and (d) the process of planning and designing.

I suggest to every Asm coder trying to learn both Asm syntaxes.

Also note that someone implemented into Gas 99% compatibility with Nasm (including Intel syntax).

Greetings
Peter
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Regarding For Assembly Language

Post by bzt »

eekee wrote:Besides, I've heard Fasm (the common name of flatassembler) has some technical advantages.
Indeed it has!
  • It is written in fasm, compiles itself
  • Being written in Assembly, extremely fast (I mean seriously, VERY VERY fast)
  • Supports virtually all formats (ELF, PE, COFF, AOUT etc. etc. etc.)
  • Easy to port (available for Win, Linux, MacOS, BSDs, and there's a special bootstrap version which only needs to be linked with your OS' libc)
  • Comes with a powerful IDE (sadly Win only)
  • Full instruction support, up to the latest CPU features
  • It's macro system is one of the best I've ever seen, and I've seen a lot. I calculate BIOS ROM checksum with its macros on-the-fly for example :-)
Actually there's a next generation of fasm (fasmg), where even the instructions are implemented as macros, therefore you can switch CPUs with a simple include. (fasm was originally written for x86, but there's a fasm-arm version too. With fasmg you can assemble for both x86 and ARM, and even for M68k etc. This flexibility comes at a price though, fasmg is slower than fasm, but still pretty fast).

Cheers,
bzt
rdos
Member
Member
Posts: 3279
Joined: Wed Oct 01, 2008 1:55 pm

Re: Regarding For Assembly Language

Post by rdos »

eekee wrote:
rdos wrote:The problem with these different syntaxes is that once you start to use them you cannot switch.
Switching anything you use daily is an interesting topic with neurological and psychological aspects. I had trouble with keyboards. Occasionally I still do. To some extent it's possible to improve your switching skills, but mostly I think that's just a case of learning not to confuse the separate... muscle memories. We need a term for things which are exactly like muscle memory but not related to actual muscles.
It's not so much the psychological aspect of learning something new rather that the code you already wrote doesn't compile or even worse, compile but then doesn't work since the new assembler has different rules.

An example is this:

mov eax,some_var

In TASM syntax this means load eax with the value of some_var while in nasm it means load eax with the address of some_var. Both of these assemble correctly in both TASM and NASM, but produce different code. So, if you have a large codebase in TASM syntax you cannot switch to NASM if you use this syntax since you would need to go through every line of code and check memory references.

FASM seems completely useless since it only produces flat binaries. Even if it didn't, letting the assembler rather than the linker produce the executable is generally a bad idea.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Regarding For Assembly Language

Post by bzt »

rdos wrote:So, if you have a large codebase in TASM syntax you cannot switch to NASM if you use this syntax since you would need to go through every line of code and check memory references.
So by "switching" you don't meant a programmer multiplexing between projects with different syntax, but actually converting codebases? I can assure you, that sucks with all languages and syntaxes, no matter what.
rdos wrote:FASM seems completely useless since it only produces flat binaries.
Now where did you get that? FASM can generate lot more kind of object files than NASM. Look up "format" directive in the documentation.
rdos wrote:Even if it didn't, letting the assembler rather than the linker produce the executable is generally a bad idea.
First, why? Second you can produce linkable objects just as well as executables, DLLs and shared objects. Just a matter which options you use for the "format" directive.
Here is an example which produces an .obj file then links it with an MSVC compiled .obj to produce the final executable.

Cheers,
bzt
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: Regarding For Assembly Language

Post by PeterX »

bzt wrote:Now where did you get that? FASM can generate lot more kind of object files than NASM. Look up "format" directive in the documentation.
http://flatassembler.net/docs.php?artic ... _manual#14 says:
Currently the only available choice is "format binary"
I hope this is outdated and false.

Greetings
Peter
nexos
Member
Member
Posts: 1078
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Regarding For Assembly Language

Post by nexos »

PeterX wrote:
bzt wrote:Now where did you get that? FASM can generate lot more kind of object files than NASM. Look up "format" directive in the documentation.
http://flatassembler.net/docs.php?artic ... _manual#14 says:
Currently the only available choice is "format binary"
I hope this is outdated and false.

Greetings
Peter
I think that manual you pointed to is for fasmg.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Post Reply