Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Trying to understand assembly
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Bigun
Advocate
Advocate


Joined: 21 Sep 2003
Posts: 2196

PostPosted: Mon Sep 17, 2012 2:41 pm    Post subject: Trying to understand assembly Reply with quote

Before I start with my issue, I guess I should state some background languages that I have learned:

PHP
SQL
Basic
Visual Basic
C++

Now I'm trying to learn assembly. Why? Because I want to create an NES game, and this leaves me with two choices in languages: C or Assembly

From what I understand, the NES cart has severely limited ROM space, and writing the game in assembly tends to make for more compact code, so assembly it is.

The tutorial I started reading is here.

With that out of the way, my main issue is trying to understand some of the terminology that assembly uses:

What the eff is a register? Whats a directive? Do I need to learn standard assembly before I dip into NES programming?

Or do I need to ditch assembly for C for sanity sake?

Just some help for me to wrap my head around some of these concepts.
_________________
"It's ok, they might have guns but we have flowers." - Perpetual Victim
Back to top
View user's profile Send private message
cwr
Veteran
Veteran


Joined: 17 Dec 2005
Posts: 1969

PostPosted: Mon Sep 17, 2012 3:13 pm    Post subject: Reply with quote

Assembler is pretty much assembler, even on quite varied CPUs, though the opcodes
and mnemonics change.

A processor register is a storage area within the CPU (not cache). Some registers are user-accessible,
some the CPU keeps to itself for its own operations.

An assembly language directive is directs the assembler to do something - unlike a mnemonic
it doesn't produce executable code.

Wikipedia is your friend.

Good luck - Will
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10587
Location: Somewhere over Atlanta, Georgia

PostPosted: Mon Sep 17, 2012 3:14 pm    Post subject: Reply with quote

Okay, just to start.
  • Standard assembly vs. NES assembly. There's really no such thing as "standard" assembly language, although you will see similarities. Each machine (i.e., CPU family) architecture has its own. Assembly language is a symbolic version of the machine language, so it has to differ on each different CPU architecture.
  • A register is a small storage element inside the CPU. It usually matches the word size of the CPU in size. So, for instance, modern x86 normally has 32-bit registers (or, in AMD64 mode, 64-bit registers). Some machines can only perform operations on values in the registers; others (e.g., x86) have instructions that will operate directly on values out in RAM. In any case, registers are the fastest storage in a computer so writing code that does a calculation all in registers can result in the fastest possible implementation. Registers are also the most limited memory resource; there are usually only a few.
  • Directives are an assembly language feature that provide information to the assembler (assembly language analogue of the compiler) to help it generate the code that you want, allocate memory, and provide information to the linker that a high level language normally provides for you, among other things.
If you didn't get those things from the tutorial you referenced (I only glanced at it), then it's targeted at someone that already knows more of the basic concepts. It might help you to start playing with x86 assembler first as (a) there will be more tutorial material out there and (b) you have everything you need already to experiment.

If you have any more specific questions, don't hesitate to ask. Good luck. :wink:

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
Hypnos
Advocate
Advocate


Joined: 18 Jul 2002
Posts: 2889
Location: Omnipresent

PostPosted: Mon Sep 17, 2012 5:38 pm    Post subject: Reply with quote

This looks like fun: 6502 compatible assembler and emulator in javascript

Tutorials here.

A variant of the 6502 was used in the old NES.
_________________
Personal overlay | Simple backup scheme
Back to top
View user's profile Send private message
bec
Apprentice
Apprentice


Joined: 30 Sep 2004
Posts: 220
Location: Cali - Colombia

PostPosted: Mon Sep 17, 2012 8:49 pm    Post subject: Reply with quote

Consider the book:

The Art of Assembly Language Programming

downloadable at:

http://www.plantation-productions.com/Webster/www.artofasm.com/index.html
_________________
abe
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54214
Location: 56N 3W

PostPosted: Mon Sep 17, 2012 9:43 pm    Post subject: Reply with quote

Bigun,

Cheat. Write C or C++ then optimise speed critcal areads by hand.
You can call assembly routines from C and pass results back.

If you tell gcc -O0 so nothing is optimised away, you can pass gcc another option to leave the assembly file behind so you can look at it.
You can also edit it and send it to the assember again but this is not really the way to go.

Once you have determined the functions with the need for speed, you can either write assembly versions from scratch or take the assebly code from the output of gcc as your stating point.
Now you need to lean to work with libraries too.

Writing hex and calulating relative jump offsets by hand is no fun. Assembly is the the next layer of abstraction up.
Its programming without the aid of a safety net.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum