View previous topic :: View next topic |
Author |
Message |
Bigun Advocate
Joined: 21 Sep 2003 Posts: 2196
|
Posted: Mon Sep 17, 2012 2:41 pm Post subject: Trying to understand assembly |
|
|
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 |
|
|
cwr Veteran
Joined: 17 Dec 2005 Posts: 1969
|
Posted: Mon Sep 17, 2012 3:13 pm Post subject: |
|
|
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 |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10589 Location: Somewhere over Atlanta, Georgia
|
Posted: Mon Sep 17, 2012 3:14 pm Post subject: |
|
|
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.
- John _________________ I can confirm that I have received between 0 and 499 National Security Letters. |
|
Back to top |
|
|
Hypnos Advocate
Joined: 18 Jul 2002 Posts: 2889 Location: Omnipresent
|
|
Back to top |
|
|
bec Apprentice
Joined: 30 Sep 2004 Posts: 220 Location: Cali - Colombia
|
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54237 Location: 56N 3W
|
Posted: Mon Sep 17, 2012 9:43 pm Post subject: |
|
|
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 |
|
|
|