ASM Code - this is weird...
CannibalRobotics
Posts: 535
OK, I'm up to my chin in my first assembly language project. I'm running into a weird problem. I have seen this in the 8085·world but I don't know if my diagnosis would apply here.
Situation: I've got two blocks of code, "transmit" and "receive". Both work great and have been extensively tested.
Now I'm trying to call them alternately so I set up a call loop:
MainLoop··············· CALL·· #transmit
······················· CALL···#receive
······························ ' little bit of code
······························ ' ...
······························ '
······················· JMP··· #MainLoop
transmit··············· CALL·· TxON
······························ ' lots of code
·······························' ...
······························ '
transmit_ret
······················· ret
receive················ CALL·· RxON
······························ ' lots of code
······························ ' ...
······························ '
receive_ret
······················· ret
This loops in MainLoop and executes the transmit segment completely then·the very top CALL in the receive routine (RxON) which turns on the reciever. The scope verifies the receiver is getting turned on.·The program·then jumps back to the very top of the MainLoop.
If I restructure the program to tell transmit to jump to the top of receive then vice versa, it works.
MainLoop··············· NOP
MainLoopT·············· JMP···· #transmit
MainLoopR·············· JMP···· #receive
······················· JMP···· #MainLoop
·
transmit··············· CALL··· TxON
······························· ' lots of code
······························ ·' ...
······························ ·'
transmit_ret
······················· JMP···· #MainLoopR
·
receive ··············· CALL··· RxON
······························· ' lots of code
······························· ' ...
································'
receive_ret
·········· JMP··· #MainLoopT
The second layout is unaccepateble as I need to do some bit setting between transmit and recieve and the CALLs to them will need to be conditional. Anyway, the problem seems to lie in the CALL statements - it is as if the return address is not getting pushed properly onto the pointer stack.
Is there some limit on how many calls can be nested in an assembly language program?
When compiling, where is the·stack pointer and how do I know if I have·left enough space to push·nested call return addresses 3 or 4 deep?
In the 8085 world one can use POP PSW to look at the processor status and pointer but I don't know how to proceed on debugging this one.
Any suggestions?
Thanks,
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent, only $1.
Send cash and signature to CannibalRobotics.
Situation: I've got two blocks of code, "transmit" and "receive". Both work great and have been extensively tested.
Now I'm trying to call them alternately so I set up a call loop:
MainLoop··············· CALL·· #transmit
······················· CALL···#receive
······························ ' little bit of code
······························ ' ...
······························ '
······················· JMP··· #MainLoop
transmit··············· CALL·· TxON
······························ ' lots of code
·······························' ...
······························ '
transmit_ret
······················· ret
receive················ CALL·· RxON
······························ ' lots of code
······························ ' ...
······························ '
receive_ret
······················· ret
This loops in MainLoop and executes the transmit segment completely then·the very top CALL in the receive routine (RxON) which turns on the reciever. The scope verifies the receiver is getting turned on.·The program·then jumps back to the very top of the MainLoop.
If I restructure the program to tell transmit to jump to the top of receive then vice versa, it works.
MainLoop··············· NOP
MainLoopT·············· JMP···· #transmit
MainLoopR·············· JMP···· #receive
······················· JMP···· #MainLoop
·
transmit··············· CALL··· TxON
······························· ' lots of code
······························ ·' ...
······························ ·'
transmit_ret
······················· JMP···· #MainLoopR
·
receive ··············· CALL··· RxON
······························· ' lots of code
······························· ' ...
································'
receive_ret
·········· JMP··· #MainLoopT
The second layout is unaccepateble as I need to do some bit setting between transmit and recieve and the CALLs to them will need to be conditional. Anyway, the problem seems to lie in the CALL statements - it is as if the return address is not getting pushed properly onto the pointer stack.
Is there some limit on how many calls can be nested in an assembly language program?
When compiling, where is the·stack pointer and how do I know if I have·left enough space to push·nested call return addresses 3 or 4 deep?
In the 8085 world one can use POP PSW to look at the processor status and pointer but I don't know how to proceed on debugging this one.
Any suggestions?
Thanks,
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent, only $1.
Send cash and signature to CannibalRobotics.
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cardinal Fang! Fetch the comfy chair.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent, only $1.
Send cash and signature to CannibalRobotics.
Main
········· CALL #A
········· JMP·· #Main
A
········· CALL #B
A_ret···· ret
B
········· CALL #C
B_ret·····ret
C
C_ret···· ret
I know not posting the code is problematic but it's on my shop machine and I'm at home today.
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent, only $1.
Send cash and signature to CannibalRobotics.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cardinal Fang! Fetch the comfy chair.
The receive_ret instruction is the problem.
I've been looking at as just another label and I was doing some house cleaning before departing the routine. ie:
receive_ret·········MOV···· ComState,#1··· ' Set to transmit
····················ret··················· ' Done with recieve
This would put the address in the wrong place and cause all sorts of weird behaviors.
Thanks,
Jim-
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent, only $1.
Send cash and signature to CannibalRobotics.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cardinal Fang! Fetch the comfy chair.