Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/05/05 13:34
Read: times


 
#98860 - Week puzzle
hi,

here is week puzzle from me.


I have made two subroutines.
First subroutine saves registers R0..R7, DPH, DPL and accuculator into stack area and the second subroutine restores their values back.
Both subroutines work perfect. I use them like:
A_SUBROUTINE:
	CALL	SAVE_CONTEXT
; a task
	CALL	RESTORE_CONTEXT
	RET
The questions is: what important care should I keep in mind when use these subroutines?

Some more details:
- the question is not about stack size; assume it is enough.
- the question is not about registers` banks; assume I use only one register bank over the whole program.
- the question is related to optimization of assembler code.


Here are the subroutines (wrote under Keil):
	USING	0

;-------------------------------------------------------------------------------;
; Preserve registers								;
;-------------------------------------------------------------------------------;
SAVE_CONTEXT:
	PUSH	ACC
	PUSH	AR0
	MOV	R0,SP
	PUSH	AR1
	PUSH	AR2
	PUSH	AR3
	PUSH	AR4
	PUSH	AR5
	PUSH	AR6
	PUSH	AR7
	DEC	R0
	DEC	R0
	DEC	R0
	MOV	A,DPH
	XCH	A,@R0
	PUSH	ACC
	INC	R0
	MOV	A,DPL
	XCH	A,@R0
	PUSH	ACC
	INC	R0
	MOV	A,@R0
	INC	R0
	MOV	AR0,@R0
	RET

;-------------------------------------------------------------------------------;
; Restore registers								;
;-------------------------------------------------------------------------------;
RESTORE_CONTEXT:
	POP	DPL
	POP	DPH
	POP	AR7
	POP	AR6
	POP	AR5
	POP	AR4
	POP	AR3
	POP	AR2
	POP	AR1
	MOV	R0,SP
	DEC	R0
	DEC	R0
	DEC	R0
	MOV	A,DPH
	XCH	A,@R0
	MOV	DPH,A
	INC	R0
	MOV	A,DPL
	XCH	A,@R0
	MOV	DPL,A
	POP	AR0
	POP	ACC
	RET

I`m waiting for your questions, ideas etc.

Regards,
Oleg

List of 53 messages in thread
TopicAuthorDate
Week puzzle            01/01/70 00:00      
   why is one a subroutine and another a ta            01/01/70 00:00      
      no RTOS            01/01/70 00:00      
   last there was discussion, in this an an            01/01/70 00:00      
      week            01/01/70 00:00      
   Last pushed in - first popped out            01/01/70 00:00      
      come in            01/01/70 00:00      
   Will it work?            01/01/70 00:00      
      Yes it will            01/01/70 00:00      
         Mmmmm?            01/01/70 00:00      
         And another thought            01/01/70 00:00      
            it's perfectly safe...            01/01/70 00:00      
               Still not convinced            01/01/70 00:00      
                  dangers            01/01/70 00:00      
                     Choices            01/01/70 00:00      
                        the same in real life            01/01/70 00:00      
                           Smart and Neat Code            01/01/70 00:00      
                              are you a math major? :)            01/01/70 00:00      
                                 Not a maths major            01/01/70 00:00      
                        yes            01/01/70 00:00      
                  what dangerous            01/01/70 00:00      
                     If misuse is chronic...            01/01/70 00:00      
   CALL + RET != JUMP            01/01/70 00:00      
      ?????????            01/01/70 00:00      
         oops Oleg Has the code to manage it sorr            01/01/70 00:00      
            return address            01/01/70 00:00      
      you got it!            01/01/70 00:00      
         Thanks for the puzzle :-)            01/01/70 00:00      
   a question            01/01/70 00:00      
      why not            01/01/70 00:00      
         well            01/01/70 00:00      
            optimisation            01/01/70 00:00      
               I have seen that happen when the require            01/01/70 00:00      
                  it's the same than if you miss a push or            01/01/70 00:00      
         The Trick is:            01/01/70 00:00      
   the answer            01/01/70 00:00      
      you never answered            01/01/70 00:00      
         solid or intermittent problem            01/01/70 00:00      
            difference between solid or intermittent            01/01/70 00:00      
   Why Push!!!            01/01/70 00:00      
      side effect            01/01/70 00:00      
         Another SAVE_CONTEXT            01/01/70 00:00      
            Sounds like a housekeeping nightmare            01/01/70 00:00      
               Sounds like a housekeeping nightmare            01/01/70 00:00      
               it IS a housekeeping nightmare            01/01/70 00:00      
                  Erik            01/01/70 00:00      
                     Pay no attention            01/01/70 00:00      
                        Donald, if you took the time to read wha            01/01/70 00:00      
                           Reading difficulties            01/01/70 00:00      
                              sorry, used wrong word            01/01/70 00:00      
                     no problem with any post, just with stat            01/01/70 00:00      
            maybe because            01/01/70 00:00      
      eh?            01/01/70 00:00      

Back to Subject List