Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
DooMBoy

Big Differences

Recommended Posts

So, tell me-what are the big differences between C programming, C++ programming, and Assembly programming?

Share this post


Link to post

Assembly is a low-level programming language. It means that you pretty much write direct instructions for the CPU. It's hard and only useful for small pieces of code that require optimized performance (some of DOOM's rendering code is written in assembly).

C is a high-level programming language, which means that the syntax is more "language-like". High-level program code is much easier to write and read than assembly code. C is almost as fast as assembly (in many cases it's just as fast). Most of DOOM was written in C. C code must be compiled.

C++ is similar to C, but fixes some limitations in C and also allows more abstraction through classes and object orientation. ZDoom has moved from C to C++. DOOM 3 is being written in C++.


Assembly:

dosseg
.model small
.stack 100h

.data
hello_message db 'Hello, World!',0dh,0ah,'$'

.code
main  proc
      mov    ax,@data
      mov    ds,ax

      mov    ah,9
      mov    dx,offset hello_message
      int    21h

      mov    ax,4C00h
      int    21h
main  endp
end   main

C:
int main()
{
    printf("Hello, World!");
}
C++:
int main()
{
    cout << "Hello, World!";
}
Those examples of C and C++ are not very good, but show the difference from assembly. If you want to look at more C or C++ code, search the Internet or download the DOOM source code ;)

Share this post


Link to post

Assembly programming is one step above feeding 0s and 1s directly into the processor. All of the elementary Assembly commands translate directly into a 32-bit binary string.

Share this post


Link to post

Assembler is basically raw machine code. It is the fastest but you have to write everything yourself which is tedious. It is also non-portable: assembler code only runs on one type of processor.

C is a bit higher level than assembler. It is portable: the code is no longer tied to one particular type of processor. It is more maintainable because it is easier to see the structure of the program. C is not as fast as Assembler because the machine code is generated by a compiler instead of a human, and humans are usually better at writing fast code. However, this isnt really a huge problem: you can usually deal with speed problems by writing the few bottlenecks in the program in assembler. Doom takes this approach: the core drawing code that draws the walls, floor etc is written in assembler but the rest is written in C.

C++ is different to C in that it is an Object Orientated language. In Object Orientated languages programs are structured as interactions between a number of abstract "objects". Each object represents something in the program: for example, an object might represent an employee in a payroll system, or a player in a game. Object Orientated languages are considered to be good because they promote writing in a structured way. There is nothing you can do in C++ that cannot be done in C but C++ generally makes it easier for the programmer. Because of its properties C++ scales to large projects better than C.

Share this post


Link to post
IMJack said:

Assembly programming is one step above feeding 0s and 1s directly into the processor. All of the elementary Assembly commands translate directly into a 32-bit binary string.

Like fredrik said it depends on the architecture. Some architectures have 32 bit length instruction (SPARC, MIPS etc). The x86 architecture in PCs has variable length instructions: some are 8 bits long, others are as much as 48 bits long. Variable length instructions are bad because they're hard to pipeline, yet another reason the x86 architecture is awful.

Share this post


Link to post

If you really want to muck around with Assembly, there's a freeware assembly-language emulator called "SPIM" that will take MIPS code and simulate running it. That's the prog I had to use in my Computer Organization course.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×