flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > pseudorandom number on i8080

Author
Thread Post new topic Reply to topic
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 17 Sep 2010, 11:55
based on two different articles from the internet Smile
Code:
;=======================================================================
;   RND -> DEHL
;-----------------------------------------------------------------------
get_rnd:
    lda .cnt
    dcr a
    jnz .lfsr
    lhld rnd
    lxi b,64525
    call umul
    push h
    push d
    lhld rnd+2
    call umul
    pop b
    dad h
    xchg
    pop h
    lxi b,1013904223 shr 16
    xchg
    dad b
    xchg
    lxi b,1013904223 and 0FFFFh
    dad b
    jnc @F
    inx d
@@:
    shld rnd
    xchg
    shld rnd+2
    mvi a,31
;-----------------------------------------------------------------------
.lfsr:
    sta .cnt
    lhld rnd+2
    xchg
    lhld rnd
    mov a,l
    xri 57h
    mov l,a
    mov a,d
    xri 80h
    mov d,a
    xchg
    dad h
    xchg
    dad h
    jnc @F
    inx d
@@:
    ral
    jnc @F
    inx h
@@:
    shld rnd
    xchg
    shld rnd+2
    xchg
    ret
;-----------------------------------------------------------------------
.cnt:   db 31
;=======================================================================
;
;=======================================================================
rnd:    dd 1
;=======================================================================
    


needs multiplication:
Code:
;=======================================================================
;   DEHL = HL * BC
;-----------------------------------------------------------------------
umul:  
    lxi  d,0
    mvi  a,16
umx1: 
    dad  h
    xchg
    jnc  umx3
    dad  h
    jnc  umx2
    inx  d
umx2: 
    dad  b
    jnc  umx4
    inx  d
    jmp  umx4
umx3: 
    dad  h
    jnc  umx4
    inx  d
umx4: 
    xchg
    dcr  a
    jnz  umx1
    xchg
    ret
;=======================================================================
    

tested with this way:
Code:
;-----------------------------------------------------------------------
    call 0C010h
;-----------------------------------------------------------------------
    lxi h,30101
    lxi d,10103
    call set_rnd
@@:
    call get_rnd
    xra a
    mov h,a
    inr a
    ana d
    mov d,a
    mvi a,-1
    call put_pixel
    lda 0FF01h ; exit if shift pressed
    rar
    rar
    jc  @B
;-----------------------------------------------------------------------
    ret    
;-----------------------------------------------------------------------
    


not ideal, you may see the result here, but maybe enough for common case Smile

Image

_________________
UNICODE forever!
Post 17 Sep 2010, 11:55
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 17 Sep 2010, 12:35
is that code compilable wih fasm? (with a '8080.inc' equ/macro file)
Post 17 Sep 2010, 12:35
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 17 Sep 2010, 13:02
sure! all i do now with 8080 is with fasm only Wink

here is the last "math.inc" from lib85 and rks binary file, possible to run in emu emulator.

[rks has 4 bytes prefix: start word, end word; and 2 bytes tail - checksum, emu uses only start word)]

if you wish i can give you later slightly reconfigured emu to run rks with less puzzle for you Wink


Description: test project with binary file
Download
Filename: math.zip
Filesize: 4.24 KB
Downloaded: 929 Time(s)

Description: latest math.inc from lib85
Download
Filename: math.inc
Filesize: 13.19 KB
Downloaded: 935 Time(s)


_________________
UNICODE forever!
Post 17 Sep 2010, 13:02
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.