Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2008-02-25 17:31:00

Awol
Member
Registered: 2008-02-25
Posts: 23
Website

C vs ASM

I read this in the Gameboy Development Resources thread:

nitro2k01 wrote:

RGBDS contains an assembler and linker. GBDK contains a C compiler and some libraries as well. If you're planning to program assembly language only, RGBDS is your choice, since it has a more powerful macro language. If you're going going for C only, or C mixed with asm, you should use GBDK.

I didn't even know that C only or ASM only were options. I had been told that the way to do it was C mixed with ASM. What are the advantages/disadvantages of each of the 3 approaches?


Formerly Grey_and_Purple.

Offline

 

#2 2008-02-25 22:00:16

IIMarckus
New member
Registered: 2008-02-23
Posts: 9

Re: C vs ASM

ASM has the advantage of more speed and less bloat, which is a plus on a limited system such as the Game Boy. C is quicker to code and easier to maintain, but you might have optimization problems, which is why it's usually better to code specific routines in ASM when you're using C.

Last edited by IIMarckus (2008-02-25 22:03:33)

Offline

 

#3 2008-02-26 07:42:46

nitro2k01
Administrator
Registered: 2008-02-22
Posts: 245

Re: C vs ASM

C+ASM, is usually the way to go, yes. There's this saying that 10% of the code is executed 90% of the time. Those 10% are the only parts that are really worth optimizing. (=Writing in ASM)
ASM only is defnitely a viable option. It takes a lot more work, and for the other 90% of the code that is being executed just 10% of the time, it won't matter much speedwise. However, that 90% will shrink alot because a C compiler tends to create bloated machine code. I can imagine many commercial games were written in ASM only, but then again, it's hard to know without seeing their source code.
And, the last option, C only. This could work for some smaller programs, or when you're experimenting with something before the stage where it becomes serious enough to care about speed. A big nono for serious projects.


Blog: Gameboy Genius
"A journey of a thousand miles begins with one small step"
Old Chinese Proverb

Offline

 

#4 2008-02-26 08:20:36

oxygenfad
New member
Registered: 2008-02-23
Posts: 3

Re: C vs ASM

I'd really like to get some hello world going. Now might be a good time to learn ASM ?

Offline

 

#5 2008-03-03 16:54:38

FailedArtifact
New member
Registered: 2008-03-03
Posts: 9

Re: C vs ASM

I beleive ASM will ALWAYS be better than any higher level programming langauge. Its just whether you want to spend so much time coding and LEARNING for a matter of fact. It is good to at least experiance ASM if not learn it. I am looking into going into Univeristy, and by doing that i have been looking at some game programming jobs. ALL the jobs i have seen which require a good knowledge of ASM get a massive pay rise than for some one who knows C++. But of course the price is high becuase its hard to learn. Starting here where ofc you are keen on success with your favourite handheld IS THE BEST place to start. The Motivation that just brings with programming on a gameboy will be enough to get you somewhere. I wish to at least view ASM hands on here, see how it goes. Maybe we can learn one or two things from our experiance. Who knows.

Offline

 

#6 2008-03-03 17:03:51

nitro2k01
Administrator
Registered: 2008-02-22
Posts: 245

Re: C vs ASM

While I'm an advocate of ASM, i don't believe it's always right. (All applications, all platforms) For very complex applications it can be error prone. Depending on what you want to do other paradigms can be better for abstracting the problem you want to solve.
But as you say, it's a good thing to experience it. It's my personal opinion that every software developer should have at least a basic understanding of how what they're developing for works, at least one level below where they work. (For a C developer, how the compiler translates C into ASM. For an ASM developer, how the target CPU is managing caching. For a Java eveloper, how the JVM works, etc.)


Blog: Gameboy Genius
"A journey of a thousand miles begins with one small step"
Old Chinese Proverb

Offline

 

#7 2008-03-05 08:28:49

FailedArtifact
New member
Registered: 2008-03-03
Posts: 9

Re: C vs ASM

True nitro, but to get the maxium out of a program, using ASM will privide a better result. But it is merly not feasiable to create a complex program using ASM, unless your a genius and have 20 years to waste!

Offline

 

#8 2008-03-28 19:19:52

dox
New member
Registered: 2008-02-24
Posts: 4

Re: C vs ASM

Using GBDK for _anything_ more complex than "Hello World"  isn't a good idea.
First - gb is rather simple (or very simple) piece of hardware. Slow, low of ram, many limitations.
Second - GBDK is buggy. Very. And annoying.

Although there's a couple of nice games written in C.
Few good looking homebrew (Crazy Zone) and commercial ones (Logical, Quix Adventures).

GB assembler language  is really simple. Imho easier to learn than gbdk-ish version of C
(knowing the "real" C doesn't helps in this case, but confuses).
The only problem could be non-orthogonal architecture and very limited instruction set.
Mixing asm with c isn't  a good idea either. Not on this hardware platform.


FailedArtifact wrote:

But it is merly not feasiable to create a complex program using ASM, unless your a genius and have 20 years to waste!

So ... how most of  8/16 bits games were made  wink ?

Offline

 

#9 2008-04-03 00:14:38

Shiny
Member
Registered: 2008-03-17
Posts: 21

Re: C vs ASM

dox wrote:

GB assembler language  is really simple. Imho easier to learn than gbdk-ish version of C
(knowing the "real" C doesn't helps in this case, but confuses).
The only problem could be non-orthogonal architecture and very limited instruction set.

Very true. I've jumped ship to RGBASM because of GBDK's bug-laden compiler and it's not much more difficult than writing in C with GBDK's quirkiness in mind; and this is coming from someone who has never written in assembly before.

dox wrote:

Mixing asm with c isn't  a good idea either. Not on this hardware platform.

And why is that? Most code has little benefit being written in assembly anyways. Only certain code actually needs that extra efficiency.

Offline

 

#10 2008-04-07 18:38:46

www.BoumPower.ch
Member
Registered: 2008-04-04
Posts: 20
Website

Re: C vs ASM

I need to make a small OS message driven (like windows) that run on GB
where can I find libraries or source code (ASM) ?
I started with C (gbdk) and I will decide if it's a good idea to restart with asm...

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson