There was a very popular book issued by RAND that had hundreds of pages of good pseudo random numbers that you could use.
Seems a lot more simple just to use the book to populate a lookup table. This method you take a hit with memory (having the table in memory grows the larger you want the table to be..) But it is a whole lot simpler to implement.
https://www.rand.org/pubs/monograph_reports/MR1418.html
For testing is a nice thing to have because you can just open the book at a page and point your finger and you have your randomly selected pseudo random value. Not sure about you fellows but a lot of the time I only need a few values to test stuff with.
You might get values that are to large for 16 bits, in that case just select another or subtract 65,535 from the result.
If you were really slick (or not worried about T states you could do 32 bit numbers)
"You know the z80 wants to be doing 32bit numbers, just look at all the register pairs!"
HL & DE mmmm... all pointing to a 16 bit value in memory..
While there was obviously some prior art, Andre Adrian's website was where I saw this...
Code: Select all
; LOAD TEST VALUES
LD HL,01213H ; LOAD HEXADECIMAL 1213 TO HL (LOWER 16-BIT)
LD DE,0F000H ; LOAD HEXADECIMAL F000 TO DE (LOWER 16-BIT)
EXX
LD HL,01011H ; LOAD HEXADECIMAL 1011 TO H'L' (UPPER 16-BIT)
LD DE,0 ; LOAD VALUE 0 TO D'E' (UPPER 16-BIT)
EXX
CALL ADD32
HALT
;==================================================
; ADD ROUTINE 32+32BIT=32BIT
; H'L'HL = H'L'HL + D'E'DE
; CHANGES FLAGS
;
ADD32:
ADD HL,DE ; 16-BIT ADD OF HL AND DE
EXX
ADC HL,DE ; 16-BIT ADD OF HL AND DE WITH CARRY
EXX
; RESULT IS IN H'L'HL
RET
END
The EXX op-code was ugly to write and read, but was the reason why everybody doing number crunching in 8-bit liked the Z80 over the 8085.
http://www.andreadrian.de/oldcpu/Z80_nu ... ocId784223