Asembly vs. C , C++, Java

Status
Not open for further replies.
I want to ask one question. I really don't understand the idea why programmers need C, C++ or Java. Assembly what is need for programmers. Right? Assembly is faster and directly communicate with hardware. No need JDK, or linker or etc.
Yeah, you just write an error-free, million line, object oriented GUI program with assembly, then get back to us. :rolleyes:

Modern compilers are far better at assembly optimization than all but the best lowlevel programmers, and don't make mistakes (well, other than compiler bugs...) The highlevel mindset also makes program design and maintenance easier.

(I posted this in both threads as I don't know which will be locked)
 

Prototyped

Ars Legatus Legionis
11,126

  • HLLs abstract away system specifics and make for more portable code[/i]
  • HLLs require far lower code volume to achieve the same thing as a much larger volume of assembly code.
  • HLLs provide structured and functional paradigms that can be semantically optimized by a compiler instead of by the programmer. This means higher productivity and less time wasted by the programmer to do things that a compiler knows to do.
  • Some HLLs also provide object oriented paradigms that make it much easier to write highly modular code with generic and specific interfaces that can reduce coupling between pieces of code. This is much harder to do at the assembly level.
  • Code written in HLLs is generally much more maintainable and easier for a maintainer to follow.


And these are only a few reasons.

Performance isn't everything. Deadlines, productivity and maintainability count for a lot.
 

Thank You and Best of Luck!

Ars Legatus Legionis
21,219
Subscriptor
Originally posted by mikeshn:
I want to ask one question. I really don't understand the idea why programmers need C, C++ or Java. Assembly what is need for programmers. Right? Assembly is faster and directly communicate with hardware. No need JDK, or linker or etc.

Assembly is different from processor family to processor family. That's why higher level languages like COBOL, FORTRAN, C, etc. were developed. Using these high level languages makes it so that you the developer don't have to completely rewrite you code or completely relearn a language each time to move to a new processor on what ever machine needs to run your program.

However I've always thought of C as just a universal Assembly language since it combines all the power of Assembly with all the ease of use of Assembly :D It's just that it will work across processor families :)

-Nathan
 

langri

Ars Tribunus Militum
1,792
Originally posted by Thanatos22:

Yeah, you just write an error-free, million line, object oriented GUI program with assembly, then get back to us. :rolleyes:

Modern compilers are far better at assembly optimization than all but the best lowlevel programmers, and don't make mistakes (well, other than compiler bugs...) The highlevel mindset also makes program design and maintenance easier.

(I posted this in both threads as I don't know which will be locked)

I gotta agree with Thanatos22, here.

Actually, I'd just like to see you write a simple data structure... like a linked list, in assembly.
 
Assembly is faster and directly communicate with hardware. No need JDK, or linker or etc.
1) Assembly isn't faster for the average programmer. It only is for the expert assembly programmer.
2) Communicating directly with hardware has *nothing* to do with assembly. Abstracting hardware is the job of the OS, not the programming language. You can access hardware directly in C, just as you can use assembly on win32 and not touch the hardware at all.
3) Assembly still needs to be linked, so you need a linker.
 
IMHO, assembly is an awesome language because it really forces the programmer to understand how the microprocessor works. It also is a good way to optimize high level code.

High level languages are more suited for "rapid application development" and low-cost, easy maintenance of applications. Assembly is better for a focused, CPU-intensive algorithm that needs to squeeze every ounce of juice from the CPU as possible.
 
Fact: you can write anything in assembly (obviously).
Fact: you would not want to write most things in assembly.

Assembly is nowadays reserved for:
- boot-strap code
- initilization code
- hardware interrupt code
- software interrupt code
- mode switches, context switches,..


And in terms of applications:
- some compilers, OS's
- many viruses, and virus detection software
- controller software
- firmware (on ROM for example)
- portions of code that need need an extra speed boost or reduction in size
- major portions of embedded code.


However I've always thought of C as just a universal Assembly language since it combines all the power of Assembly with all the ease of use of Assembly. It's just that it will work across processor families

This is not true. You can *embed* assembly into C, but then you gain no advantage because to port it, that portion has to be rewritten with the assembly of the target processor anyway. Without embedded assembly, C is not as powerful as assembly, although you can still R/W to memory, memory-mapped I/O, and registers (depending on the OS/monitor).

General application software would be too tedious and error-prone to construct using assembly language. Besides, with today's compiler technology, the old reasons for coding in assembly have all but vanished.
 
Originally posted by clasm:
IMHO, assembly is an awesome language because it really forces the programmer to understand how the microprocessor works.

What's funny is that isn't even necessarily true anymore. It seems that most processors these days are so different from the old x86 lines that they are really running quite complex interpreters to convert the machine code into how the processor really thinks internally. Most significant, I think, is how the whole concept of the low fixed number of general and specialized registers is completely unlike how the processor operates on the inside. Don't modern processors have tons of registers? I wonder if there would be a dramatic difference in code speed if assembly were more natural to the internals of modern processors.

Originally posted by petrov:
I think you guys all fell for a troll.

--sam

I'm not sure he is a troll, He's asked a lot of exceptionally newbie questions in the past. Generally I would discourage replying to questions that could be found in a faq somewhere, but there is no reason we can't have ourselves an intelligent conversation regardless of the intelligence of the question.
 

JesusII

Ars Scholae Palatinae
722
I wonder if there would be a dramatic difference in code speed if assembly were more natural to the internals of modern processors.

In a post from Paul Demone, he mentioned that x86 CPUs have about a 30% loss in performace do to the not so great qualities of their ISA (I hope I'm not misquoting him, I'm 99% sure that was the figure). But since x86 CPUs have access to the best processes and engineering they can make up for it.
 
In a post from Paul Demone, he mentioned that x86 CPUs have about a 30% loss in performace do to the not so great qualities of their ISA (I hope I'm not misquoting him, I'm 99% sure that was the figure). But since x86 CPUs have access to the best processes and engineering they can make up for it.
Hannibal might disagree with you on that one:
The main drawback to using microcode to implement an ISA is that the microcode engine was, in the beginning, slower than direct execution. (Modern microcode engines are about 99% as fast as direct execution.) However, the ability to separate ISA design from microarchitectural implementation was so significant for the development of modern computing that the small speed hit incurred was well worth it.
(emphasis mine)
 
Modern compilers are far better at assembly optimization than all but the best lowlevel programmers, and don't make mistakes (well, other than compiler bugs...)

This I'm not so sure about. Having had a look at the code generated by compilers such as Visual C++ 6 and gcc version 2.95 for the x86 Pentium II, there are many occasions when they make suboptimal choices for the bodies of loops which generally you want to be as efficient as possible.

I've often heard it said that modern optimizers are better than hand-coding on modern architectures. Either this isn't actually true, or the common compilers don't have modern optimizers :)

The highlevel mindset also makes program design and maintenance easier.

This though is of course where the advantage lies. I shudder at the thought of having to write a large program in assembly, let alone debug it.

There's also the time factor! While a human programmer might be able to hand-optimize a tight loop better than a compiler, the compiler's attempt takes a fraction of a second and hand-optimizing can take hours and hours. Usually the gains in code efficiency aren't worth it, though there are of course exceptions (like rendering engines, game AI, etc. :))
 

earl

Well-known member
3,066
I don't think Hannibal would disagree. Hannibal's statement about microcode is that implementing a uniform ISA on a range of processors was the significant jump for modern computing. However, what current processors do now is on-the-fly, in-hardware translation of the x86 ISA to the internal ISA. All this consumes, on modern x86 CPUs, about 30% of the silicon. Removing this requirement, or at least reducing it with a more modern ISA, would allow the design engineers to devote much more silicon to functional units, etc and reduce overall complexity of the execution hardware.

FWIW, Demone's opinion is shared by James Goodman, a former Intel fellow and current CS professor at the UW-Madison.

-earl-
 

Midlands

Ars Praetorian
535
Subscriptor
Originally posted by Thanatos22:
In a post from Paul Demone, he mentioned that x86 CPUs have about a 30% loss in performace do to the not so great qualities of their ISA (I hope I'm not misquoting him, I'm 99% sure that was the figure). But since x86 CPUs have access to the best processes and engineering they can make up for it.
http://www.arstechnica.com/cpu/2q00/x86future/isa-future-1.html might disagree with you on that one:
The main drawback to using microcode to implement an ISA is that the microcode engine was, in the beginning, slower than direct execution. _(Modern microcode engines are about 99% as fast as direct execution.)_ However, the ability to separate ISA design from microarchitectural implementation was so significant for the development of modern computing that the small speed hit incurred was well worth it.
(emphasis mine)

These statements aren't actually in conflict. x86 CPUs may suffer <1% from any microcode involved, and still take a 30% hit from the ISA. ISA != microcode -- you can have an ISA that gets implemented with no microcode at all and still takes a big hit just because it's a lousy ISA. (Take any RISC machine and give it two registers. There's an ISA that will penalize you and still require no microcode.)
 

earl

Well-known member
3,066
Here's an anecdotal point. Because I was just examining this, look at the x86 ISA and register starvation. You have basically 8 general purpose registers. This leads to programs full of load/store commands because they don't have enough registers. This leads to wasted time and pipeline stalls -> more wasted time.

Of course, no one would create a processor with only 8 gp registers anymore. So what you end up with is somewhere from 32 to 128+ registers and a set of register pointers. When the executable does a store followed by a load, the CPU switches which internal register the ISA register maps to, in the hopes of avoiding a future request to reload the value it was supposed to just discard.

As one would imagine, this takes a shitload of logic on the CPU itself and creates two more problems -- hand optimized code will perform very differently on different processor cores and synchronization between multiple processors gets that much more difficult.

Imagine, instead, an ISA that provided 32 gp registers (like MIPS, give or take.) There is much less call for such manipulations behind the program's back, so you have to have a lot less logic in the chip to do the work.

-earl-
 

earl

Well-known member
3,066
Horatio,

I think that the whole process (decode of x86, various execution difficulties, register renaming, recode of x86 output) consumes probably 30% of silicon, yes. And that if you didn't have to do this, that 30% could be used far more productively -- hell, just add another FPU and ALU :D

The solution that I think would be interesting is to design a new ISA (knowing full well that in 10 years people will be cursing the design tradeoffs you make.) Start making motherboards with two processors: the new processor and an old x86 processor that you feed x86 programs to. This allows you to run new/old code side by side. Note that I don't know if this is feasible; just insanely cool.

-earl-
 

Horatio

Ars Legatus Legionis
24,430
Moderator
I've seen silicon maps of x86 processors, and the decode logic doesn't take up much of the space at all. The biggest space eaters are the FPU and the clock driver. Most processors do the register renaming, and there is no x86 recode phase. The only thing the x86 decoder has to do is to disassemble each x86 macroinstruction into some number of uOps. From there, it's a standard OOO processor. I'm close to 100% certain that the x86 specific logic takes up far less than 30% of the chip surface.
 

Prototyped

Ars Legatus Legionis
11,126
earl,

This is what Itanium (and McKinley, when it's released) does. ;)

Of course, VLIW instruction sets like Itanium's open up huge possibilities in compiler- and assembler-based optimizations (in terms of scheduling, branch prediction, out-of-order execution, parallelization, vectorization, etc.), but are hard to optimize for by hand (and much harder, of course, to be targetted by a good optimizing compiler).

Itanium and McKinley carry a stripped-down implementation of IA32 in the CPU along with the IA64 implementation, for backwards compatibility.
 
The solution that I think would be interesting is to design a new ISA (knowing full well that in 10 years people will be cursing the design tradeoffs you make.) Start making motherboards with two processors: the new processor and an old x86 processor that you feed x86 programs to. This allows you to run new/old code side by side. Note that I don't know if this is feasible; just insanely cool.

-earl-
Given the ongoing increase in performance, I'd say that emulation of the old ISA via software would be much more economical, practical, and simple. Oh but wait, it's already been done, and quite a while ago! (Digital FX!32 is what I'm talking about.)
 

magic_p

Ars Tribunus Angusticlavius
9,027
This statement was obviously not thought through very well. In general Computer Scientists "Ace-in-the-Hole" has been the fact that computer scientists can use abstraction. Using assembly language defeats that purpose. It does have it good points, being that with it you can talk directly to hardware and control basically everything.

However, it also has many downfalls. First, an assembly program gone wrong could easily overwrite your BIOS code for the motherboard or any other device that has a PROM (Programmable ROM) of some sort. This destructive nature also makes assembly dangerous. Given programming languages like C don't have much memory protection, the debugging environments and compilers will enforce some memory protection.

Take a class in modern operating systems. I guarantee after you are finished you will praise C or Java for what it can really do. I dare you to write a TCP/IP stack in assembly. "If" you have fingers left and you are still sane, and it works I'll give you a cookie, then tell you to write it again in C. The code will be so much easier to read and easier to write. Java is to the point where sockets are so well abstracted away that you declare one, then use a few member functions to write and read from the socket.

A few hours after reading some RFCs and you have an http server.

The one thing that makes high level languages so powerful is that you write a function, make sure it works correctly in all situations, then build on top of that. The abstraction and ability to do that is a power tool. Without abstraction we wouldn't have any of the modern operating systems we have now, and the code for them would easily be hundreds of times larger and more complicated. You also woulnd't have fixed the Y2k problem on time. Can you imagine sifting through assembly code that you didn't write and figuring out what is going on? I have enough trouble going through COBOL code. Assembly is even worse.

It's not a coincidence that sockets were invented just after the C programming language was invented. C was the first langauge powerful enough to create something liek sockets. Assembly would be too complicated.
 

earl

Well-known member
3,066
euzeka: macs did it as well with their switch to a different architecture a while back. Or at least partial emulation...

However, the nice thing about actually putting a whole legacy CPU on the motherboard is the CPU is cheap and *no* speed degredation.

Horatio: I could be misinformed. I'm just remembering from my design classes and the aforementioned opinion. I'll do a little more digging on my own.

-earl-
 
euzeka: macs did it as well with their switch to a different architecture a while back. Or at least partial emulation...

However, the nice thing about actually putting a whole legacy CPU on the motherboard is the CPU is cheap and *no* speed degredation.
I know about the macs ;) I've even had to deal with code still using some of the old interfaces (yuck!).

I don't quite agree with you on not loosing speed by using an actual CPU though. The odds are that the CPU with the newer architecture will be faster and able to emulate the older CPU at least as fast as actual old silicon (that was the case with the Alpha anyway). And the gap would only continue growing, making the solution of having a 2nd CPU ridiculous after a few years.
 
The odds are that the CPU with the newer architecture will be faster and able to emulate the older CPU at least as fast as actual old silicon (that was the case with the Alpha anyway).
It wasn't the case with FX!32 (tho' the Win2K for Alpha version was meant to be both better-integrated and more efficient, so perhaps it was a more useful speed), though I think it was the case with Apple's 68K to PPC transition.

The problem is, an Alpha just isn't that much faster (if it's even faster at all) than the current fastest x86 processors.
 

warmachine

Ars Tribunus Militum
2,479
Subscriptor
I've had very little exposure with assembly but I know one thing: I have far better things to do with my time than scan through assembly code that deals with parameter passing. I need to think about what function or class to use, what it does and what parameters to pass to it, not mundane mechanics. I need to write applications with complex functionality and a wide wariety of input in a reasonable time. I need libraries, design patterns, frameworks and high-level languages. I don't want to optimise the code around the microprocessor architecture - I don't have the time to do that. I need productivity far more than I need performance. Assembly won't give me that.
 
Thanatos22:
IMHO the recent advent of JIT compiling will go a long way towards making the ISA less and less important.

How so? You'd still have to produce instructions to feed the CPU. If these instructions are complex then it's harder both to create them for the JIT and for the CPU to decode them and translate into it's my-ops.

(I'm currently studying for a computer architecture class so my brain is under high influence of this right now. ;-) Just wondering if you had some neat ideas about it. Because I'd agree that JIT's are going to be big-big-big soon.)
 
Originally posted by euzeka:
It isn't now, but I think it was back then. IIRC, Digital FX!32 dates back to around the pentium era, or maybe very early early P2.
I didn't use it extensively, but I had chance to use it on a few occasions; it gave the impression of turning your nice expensive Alpha into a 486. It was tolerable for things like Office, but not something you'd want to do any work in (though for all I know it was misconfigured and/or out of date). It dates back to the days of the PPro and Pentium MMX (NT 4 was out in 1996 if memory serves). The Pentium II didn't emerge until 1997.
 
Status
Not open for further replies.