gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > A Random number problem with a difference

#9872 - Omega81 - Wed Aug 20, 2003 7:33 pm

Hello I was wondering if any of you guys/gals can take a look at this piece of code and tell me if there is anything wrong with.

Code:

@using Congruential Random Number Generator routine seed+1 = (A*seed + C) % M
@ r0 = A, r3 = seed (defined in calling fucntion) r2 = C and r3 = M
@ save result in r3

.global Rand
.arm
.align 4
Rand:

   stmfd sp!, {r0-r2}  @ push these registers on the stack
    ldr r0, =69069
   ldr r2, =1
    mul r2,r3,r0             @ A*seed+C
   add r2,r2,#1
   mov r3,r0,lsr#17      @ loss lower 17bits
   ldr r1,=1
   mov r1,r1,lsl#15      @ shift 1 <<15
   and r3,r1,r3             @ and (1<<15) with (r3>>17)
   ldr r2,=160               @ 160 is the limit
   mul r1,r3,r2              @ 
   mov r3,r1,lsr#15      @ losse last 15bit
   ldmfd sp!, {r0-r2}    @ pop the registers off the stack
mov pc,lr             @ return to calling function

it is surpose to generate a random number which I feed to my plot pixel and RGB functions which should give me the old random pixel screen plotter. but I get a blank screen. So if anyone can see what I am doing wrong. please let me know. Also it is based on the C function "tepples" gave at this post : http://forum.gbadev.org/viewtopic.php?t=873

Charles
_________________
Keep it real, keep it Free, Keep it GNU

#9875 - FluBBa - Wed Aug 20, 2003 10:07 pm

Seems like you are confusing alot of stuff here.

ldr r0, =69069
ldr r2, =1 @???
mul r2,r3,r0 @ multiply r0 & r3 put result in r2
add r2,r2,#1 @ add #1 to r2
mov r3,r0,lsr#17 @ r3=(69069>>17)=0
ldr r1,=1
mov r1,r1,lsl#15 @ r1=( 1 <<15 )=0x8000, (mov r1,#0x8000)
and r3,r1,r3 @ r3=0 && 0x8000
ldr r2,=160 @ overwrite r2 with #160
mul r1,r3,r2 @ r1=0*160
mov r3,r1,lsr#15 @ loose last 15bit

I hope this can help you somewhat.
_________________
I probably suck, my not is a programmer.