I'm trying to rewrite this function in assembly in order to optimize it:
uint32_t queueEnqueue(struct Queue* q, uint32_t val)
{
if(q->numElem == BUFFER_SIZE)
{
return QUEUE_FULL;
}
q->arr[q->tail] = val;
q->tail = (q->tail + 1) % BUFFER_SIZE;
q->numElem++;
return 0;
}
It uses a Queue struct, which you can see here:
struct Queue
{
uint32_t arr[BUFFER_SIZE]; // data. BUFFER_SIZE == 320
uint16_t head; // read index
uint16_t tail; // write index
uint16_t numElem; // to check for buffer overflow
};
How would I access these different elements in assembly, if passed a pointer to the queue?
Thanks!
-Tim
Access member of struct in assembly
-
- Junior Member
- Posts: 4
- Joined: Sat Jan 07, 2017 10:39 pm
-
- XCore Addict
- Posts: 169
- Joined: Fri Oct 23, 2015 10:23 am
Hi
A good starting point would be to see what the compiler would generate.
You can then take that code and improve it - or rewrite it.
Add the flags "-Os -S -o -" to output optimised assembler to the screen.
Robert
A good starting point would be to see what the compiler would generate.
You can then take that code and improve it - or rewrite it.
Add the flags "-Os -S -o -" to output optimised assembler to the screen.
Robert