This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problems with stack pointer in ASM

Hi everyone,
j returned to ASM programming after a lot of time programming in C, so maybe
j forget some concepts.My problem is the following : j have a project in
ASM made of some modules, seems that the last variable in the last linked
module overlaps the first byte of the stack pointer. Look at the following
lines extracted from the M51 file :

TYPE BASE LENGTH RELOCATION SEGMENT NAME
-----------------------------------------------------

* * * * * * * D A T A M E M O R Y * * * * * * *
REG 0000H 0008H ABSOLUTE "REG BANK 0"
DATA 0008H 0012H UNIT SERIALDATA
DATA 001AH 0001H UNIT HTRCDATA
DATA 001BH 0001H UNIT E5551DATA
001CH 0004H *** GAP ***
BIT 0020H.0 0000H.1 UNIT E5551BIT
BIT 0020H.1 0000H.1 UNIT BITDATA
0020H.2 0000H.6 *** GAP ***
DATA 0021H 0023H UNIT PROTDATA
IDATA 0044H 0010H UNIT STACK

the address of the last variable in segment "PROTDATA" is 21H + 23H -1 = 43h so
since the stack pointer starts from 44h this seems ok (no overlaps). But at
the beginning of my code j have the following lines :

CSEG AT 0 ; absolute Segment at Address 0
LJMP start ; reset location (jump to start)

org 23h
;Serial Rx/Tx interrupt
ljmp SerialInt

maincode SEGMENT CODE

RSEG maincode ; switch to this code segment


start:
MOV SP,#STACK-1 ; assign stack at beginning
;...
;....

So the stack pointer begins at 044h -1 = 043h the same address of the last variable in
PROTDATA. J don't understand why pointing to #STACK -1 !!
Please help me!

0