It does not generate the intended randomness.
I thought starting with a seed like $66 and xoring the two last lower bit and ror would give me the next random number and so on but it only shows $B3 and does not change at all.
How am I meant to feed? The line above random displays the number on portc as I want two numbers displayed after each other.
I am only using avr studio 4 for atmega 8535 at 1Mhz.
> ;Program to random numbers on port C > > ;Stack and Stack Pointer Addresses .equ SPH =$3E > ;High Byte Stack Pointer Address .equ SPL =$3D > ;Low Byte Stack Pointer Address > > .equ RAMEND =$25F ;Stack Address > > ;Port Addresses > > .equ PORTC =$15 ;Port C Output Address > > .equ DDRC =$14 ;Port C Data Direction Register > Address > > .equ numberoneddr=DDRC > > .equ numberoneport=portc > > .equ numbertwoddr=DDRC > > .equ numbertwoport=portc > > .equ delayCount=21 > > .equ random1 =$66 > > ;Register Definitions > > .def numberone =r1 ;Register to store data pointed > to by Z > > .def numbertwo =r2 > > .def temp =r16 ;Temporary storage register > > > > reset: > > ; initialize stack pointer. Done automatically at reset on many AVRs > > ldi temp, low (RAMEND) > > out spl, temp > > ldi temp, high (RAMEND) > > out sph, temp > > > > > ;port initialisation > > ldi temp,$FF > > out numberoneddr,temp > > out numberoneport,temp > > out numbertwoddr,temp > > out numbertwoport,temp > > > > ;Program Initialisation > > ldi temp,$66 > > rcall random > > mov numberone, temp > > out numberoneport,numberone > > rcall random > > mov numbertwo, temp > > out numberoneport,numbertwo > > > > > random: mov r19,temp > > ldi r17, 0x01 > > eor r19,r17 > > ror r19 > > mov temp,r19 > > ret > > > > delay: > clr r20 > > clr r21 > > ldi r22, delayCount > > loopDelay: > > dec r20 > > brne loopDelay > > dec r21 > > brne loopDelay > > dec r22 > > brne loopDelay > > ret 


temp=$66each random call so the result is always the same ... you should feed the temp only once. also I would add a swap of bits (not justror) it usually leads for better randomness. also what are the 3 lines aboverandom:label do ... they are not executed oncall random!!!ldi temp,$66at program init and remove it from random subroutine. Also temp is a bad name for this ... when your program grows try to rename it torandom_tmpfor example