??? 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 RETThe 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 |