Are these declarations correct?
#include <stdint.h>
#include <stdbool.h>
#include <reg_mg82f6d64.h>
uint8_t data *R0 = 0x00;
uint8_t data *R1 = 0x01;
uint8_t data *R2 = 0x02;
uint8_t data *R3 = 0x03;
uint8_t data *R6 = 0x06;
uint8_t data *R7 = 0x07;
uint16_t code *DPTRc = 0x0000;
uint16_t xdata *DPTRx = 0x0000; // pdata
uint8_t data *DPTRd = 0x00;
uint8_t idata *STACK[10] = {(uint8_t idata *)0x81};
In here I am trying to use them exact same on 8051 assembler with C features but sometime it goes wrong, for example i can not use SP register for PUSH, POP like on assembly.
void wrb(void) // (write read byte)
{
*STACK[1] = ACC; // i want to do PUSH(ACC);
while ((SPSTAT & 0x80) != 0);
ACC = STACK[1]; // // i want to do POP(ACC);
SPDAT = ACC;
while ((SPSTAT & 0x80) == 0);
ACC = SPDAT;
}
void PUSH(void)
{
SP++;
*(uint8_t idata *)SP = ACC;
}
void POP(void)
{
ACC = *(uint8_t idata *)SP;
SP--;
}
So when MCU has Stack Pointer why would i declare another array and use more memory size which is a bad development!
lang-c
SP? Is it the processor's stack pointer? If so, then yourPUSHandPOPfunctions cannot work, because the processor's stack pointer is presumably used for the return address.PUSHandPOPlive in different functions so you could not use the same stack the cpu uses for return addresses anyway.x. In assembly you might dopush acc; mov a, x; add a, #10; mov x, a; pop accor similar. The accumulator is used because the cpu can only do addition there. Note that thepush/popis only because the code might want to preserve the original value, it's not an algorithmic requirement for a stack. You don't want to copy all these steps to C, you would just writex += 10;and be done with it.