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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/30/08 20:13
Read: times


 
#152720 - Does not ignore RET but...
Responding to: ???'s previous message
There are a number of 8051 assembly language coding techniques that have a trick of using the pushed "return address" in a unique way but skipping the RET is not one of them.

One technique I have used from time to time is the concept of "inlining" parameter(s) such as a string pointer as shown in following subroutine:
IL_PROC:
     POP   ACC             ; fetch high string address from stack
     MOV   DPH, A
     POP   ACC             ; fetch low string address from stack
     MOV   DPL, A
IL_LOOP:
     MOVC  A, @A+DPTR      ; get a byte of string
     INC   DPTR
     JZ    IL_END          ; exit the loop 
;
 ... (process the string byte in A register)...
;
     JMP   IL_LOOP
;
IL_END:
     MOV   A, DPL          ; restore return address
     PUSH  ACC
     MOV   A, DPH
     PUSH  ACC
     RET


A routine like the above is used in a manner like the following:
     CALL  IL_PROC
     DB    "Inline String", 0   ; must end string with zero byte.
     NOP                    ; this is the instruction returned to 
     NOP                    ; after the IL_PROC completes.


It is possible to make small modifications to the inline processing routine to deal with fixed length inline arguments such as this example that always passes two byte to the subroutine:
     CALL  IL_ROUTINE
     DB    2, 42        ; inline two fixed bytes.
     NOP                ; this is the instruction returned to 
     NOP                ; after the IL_ROUTINE completes.


Using this coding style can save many many bytes of code in a large program that calls low level subroutines from dozens and dozens of places that used some fixed content arguments. The savings comes from not having to load registers with values or a pointer before calling the subroutine. The code space savings comes at the expense of some extra processing cycles inside the called subroutine.

Note that in general there is less and less reason to use these techniques in modern project work because it is easy to find 8052 type MCUs that have nice amounts of code memory. In earlier times when on board code memory was much more limited these schemes allowed one to make a project "fit".

Michael Karas

Note: The code I typed into this posting has not been compiled and as such please make sure to test it carefully in your application if you should choose to implement the techniques.



List of 15 messages in thread
TopicAuthorDate
call routine problem            01/01/70 00:00      
   Yes, but...            01/01/70 00:00      
      call routine            01/01/70 00:00      
   what do you mean by "come out"?            01/01/70 00:00      
      call routine            01/01/70 00:00      
   Does not ignore RET but...            01/01/70 00:00      
      Good implementation            01/01/70 00:00      
         one of the reasons might be...            01/01/70 00:00      
         call routine            01/01/70 00:00      
            please explain...            01/01/70 00:00      
               Two things need explaining            01/01/70 00:00      
            Processor doesn't just ignore instructions!            01/01/70 00:00      
   I guess ...            01/01/70 00:00      
      call routine            01/01/70 00:00      
   use sjmp ljmp ajmp            01/01/70 00:00      

Back to Subject List