#36 - Lord Graga - Wed Jan 01, 2003 4:04 pm
I am making a small ASM program that deletes the SRAM completely (fills it with FF's).
I have made the code in C, and tried to translate it into ASM, but with no luck...
Here is the C code:
Code: |
void AGBMain (void)
{
int i;
for(i=0;i<32768;i++)*(unsigned char*)(0x0e000000 + i) = 0xFF;
*(volatile unsigned long*)0x4000000 = (0x3|0x400);
while(1);
}
|
Now i need a good translation in ASM...can you guys help me and explain it? as far as i understand there are no real loop stuff in ASM...but i think i am wrong...
Thanks in Advanve.
#37 - DekuTree64 - Wed Jan 01, 2003 5:57 pm
Try
asm volatile("
mov r0, #0xe000000
mov r1, #32768 @careful, you can only MOV numbers that can be created by an 8-bit number and a shift
mov r2, #0xff
sram_loop:
subs r1, r1, #1 @pre-decrement and set processor flags because we started at 32768, and the highest byte we'll store is at 32767
strb r2, [r0, r1]
bne sram_loop @if r1 - 1 was not equal to 0
"
:
:
: "r0", "r1", "r2"
);
I haven't actually tested that, but it should work. That's in ARM, so make sure it's compiled that way. I've never used THUMB ASM myself, but I think it would pretty similar.sram_loop
#38 - Lord Graga - Wed Jan 01, 2003 6:31 pm
It works, thank you :D
#89 - jeff - Thu Jan 02, 2003 5:47 pm
Another method would be to use DMAs if you need this to be fast:
mvn r0,#0 ; r0 = 0xFFFFFFFF
str r0,[sp,#-4]! ; Push r0 onto hardware stack
; Transfer using DMA 3
mov r1,#0x4000000
str sp,[r1,#0xD4]
mov r2,#0xE000000
str r2,[r1,#0xD8]
mov r2,#0x85000000
add r2,r2,#0x2000 ; 32K
str r2,[r1,#0xDC]
; Transfer done
add sp,sp,#4 ; Pop 0xFFFFFFFF off the stack
HTH,
Jeff
#91 - Costis - Thu Jan 02, 2003 5:52 pm
Hi,
DMA won't work for what he wants because it doesn't have 8-bit bus witdh transfers, only 16 and 32 bit. The SRAM cartridge bus' width is 8-bits, so therefore DMA can't be used to copy information to it.
Costis
#100 - jeff - Thu Jan 02, 2003 7:17 pm
Ack, forgot that... :)
My bad,
Jeff
#172 - sgeos - Sat Jan 04, 2003 8:40 am
This worked for me:
ldr r2,=0x8000
ldr r1,=0x0E000000
ldr r0,=0xFF
sramlop:
subs r2,r2,1
strb r0,[r1, r2]
bne sramlop
I need to go to sleep (parents). Does anyone mind doing my homework for me? I need to push r14 onto the stack because I'm doing lots of nested subroutine calls. What lines do I use to push and pop it?
bl subroutine
endless:
b endless
subroutine:
; push r14
bl subtank
bl subtank
bl subtank
; do stuff
; pop r14
mov r15,r14
subtank:
; push r14
bl somethingelse
; do stuff
; pop r14
mov r15,r14
somethingelse:
; no more subroutines!
; do something else
mov r15,r14
-Brendan
#438 - pulstar_3 - Tue Jan 07, 2003 6:36 pm
Okay if you are in ARM mode, you will need to use this code,
str r13!,(register to push)
to pop
ldr r13!,(register to pop the value into).
To do multiple register use something like this,
stmfd r13!,{r0-r1} to push and ldmfd r13!,{r0-r1}. This will push and pop r0 and r1 onto the stack. Hope this helped.
#677 - sgeos - Thu Jan 09, 2003 6:23 pm
Thanks a lot! Thats exactly what I was looking for!
-Brendan