.word/.long/.short Instruction

Started by Deathwolf, July 30, 2011, 11:59:47 PM

Previous topic - Next topic

Deathwolf

For what is this instruction exactly? I've seen here a topic called "LUT" or something like that which is chunk of values but what are they doing? (I think for  LUT you need .long instructions too for the values)
dcx2 used it too for his code: http://wiird.l0nk.org/forum/index.php/topic,5791.msg54813.html#msg54813

Thanks for any answer.
lolz

FL4SHK

I'm not sure if I'm understanding your question, but I'll try to answer anyway.  I thought that instructions like .word and .short were basically for declaring constant values, usually as a label's value in the original assembly.  i.e., those instructions are like when using the "const" keyword for variables in C++.

dcx2

Nope.

Instructions that begin with . are usually called assembler directives.  .set is the assembler directive FLSHK is talking about.  It's probably more analogous to #define in C.

.word, .long, .short, and .float are data declaration assembler directives.  It allows you to specify data in the middle of ASM.

When you see .word in the disassembler, it means that there isn't a corresponding ASM instruction for the word.

For instance, open up ASMWiiRD.  put in ".long 0x80000000".  Then hit assemble.  You'll see

C2000000 00000001
80000000 00000000

However, 0x80000000 is actually valid ASM.  So if you disassemble, you'll get lwz r0,0(r0).

Normally, you'll need to use the bl trick to make sure the data isn't executed as ASM, otherwise it would crash.

Deathwolf

Ah ok thanks but what about your code? I uses some 00000000 values.
lolz

dcx2

The code needs somewhere to store the coordinates when you save them.  I use .word to allocate space for the coordinates so that I have somewhere to write them.

Deathwolf

#5
Ah I see. Maybe it's a little bit offtopic but for what is LUT?
lolz

dcx2

As mentioned in the LUT thread...a LUT is a Look Up Table.  It allows you to map a set of values from one to the next by using the index into the table as the input and the value at that index as an output.

For instance, each surface in SMG2 has a value.  Lava was 0xA, I think.  The LUT was preconfigured with 0 at the first index, 1 at the second index, 2 at the third index, etc.  If you're on lava, it looks up the value in index 0xA.  You would then replace 0xA with 0, so that Lava is Ground.  Then, when you're standing on lava, the game will look up the 0xA'th index, and use the value 0 instead of 0xA.

Deathwolf

It's something like a compair instruction? Sorry if I understood you wrong.
lolz

biolizard89

Quote from: Deathwolf on August 01, 2011, 01:18:39 AM
It's something like a compair instruction? Sorry if I understood you wrong.
LUT's aren't for comparing necessarily; it's basically just a list of values.  An example which is often used: trig functions take significant time to compute if you don't have floating point hardware.  On the GBA, which doesn't have floats, trig is often calculated instead by simply storing a precalculated table of every possible angle and its sine.  Like this:
long SinLut[] =
{
0 // 1000 * sin(0 degrees)
17 // 1000 * sin(1 degree)
35 // 1000 * sin(2 degrees)
// etc.
};

To find the sine of 7 degrees, I take SinLut[7] and I have my result (scaled by 1000 in this case).  Since this is simply an array lookup, it's much faster than computing by hand.

That's what LUT's do.  They're not just used for replacing float functions; they may be used as arbitrary functions as dcx2 said... they can be useful for lots of stuff.

Hope I explained that okay....

FL4SHK

#9
Quote from: dcx2 on July 31, 2011, 03:50:57 AM
Nope.

Instructions that begin with . are usually called assembler directives.  .set is the assembler directive FLSHK is talking about.  It's probably more analogous to #define in C.

.word, .long, .short, and .float are data declaration assembler directives.  It allows you to specify data in the middle of ASM.

When you see .word in the disassembler, it means that there isn't a corresponding ASM instruction for the word.

For instance, open up ASMWiiRD.  put in ".long 0x80000000".  Then hit assemble.  You'll see

C2000000 00000001
80000000 00000000

However, 0x80000000 is actually valid ASM.  So if you disassemble, you'll get lwz r0,0(r0).

Normally, you'll need to use the bl trick to make sure the data isn't executed as ASM, otherwise it would crash.

Actually, that's what I was trying to describe.  I guess I didn't explain it properly.  I was trying to say, for example, ".word 0x01234567" after a label is basically assigning a value to a label.

Edit:  Then again, maybe I'm just confused.  I don't know PPC assembly very well, I suppose.