Przesuwanie elementów tablicy.
-
JanJJW
- Posty: 25
- Rejestracja: 17 sty 2018, 0:17
Przesuwanie elementów tablicy.
Czy ktoś ma pomysł na procedurę przesuwania wartości w tablicy? Chodzi o to by tablica funkcjonowała jak stos. To znaczy by dopisanie kolejnego elementu spowodowało przesunięcie pozostałych wartości w górę (w dół) o jedną pozycję. Jakoś nic rozsądnego nie przychodzi mi do głowy 
- Pikczu
- Posty: 399
- Rejestracja: 17 sie 2015, 13:46
- Lokalizacja: Dublin, Ireland
- Kontakt:
Re: Przesuwanie elementów tablicy.
Jeśli to ma obracać w kółko to proszę bardzo, przesuwanie przykład od samego Marka Albertsa.
Link do mcs forum: https://www.mcselec.com/index2.php?opti ... ift+array
******************************************************************edit*****************************************************
Fifo bufor zamień tylko stringi na bajty
Oryginał ma MCS https://www.mcselec.com/index2.php?opti ... ing+buffer
Link do mcs forum: https://www.mcselec.com/index2.php?opti ... ift+array
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "m8def.dat"
- $crystal = 12000000
- $hwstack = 32
- $framesize = 24
- $swstack = 16
- Declare Sub My_rotate_right(ar() As Byte , Byreg R24 As Byte)
- Dim Ar(20) As Byte , J As Byte
- Ar(1) = 1
- Do
- Call My_rotate_right(ar() , 5)
- For J = 5 To 1 Step -1
- Print Bin(ar(j)) ; " ";
- Next
- Print
- Loop
- End
- Sub My_rotate_right(ar() As Byte , Byreg R24 As Byte)
- Loadadr Ar(1) , X
- !push r26
- !push r27
- !ld r16,x+ ; get byte
- !lsl r16 ; lsl to left
- !dec r24 ; just make sure passed byte > 1 !!!!!!!!
- Myrotate_lp1:
- !ld r17,x ; get N byte
- !rol r17 ; rotate left with carry
- !st x+,r17 ; store and advance pointer
- !dec r24 ; next byte
- !brne myrotate_lp1
- !pop r27
- !pop r26
- !adc r16,r24 ; add carry to bit 0
- !st x,r16
- End Sub
******************************************************************edit*****************************************************
Fifo bufor zamień tylko stringi na bajty
Oryginał ma MCS https://www.mcselec.com/index2.php?opti ... ing+buffer
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- Declare Sub Push_FIFO(char as string)
- Declare Function Pop_FIFO() as string
- 'Set the size of the buffer
- Const FIFOSIZE = 10
- 'Pad the buffer with one extra byte so it is easy to distinguish a full buffer
- 'from an empty one
- Const FIFOBUFSIZE = FIFOSIZE + 1
- Dim FIFO_Buffer(FIFOBUFSIZE) as Byte
- 'Head and Tail point to the start and end of the buffer. If head = tail, then
- 'the buffer is empty.
- Dim Head as Byte
- Dim Tail as Byte
- '"Empty" the buffer
- Head = 1
- Tail = 1
- 'Start of program
- Dim i as byte
- Dim temp as string * 1
- Dim MyData as string * 5
- MyData = "Hello"
- 'Load the FIFO
- For I = 1 to 5
- temp = mid(MyData, i, 1)
- Call Push_FIFO( temp )
- Next
- 'Now empty the data in the FIFO
- While Head <> Tail
- Print POP_FIFO()
- Wend
- End
- Sub Push_FIFO(char as String)
- 'Add a character to the FIFO
- Local OldHead as byte
- 'Save the current Head location to revert if the FIFO is full
- OldHead = Head
- Incr Head
- 'Handle wrapping around to the beginning
- If Head > FIFOBUFSIZE then Head = 1
- If Head = Tail then
- 'FIFO is full. Handle this however you want. Here I will simply
- 'discard the new data and do nothing.
- Head = Oldhead
- Else
- FIFO_Buffer(OldHead) = asc(char)
- End If
- End Sub
- Function Pop_FIFO() as String
- 'Return a character from the FIFO
- Local Result as byte
- 'Get the character at the tail of the buffer
- Result = FIFO_Buffer(Tail)
- 'Update the tail pointer
- Incr Tail
- If Tail > FIFOBUFSIZE then Tail = 1
- 'Assign result as last instruction in the function
- Pop_FIFO = Chr(Result)
- End Function
-
JanJJW
- Posty: 25
- Rejestracja: 17 sty 2018, 0:17
Re: Przesuwanie elementów tablicy.
Dziękuję bardzo. Przyda się 
-
JanJJW
- Posty: 25
- Rejestracja: 17 sty 2018, 0:17
Re: Przesuwanie elementów tablicy.
Jeszcze raz dziękuję. Problem okazał się właściwie banalny. Dziękuję za naprowadzenie mnie na rozwiązanie.
