??? 07/29/06 08:31 Read: times |
#121302 - Optimisations Responding to: ???'s previous message |
Whenever you're repeating much the same thing over again you can usually use a loop. Also, with your strings, most of them are the same execpt for the number and on or off.
So you could split the strings as such: device_str db CR,LF,'Device.',0 on_str db 'ON',0 off_str db 'OFF',0 You've saved quite a few bytes just by doing this. To loop you stats code you could do something like this (don't expect it to be 100% correct!!!) ; ; uses R1,R2 ; print_status: mov r1,device ;I normally have constants as upper case mov r2,#0 ;input# ps_lp: mov dptr,#device_str acall pstring ;print string->dptr mov a,r2 ;get input# add a,#'0' ;convert # to ascii acall pchar ;out the serial port mov a,r1 ;get bit statuses rrc a mov r1,a ;shift bit status into Carry jc ps_on mov dptr,#off_str ;if status was OFF sjmp ps_1 ps_on: mov dptr,#on_str ;if status was ON ps_1: acall pstring inc r2 ;next input cjne r2,#8,ps_lp ret ;job done As you can see the code is a lot more compact and still has the same ouput. I usually have routines called pstring and pchar. pchar just sends a character out the serial port (or to a lcd) and pstring does the same as you routine named disp_message except it would call pchar for the character output. This means if you wanted to change the output destination, you would only have to change the pchar code. Sure, doing this means you use more stack, but unless pressed, it makes you life easier. If you divide your routines up nicely, then that makes changes a lot easier in the future. |