I think there it is not problem with data alignment. I modify code as it:
Code: Select all
unsigned char unCompressHeader[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned char tgaHeader[12];
unsigned char header[6];
fread( &tgaHeader, 1, sizeof(tgaHeader), f );
//read only uncompressed TGA's
if( memcmp( unCompressHeader, tgaHeader, sizeof(unCompressHeader)) != 0 )
{
fclose( f );
return false;
}
// Read Image info
fread( header, 1, sizeof(header), f );
// Calculate and save the Width & Height of Image
int iImageWidth = header[1] * 256 + header[0];
int iImageHeight = header[3] * 256 + header[2];
unsigned int c = iImageWidth * iImageHeight;
iImageWidth and iImageHeight is 256, but the value c is still zero. I debug the code with gdb, step with asm. the last line asm code like this:
(gdb) info r
Code: Select all
zero at v0 v1 a0 a1 a2 a3
R0 00000000 0008ff00 00000100 00000100 09f3eb9a 09f3eb98 00000000 00000001
t0 t1 t2 t3 t4 t5 t6 t7
R8 09f3eb98 089b2540 09f3eb94 089b253c 00000000 00000e00 08973508 00088600
s0 s1 s2 s3 s4 s5 s6 s7
R16 089b0ae0 09f3ee44 00000001 09f3eef0 0000000d 00000013 deadbeef deadbeef
t8 t9 k0 k1 gp sp s8 ra
R24 0000012f 0000013c 09f3ef00 00000000 089a8870 09f3eb68 09f3eb68 0892a324
sr lo hi bad cause pc
60088613 00000000 00000009 00010004 10000024 0892a34c
fsr fir
00000e00 00003351
the code:
319 unsigned int c = iImageWidth * iImageHeight;
1: x/i $pc 0x892a34c <_Z7loadTGAPKcb+300>: lw v1,8(s8)
1: x/i $pc 0x892a350 <_Z7loadTGAPKcb+304>: lw v0,4(s8)
1: x/i $pc 0x892a354 <_Z7loadTGAPKcb+308>: mult v1,v0
1: x/i $pc 0x892a358 <_Z7loadTGAPKcb+312>: mflo v0
after this step ,registers v0 changed:
(gdb) info r
Code: Select all
zero at v0 v1 a0 a1 a2 a3
R0 00000000 0008ff00 deadbeef 00000100 09f3eb9a 09f3eb98 00000000 00000001
t0 t1 t2 t3 t4 t5 t6 t7
R8 09f3eb98 089b2540 09f3eb94 089b253c 00000000 00000e00 08973508 00088600
s0 s1 s2 s3 s4 s5 s6 s7
R16 089b0ae0 09f3ee44 00000001 09f3eef0 0000000d 00000013 deadbeef deadbeef
t8 t9 k0 k1 gp sp s8 ra
R24 0000012f 0000013c 09f3ef00 00000000 089a8870 09f3eb68 09f3eb68 0892a324
sr lo hi bad cause pc
60088613 deadbeef deadbeef 00010004 10000024 0892a35c
fsr fir
00000e00 00003351
the last line
1: x/i $pc 0x892a35c <_Z7loadTGAPKcb+316>: sw v0,0(s8)
save the v0 value 0xdeadbeef into c. I dont know "mflo v0" means what but this step cause c error.