Post Reply 
Scientific RPN Calculator (with ATTINY85)
03-08-2018, 12:54 PM
Post: #24
RE: Scientific RPN Calculator (with ATTINY85)
I think there is another small saving to be had.

Change the assignment of floats/doubles to use the memmove function instead. It seems smaller.
I haven't checked but it might even be worth having a copy function:
Code:
static void copy(double *dest, const double *src) {
    memmove(dest, src, sizeof(double));
}

In this case it is also possible to use memcpy directly since memmove uses memcpy for one direction of copy so no wasted code.

Also, change the stack functions to:

Code:
static void push(void) { // Push stack
  memmove(&y, &x, sizeof(y) * 3);
}

static void pull_upper(void) { // Pull upper part of stack
  memmove(&y, &z, sizeof(y)*2);
}

void pull(void) { // Pull stack fully
    memmove(&x, &y, sizeof(x)*3);
}

These have to be memmove calls since the blocks overlap. It is probably also sensible to declare the stack as a structure or array for this to be completely safe. There shouldn't be an extra overhead for doing so.

Pauli
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Scientific RPN Calculator (with ATTINY85) - Paul Dale - 03-08-2018 12:54 PM



User(s) browsing this thread: 1 Guest(s)