ASM is easier than believed

Programming, for all ages and all languages.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

I thought I couldn't understand it. Now I'm learning AT&T syntax, it's actually really readable.
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post by mystran »

Like I've stated several times, I find AT&T easier to read as well, as it's very regular. A nice bonus is that you can identify registers from the % even if you didn't know such a register exists (say, you're reading code for an architecture you don't know very well).
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

while register use is more obvious in at&t syntax, IMHO memory addressing is more obvious in intel syntax as it is more explicit:

compare
foo(%eax,%ebx,0x4)
to
[foo + eax + 4*ebx]

if you know neither syntax, you can sensibly know in the second case what is being computed while you can't in AT&T syntax without looking it up.

Also, a memory access is hard to distinguish from a register access, while in intel syntax, you'll see [...] for every explicit memory operand, while in at&t "mov foo, %eax" is a memory access that reads pretty much like an immediate access.


now SIB addressing in AT&T isn't that hard to learn, but once you've seen some other dialects neither ATT nor Intel looks bad... Consider the following 68k assembly:

Code: Select all

mov.w ([foo,A3],D5.w*2,bar), -(A5)
I'll leave it as an excercise for the reader to try and figure what that does without getting the manual. :twisted:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Registers on the PDP-11 are annoying - r0, r1... sp...

Is there a version of GAS that takes Intel syntax? Can you use Intel syntax with GCC?

Either way, assembly is much easier than most say, once you take the time to learn it.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

pcmattman wrote:Registers on the PDP-11 are annoying - r0, r1... sp...

Is there a version of GAS that takes Intel syntax? Can you use Intel syntax with GCC?

Either way, assembly is much easier than most say, once you take the time to learn it.
I've posted this about a billion times, You CAN use intel syntax in C (inline)..

This is how you do it in C...
(Note that after you use Intel syntax you much switch back..)

Code: Select all

asm(".intel_syntax noprefix");
asm("mov eax, edx");
asm(.att_syntax");
And this is how you could do it in a file assembled with GAS..

Code: Select all

.intel_syntax noprefix
mov eax, edx
.att_syntax
But it's not worth the trouble, AT&T syntax is great.. 8)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
Aali
Member
Member
Posts: 58
Joined: Sat Apr 14, 2007 12:13 pm

Post by Aali »

-masm=intel will make gcc spew intel syntax

(which means you dont need to specify it in your inline asm)

it does make the build process less obvious though

and you can't mix and match with AT&T somewhere else in the code
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Post by B.E »

IMHO assembly has it's place. but only if you use it in the right manner. For example, someone could write a whole system (by system, I mean a program that is database driven) in assembly, but wouldn't be maintainable (i.e if the code need to be ported to another achecture).

If you know that the archecture unlikly to change. then Assembly is the best laguage in the world (in moderation, is even better C).
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
Tyler
Member
Member
Posts: 514
Joined: Tue Nov 07, 2006 7:37 am
Location: York, England

Post by Tyler »

mystran wrote:Like I've stated several times, I find AT&T easier to read as well, as it's very regular. A nice bonus is that you can identify registers from the % even if you didn't know such a register exists (say, you're reading code for an architecture you don't know very well).
No offense but that is a terrible reason to choose a syntax... If you don't know the ISA then you probably shouldn't be programming it. Intel Syntax is so much cleaner looking, and it actually matches the ISA instead of making up its own (movl etc)
User avatar
binutils
Member
Member
Posts: 214
Joined: Thu Apr 05, 2007 6:07 am

Post by binutils »

Yes to some human, But not to GCC
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Post by mathematician »

There may have been a time when portability was an issue with assembly language, but nowadays about 97% of desk top computers are IBM compatible PC's (much to the disgust of Mac users), and most of them are running Windows (much to the disgust of Linux users).
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Post by Colonel Kernel »

mathematician wrote:There may have been a time when portability was an issue with assembly language, but nowadays about 97% of desk top computers are IBM compatible PC's (much to the disgust of Mac users)
Uhhh... Macs these days are x86-compatible too. Where have you been?

Also, there are still a lot of high-end servers out there running various *nix flavours on different architectures. For example, the project I'm working on now involves porting code between x86, Sparc, PowerPC, Itanium, and PA-RISC. This is a big commercial project for a big customer with big $$$... portability still matters IMNSHO.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

mathematician wrote:nowadays about 97% of desk top computers are IBM compatible PC's...
...yet still only a fraction of all software engineers write software for the x86.

And allmost all lifeforms are insects.

Aren't statistics great? ;-)
Every good solution is obvious once you've found it.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Haven't you heard? 24.53% of statistics are made up on the spot?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Actually I was referring to this article and the fact that most CPUs today are 8bit... 8)
Every good solution is obvious once you've found it.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Aha... I just felt like throwing in that time-tested joke...
Post Reply