+  RHDN Forum Archive
|-+  Romhacking
| |-+  ROM Hacking Discussion
| | |-+  Quick MIPS question
Pages: [1]
Author Topic: Quick MIPS question  (Read 410 times)
DaMarsMan
Guest
« on: May 01, 2007, 05:07:30 pm »

I want to copy a chunk of data from my exe to 80170000 in ram of psx. I have this running from my new intro. It's now working and here is my loop. I'm not really good with this kind of assembly yet. Did I do anything wrong?

Code:
li         t1, 0               ;load 0 into t1 (counter)
li         t3, $FFFF        ;load maximum amount (0xFFFF)

copydata   
lb        t0, System1(t1)          ;load a byte from System1 + counter(location of my data)
sb       t0, $A0170000(t1)     ;store the byte into our new position + counter
addiu  t1, 1                           ;increment counter by 1
beq     t1, t3, copydata         ;brand if counter reaches max of 0xFFFF 


The code actually runs through but I don't see anything getting copied.

By the way...there is a good reference for MIPS and other stuff here http://faculty.cs.tamu.edu/ejkim/Courses/cpsc321/
Deathlike2
Guest
« Reply #1 on: May 01, 2007, 05:34:29 pm »

Quote from: DaMarsMan on May 01, 2007, 05:07:30 pm
I want to copy a chunk of data from my exe to 80170000 in ram of psx. I have this running from my new intro. It's now working and here is my loop. I'm not really good with this kind of assembly yet. Did I do anything wrong?

Code:
li         t1, 0               "";load 0 into t1 (counter)
li         t3, $FFFF        ;load maximum amount (0xFFFF)

copydata   
lb        t0, System1(t1)          ;load a byte from System1 + counter(location of my data)
sb       t0, $A0170000(t1)     "";store the byte into our new position + counter
addiu  t1, 1                           "";increment counter by 1
beq     t1, t3, copydata         "";brand if counter reaches max of 0xFFFF 


The code actually runs through but I don't see anything getting copied.

By the way...there is a good reference for MIPS and other stuff here http://faculty.cs.tamu.edu/ejkim/Courses/cpsc321/


If any of my MIPS knowledge can be recalled, I'd be surprised.

I don't believe you can reference the data like that. You want to store the address of the data in a register and use that instead.

So, it would be more like this:

Code:
li         t1, 0               "";load 0 into t1 (counter)
li         t3, $FFFF        ;load maximum amount (0xFFFF)
la        t2, System1   ""; add instruction to load address, something like this I think
la        t4, $A0170000 ; destination address

copydata   
lb        t0, t2(t1)          ;load a byte from System1 + counter(location of my data)
sb       t0, t4(t1)     "";store the byte into our new position + counter
addiu  t1, 1                           "";increment counter by 1
beq     t1, t3, copydata         "";brand if counter reaches max of 0xFFFF 


http://en.wikipedia.org/wiki/MIPS_architecture - Wikipedia does have an OK reference here
Gemini
Guest
« Reply #2 on: May 01, 2007, 05:39:47 pm »

That code is never gonna work, not even on real hardware (how it did compile is a mystery to me O_o). Change it to this:
Code:
li         t1, 0               ;load 0 into t1 (counter)
li         t3, 0xFFFF        ;load maximum amount (0xFFFF)
[color=red]li         t2, System1
li         t4, 0xA0170000      ; illegal address, but you can replace it with whatever the real value is[/color]

copydata:
lbu         t0, 0(t2)          ;load a byte from System1 + counter(location of my data)
[color=red]addiu      t2, 1              ; increment read address[/color]
sb         t0, 0(t4)     ;store the byte into our new position + counter
addiu      t1, 1                           ;increment counter by 1
beq        t1, t3, copydata         ;brand if counter reaches max of 0xFFFF
[color=red]addiu      t4, 1              ; increment write address[/color]

Also remember to respect delay slot, lazy jumps and addressing mode. You can't use immediately a value loaded with lb/lbu/lh/lhu/lw, so you'll have to wait at least for another instruction to be executed.
Even more important, branch and jump instruction execute the next opcode immediately, so remember to place something after them (like NOP if necessary).
And what is that A0170000 address? Psx ram range is 80000000~80200000. You can't just store stuff wherever you want.

PS: You could have used just a simple memcpy() function. Tongue The Psx BIOS has it, among other C standard routines.
Deathlike2
Guest
« Reply #3 on: May 01, 2007, 05:45:46 pm »

I think the important thing to note is that you cannot do direct memory to memory copy, but you would have to copy into the register and back into mem.. which is the only way.

I think there was a reason for this, but I didn't pay enough attention in class to remember why, but it probably by design anyways.

Edit: This site is pretty nice - http://www.computing.dcu.ie/~ray/CA225b.html
« Last Edit: May 01, 2007, 06:09:25 pm by Deathlike2 »
DaMarsMan
Guest
« Reply #4 on: May 01, 2007, 07:15:31 pm »

Cool thanks every. I'm using spAsm that's why it's formatted all crappy and compiles like that. The last thing I changed it the beq at the bottom should be bne.
Gemini
Guest
« Reply #5 on: May 01, 2007, 07:23:17 pm »

Crap, I didn't notice that beq. xD
Pages: [1]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC