News:

  • October 18, 2026, 07:49:07 PM

Login with username, password and session length

Author Topic: Sorting Array  (Read 7615 times)

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Sorting Array
« on: January 23, 2021, 08:47:42 AM »
Is there a built in way to sort an array by array position? Example: Array1[E1, E2, E3, E4] -->Array2[E4, E3, E2, E1]. I was trying to use a FIFO to store error messages but I would then like to reorder that array so that the most recent messages were at the top of an array sorted to the oldest messages.

ADC Product Engineer

  • Hero Member
  • *****
  • Posts: 270
Re: Sorting Array
« Reply #1 on: January 23, 2021, 11:16:27 AM »
No, but there is a sort posted in the program examples section.

https://forum.hosteng.com/index.php/topic,1020.0.html

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Sorting Array
« Reply #2 on: January 23, 2021, 03:57:29 PM »
I'm not sure what your purpose is to put them in a FIFO, as that implies you are taking them out again. I put many things into a memory block with a pointer, and then increment the pointer with a mask so it rolls over. Or use a MEMCOPY to copy 0 through 254 into 1 through 255, and insert new data into 0.

Bolt

  • Hero Member
  • *****
  • Posts: 598
Re: Sorting Array
« Reply #3 on: January 23, 2021, 04:00:40 PM »
Reread your post, sounds like you need to do the MEMCOPY 0 through 254 to 1 through 255, then unload FIFO into spot 0.

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Re: Sorting Array
« Reply #4 on: January 23, 2021, 06:13:36 PM »
Ultimately just used a for loop. An instruction that automatically sorted would be nice.