random numbers and delay loops HELP

General discussions related to the Altair 8800 Clone

random numbers and delay loops HELP

Postby gio74 » March 2nd, 2015, 5:51 am

I've created a random number generator that outputs number from 1 to 8, and I'd like to use that number to change the time of a delay loop
the problem is that the delay seems to ignore the changes. what am I doing wrong?

Code: Select all
; tempo random
; 1 March 2015   

               org      100h

           mvi   a,03h
           out    10h
           mvi    a,15
           out    10h

          
           lxi    h,200h ;initialise random number gen. by reading 200h

start     mvi   a,'+'      ;output an ASCII + to monitor the delay routine
           out   11h
   
random   mov    a,m ;random number generator
          rrc
           add   m
           rrc
           mov    m,a
           inx   h
           xra   m
           mov   m,a
           ani   7o
           inr   a
tempo      set   a ;0 to 7 should be assigned to variable "tempo"
   
           lxi   d,tempo*5000 ;this is the problem, I've tried also other things like "lxi d,a*5000", no luck
delay        dcx   d         
           mov   a,d      
           ora   e      
           jnz   delay       
   
           jmp   start

   
           end
   


sorry for the bad formatting, switching between PC and Mac makes some mess
gio74
 
Posts: 54
Joined: January 30th, 2015, 2:43 pm

Re: random numbers and delay loops HELP

Postby toml_12953 » March 2nd, 2015, 8:46 am

gio74 wrote:I've created a random number generator that outputs number from 1 to 8, and I'd like to use that number to change the time of a delay loop
the problem is that the delay seems to ignore the changes. what am I doing wrong?

Code: Select all
; tempo random
; 1 March 2015   

               org      100h

           mvi   a,03h
           out    10h
           mvi    a,15
           out    10h

          
           lxi    h,200h ;initialise random number gen. by reading 200h

start     mvi   a,'+'      ;output an ASCII + to monitor the delay routine
           out   11h
   
random   mov    a,m ;random number generator
          rrc
           add   m
           rrc
           mov    m,a
           inx   h
           xra   m
           mov   m,a
           ani   7o
           inr   a
tempo      set   a ;0 to 7 should be assigned to variable "tempo"
   
           lxi   d,tempo*5000 ;this is the problem, I've tried also other things like "lxi d,a*5000", no luck
delay        dcx   d         
           mov   a,d      
           ora   e      
           jnz   delay       
   
           jmp   start

   
           end
   


sorry for the bad formatting, switching between PC and Mac makes some mess


Could you be loading the location of tempo rather than the contents at that location?
I'm more familiar with Z-80 code but in order to use the 0 - 7, you'd have to
do something like this:

ld hl,(tempo)*5000

Tom Lake
toml_12953
 
Posts: 206
Joined: June 7th, 2013, 12:54 pm

Re: random numbers and delay loops HELP

Postby AltairClone » March 3rd, 2015, 10:45 am

Gio,

I see a few problems that need to be solved. One is that "lxi hl" loads the actual value specified in the right column - the right column is not an address from which hl is loaded. Second, the "set" mnemonic is a directive to the assembler used to set the value of a symbol during assembly - it is not an 8080 instruction.

Post the algorithm in some sort of pseudo-code and we can help convert it into 8080 assembly with you.

Mike
AltairClone
Site Admin
 
Posts: 421
Joined: April 5th, 2013, 10:55 am

Re: random numbers and delay loops HELP

Postby gio74 » March 4th, 2015, 3:00 am

oh thanks Mike!

the random gen works great, the only problem I have is to use that number to change the delay loop time

I see a few problems that need to be solved. One is that "lxi hl" loads the actual value specified in the right column - the right column is not an address from which hl is loaded.


Ok I misunderstood, lxi loads a 16 bit address and not its content, nevertheless the random gen works

Second, the "set" mnemonic is a directive to the assembler used to set the value of a symbol during assembly - it is not an 8080 instruction.


mhh I need to understand this. I used set before in another program and it worked. What is exactly a directive? the 8080 manual does not explain this.

anyway the program is basically this


10 initialise the serial port

20 print "X"

30 generate a random number between 1 and 8
40 assign random number to variable A$

50 perform loop delay
loop delay time = lxi d,...x..... where x = A$*5000

60 goto 20
gio74
 
Posts: 54
Joined: January 30th, 2015, 2:43 pm

Re: random numbers and delay loops HELP

Postby AltairClone » March 4th, 2015, 11:30 am

Here are some comments and updates to help you along:
Code: Select all
; tempo random
; 1 March 2015   

   org   100h

   mvi   a,03h
   out   10h
   mvi   a,15
   out   10h

;****
; Moved lxi h,200h inside the loop, otherwise, hl increments forever.
;    Also changed absolute address reference to a symbol

start   lxi   h,rndVal      ;hl->rndVal where 16 bit random number is

updated
   mvi   a,'+'      ;output an ASCII + to monitor the delay routine
   out   11h

random   mov   a,m
   rrc
   add   m
   rrc
   mov   m,a
   inx   h
   xra   m
   mov   m,a
   ani   7      ;a = msb and 7
   inr   a      ;a = 1 - 8 (not 0-7 as stated below)

;****
; This just sets the symbol "tempo" to a fixed value of 7 at assembly time.
;   In many 8080 instructions, "a" has the value of 7 in the bit field of
;   the instruction that identifies the register to be used

; tempo   set   a       ;0 to 7 should be assigned to variable "tempo"

;****
; This sets the value loaded into d to the fixed value of 7*5000 which when
;    wrapped to 16 bits is 88B8h. There is not a multiply instruction in the 8080.

;   lxi   d,tempo*5000


; compute de = a*4096 (instead of a*5000) by shifting a to the left 12 bits.

   rlc         ;move lower nibble to upper nibble
   rlc
   rlc
   rlc
   mov   d,a      ;d=msb of a*4096
   mvi   e,0      ;de=a*4096

delay   dcx   d
   mov   a,d
   ora   e
   jnz   delay       

   jmp   start

; Variables

rndVal   ds   2      ;16 bit random value variable

   end

AltairClone
Site Admin
 
Posts: 421
Joined: April 5th, 2013, 10:55 am

Re: random numbers and delay loops HELP

Postby gio74 » March 4th, 2015, 2:59 pm

Great Mike, I will study this very very closely.
thank you very much indeed.
gio74
 
Posts: 54
Joined: January 30th, 2015, 2:43 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest