Why my Z80 won't RET after CALL?

Discussion in 'Programmer's Corner' started by slowmo, Aug 25, 2006.

  1. slowmo

    Thread Starter New Member

    Aug 4, 2006
    6
    0
    I have a simple circuit using a Z80 and a 29C256, the program on the eprom(with the opcodes and addresses) is:

    0000 3E 01 LD A,01H
    0002 CD 0A 00 START: CALL TEST
    0005 0E 03 LD C,03H
    0007 C3 02 00 JP START

    000A 06 02 TEST: LD B,02H
    000C C9 RET

    The problem I have is, after "CALL TEST" is executed, the program will jump to the "TEST" subroutine but on executing "RET", it won't return to address 0005h("LD C,03H") but instead will start right from address 0000h("LD A,01H") again. You can see the logic analyser screen cap by cutting and pasting this link to your browser.

    http://kalawala.freewebspace.com/LAcap.jpg

    The circuit is very simple with the Z80's and the 29C256's address lines together, the data lines together, RD goes to the eprom's OE, WR to WE, the eprom's CE is tied low. The Z80's control lines(RESET, INT, NMI, BUSRQ, WAIT) are all pulled high, all other control lines are not connected. For a copy of the Z80 manual & spec., you can get one here:

    http://www.z80.info/zip/z80cpu_um.pdf

    Any help will be greatly appreciated. Thank you all in advance.
     
  2. thingmaker3

    Retired Moderator

    May 16, 2005
    5,072
    6
    You are calling 00A0 but your routine is located at 000A.
     
  3. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    greetings slowmo,

    I suspect that you have not set up your "STACK" pointer register. I would read up on setting up the Z80 stack pointer. When you make a subroutine call, the microprocessor uses the stack pointer to know where to place the return address. If the stack pointer is not set to point to a valid ram address then the return from the subroutine will end up going to an address that may or may not be valid.

    hgmjr
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,789
    Do you have any RAM in your system for the Z80 to store a return address in? It won't do you much good to setup the stack pointer if there is no place to put anything.

    A Z80 is NOT a single chip microcontroller!
     
  5. slowmo

    Thread Starter New Member

    Aug 4, 2006
    6
    0
    Thank you for the advice gentlemen.

    This is one of my major boo-boo(again), as a novice I just think that the Z80 will save the PC in some internal memory/register when a CALL instruction is executed. And on second thought, this really doesn't make a whole lot of sense. NOW I know I have to put in some RAM to make it work! :)

    Thank you once again for saving my day, Papabravo; as far as I remember, this is the second time. You gotta stick around on this site!
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,789
    No problem. We learn the best lessons when we stumble and fall. I was once where you are now. I made different mistakes, but the feeling of relief when I fixed them was the same.
     
Loading...