Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

80c196kc and stack pointer

Status
Not open for further replies.

kasd

Member level 1
Joined
Nov 11, 2004
Messages
39
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,286
Location
Singapore
Activity points
359
196kc logic analyzer

Anyone has experience with intel 80c196kc and its stack pointer?

I have problem declaring my stack pointer to external memory address even though the datasheet says the stack can be located in external or internal.... I have hooked up the MCU data and address lines to a logic analyzer and found that the MCU goes wrong address after executing a subtract 2 from the stack pointer if the pointer reside in external memory.

PS: I am using IAR complier for the binary generation.
 

I had no problem with external stack with the 196KC, nevertheless I don't remember subtracting from stack pointer.

But, as the stack pointer itself is a SFR (at the same address and hwindow for both read and write), there should be something else. If you are working in C and messing around with the stack, I think you are doing a risky business; the compiler does not expect the user to do anything with the stack. Why are you attempting to do that?

How do you exactly doing the "subtract 2 from the stack pointer"? Can you post the compiled listing (containing assembly) of the relevant part?

wek
 

I did not do anything to the stack. It happens when the main function is entered as you can see below. I do not understand why the IAR compiler produces this assembly to subtract the SP too...

Anyhow if I point the SP to internal RAM at address 0x200 and below, it works nevertheless, even with that subtract on entering main.

Code:
      1          #include <IO196_KC.H>

   \                                 In segment NEAR_AC, at 0xf
   \   unsigned char volatile __near __IO_PORT1;
   \                     __IO_PORT1:
   \   000000                        DSB 1

   \                                 In segment NEAR_AC, at 0x10
   \   unsigned char volatile __near __IO_PORT2;
   \                     __IO_PORT2:
   \   000000                        DSB 1
      2          /**********************************************************************************************************
      3          *                                              CONSTANTS
      4          **********************************************************************************************************/
      5          
      6          /**********************************************************************************************************
      7          *                                              VARIABLES
      8          **********************************************************************************************************/
      9          
     10          /**********************************************************************************************************
     11          *                                         FUNCTION PROTOTYPES
     12          **********************************************************************************************************/
     13          
     14          
     15          /**********************************************************************************************************
     16          *                                                  MAIN
     17          **********************************************************************************************************/
     18          

   \                                 In segment CODE, align 2
     19          void main (void)
   \                     main:
   \   000000                        REQUIRE ?CL96KCSF_6_02_L08
     20          {
   \   000000   69020018             SUB     SP, #2
     21            volatile unsigned char x; 
     22                __IO_PORT1=0xFF;
   \   000004   B1FF..               LDB     ?GR+0:8, #255
   \   000007   C7000F..             STB     ?GR+0:8, 15:8[0]
     23                __IO_PORT2=0xFF;
   \   00000B   C70010..             STB     ?GR+0:8, 16:8[0]
     24                /* __IO_PORT2=0x00; */
     25                
     26            for(;;)
 

Ah I see. It is strange; nevertheless I don't C on 196KC.

Where do you try to set the SP at? What is your external memory arrangement? And how do you know the "MCU goes wrong address" and which address is it?

wek
 

I set the SP in the assembly startup file provided by the compiler/assembler.

The below assembly execute at address 0x2080 and #SFE(CSTACK) takes a value which I specified in a configuration. Why is it so complicated. Well, compiler/assembler default procedure.

The value of #SFE(CSTACK) can be specified by 0x0180 which works properly or 0x1700 which is not working properly.

Code:
RSEG    CSTART
	
startup:
	LD	SP,#SFE(CSTACK)	        ; From high to low addresses
 

If the stack is set at 0100-01FF, are you able to write to the RAM at 1600-16FF write and read back words? (in other words, is your external memory hardware OK?)

wek
 

I think the RAM is ok because when the SP is pointed to external address at 0x1700, the MCU is able to fetch from that external location. I checked this with the logic analyzer.

But after the MCU do the fetch @ address 0x1700 for the subtract, the MCU goes haywire by fetching data from address 0x0000 and then incrementally.

Maybe I should try another compiler.
 

Nonono! It should NOT fetch from 0x1700 for the sub sp,#2!!! It fetches the STACK POINTER at address 0x18 (it's a SFR), not the CONTENT of the stack!

What I think is happening is, that after you set the SP to 0x1700 a ret is executed; which fetches some garbage (most probably 0x0000), which then puts into PC and continues running from there...

Maybe you put the SP-setup into an incorrect place.

You should perhaps try to step through the generated hex/binary in some simulator?

wek

PS. I hope you are aware that putting the stack to external memory significantly degrades the performance of 196KC, especially if the stack is in an 8-bit RAM.
 

hi wek,

thanks for your replies so far.

after i read your reply, i realised i have made a wrong description of the program execution. here is what's happening after re-lloking at the LA capture.

Actual events captured:
after fetching the first instruction of the main function which is the SUB SP,#2. the MCU fetch from the location 0x14FE and get 0x0000. After that the MCU start to fetch data from 0x0000 onwards. I dont understand about getting from location 0x14FE because in the SP I have written 0x1700 as shown below. 0x14FE is just too far away.

location Machine Assembly
0x2080 A1001718 LD SP,#1700H
 

Well there might be something else between the LS SP,#1700h and SUB SP,#2, which changed the SP itself. I can't tell it without knowing the details so you need perhaps go through the whole LA instruction-by-instruction and decode what happens...

wek
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top