I found a relative small random number generator written in Z80 ASM, and I have tried to convert it to AVR but it don't work , if it's the code or my translation that fail I don't know so:
Are there anyone that can check if the Z80 code actually work?
and/or what I have done wrong? (I haven't done Z80 for a long time so perhaps something with the carry is not what I expect or something like that)
it's all here (I know that it can be optimized a lot but first I want it to work)
; ; AssemblerApplication4.asm ; ; Created: 09-02-2017 23:45:45 ; Author : Admin ; //Z80 code //ld de,(RandSeed) //ld a,d //ld h,e //ld l,$FD //or a //sbc hl,de //sbc hl,de //ld d,0 //sbc a,d //ld e,a //sbc hl,de //jr nc,Rand //inc hl //Rand ld (RandSeed),hl //r23 a //r25:r24 de //r27:r26 hl //r17:r16 RandSeed //Z counter ldi r30,0 ldi r31,0 //seed=1 ldi r16,1 ldi r17,0 start: movw r24,r16 //ld seed mov r23,r25 //a=d mov r27,r24 //h=e ldi r26,0xfd//l=fd clc //or a sbc r26,r24 sbc r27,r25 //hl-=de sbc r26,r24 sbc r27,r25 //hl-=de ldi r25,0 //d=0 sbc r23,r25 //a-=d mov r24,r23 //e=a sbc r26,r24 sbc r27,r25 //hl-=de brcc L0 adiw r26,1 //inc hl L0: movw r16,r26//store seed adiw r30,1 //just loop counter or r17 ,r17 brne start nop rjmp start
My way of checking is to have a breakpoint at "nop" and then see different numbers in r16 that only repeat after 256 times, (Z show the number of loops)