Skip to content

githubgilhad/memxFORTH-asm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MemxFORTHChipandColorfulStack.png

memxFORTH-asm

This project builds memxFORTH directly from assembler and try to be memory-effective

Target is ATmega2560 at MegaHomeFORTH board

  • All pointers should be 3-bytes/24-bits long, also CELL size is 3-bytes, so there is no size mismatch between address and value
    • Extra-byte (bits 16..23) is 0x80 for RAM, 00..04 for FLASH (and maybe something else for paged RAM and Shared Ram)
    • all memory acceess should be via system calls: THIS and THAT
  • reserved/assigned registers are this, every primitive is requered to protect and update them responsibly (just idea):
    • X -
    • Y - IP (preserved in C)
    • Z -
    • SP - RETURN stack
  • special registers:
    • Z - EIJMP, ELPM, Z+displacement
    • Y - Y+displacement
    • X - normal ( each can predecrement and postincrement)
#define JMP_ADDR(addr16)                   \
        do {                               \
                __asm__ __volatile__ (     \
                        ".word 0x940C\n\t" \
                        ".word %0\n\t"     \
                        : : "i" (addr16)   \
                );                         \
    } while (0)
register uint8_t counter asm("r2");  // r2 is the counter
__attribute__((naked, noreturn)) void function_A(void) { ... ;EIJMP; }
__attribute__((naked, noreturn))
void jump_to(uint32_t addr) {
        __asm__ __volatile__ (
                "mov r30, r22\n\t"
                "mov r31, r23\n\t"
                "out %[_RAMPZ], r24\n\t"
                "eijmp\n\t"
                :
                : [_RAMPZ] "I" (_SFR_IO_ADDR(RAMPZ))
        );
}

License

GPL 2 or GPL 3 - choose the one that suits your needs.

Author

Gilhad - 2025

About

FORTH for ATmega2560 with more asm code

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published