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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/16/01 05:29
Read: times


 
#15718 - RE: Converting my o/p to drive LCD disp
neil,

when someone hands me some assembly language programm and says, 'its doing something completely unexpected'...

i say 'great! those are clues to learn by.'

on your code:

the advantage of the @a+dptr is that you can keep the dptr unchanged as the top of table (as long as you only reach into to a 256 byte page) and use the accumulator as the offset. sometimes you can merely change the high byte of the dptr pair to strategically switch between two associated buffers or to page into the next 256 bytes of the buffer.

i tend to use an r register for the pointer offset since its fast to increment and can be swapped or moved quickly from the accumulator.

i avoid dptr use in preference to r0 and r1 relative addressing but dptr is good for novices. most people overuse it and so we have secondary dptrs in many micros. @r0 and @r1 can be incredible if you really plan your systems implementation before you go coding (here i'm talking to seasoned programmers).

;--------------------
init:
mov dptr,#table
clr r2 ;pointer
jp begin

loop:
call careful.of.registers.changed.comm
inc r2 ;bump protected for next fetch

begin:
mov a,r2 ;load pointer
movc a,@a+dptr ;fetch from table

;does movc a,@a+dptr change the z-flag?
;maybe a logical op is needed first?
jnz loop ;jif while more, exif not
;else done
;--------------------

i folded a jump out of the loop and that probably looks odd. i did that to reduce having two jumps inside the loop... one jump for the test for exit, and the second jump for the loop. while i still have two opcode jumps... the initialization jump is executed only once. its useful to think about which lines repeat a lot and which are flowed through once.

in the classic structure, you'd have a test to exit that gets tried every loop but only jumped on the last pass, plus the jump to do the next loop. that's a little more microcontroller time wasted.

;initialize
:loop
;bump&load pointer
;fetch character
;exif end of buffer
;send character otherwise
;go to loop
exit:

this is easier to read but embeds a jump inside the loop unnecessarily.

sometimes it matters. sometimes the byte counts are more important, sometimes the operation time is more important, and sometimes clarity is more important. being able to see many ways to do the same thing, give you the ability to adapt for the application.

advice: experiment with cryptic looking code but avoid it on the job - showing off just wastes everyone's time when its later modified. I had to work on some code done by a Hawaiian Z-80 programmer that was showing off by having entry points in the middle of opcodes. yeah it worked and only the smart guys could see what he was doing, but it wasted company time and increased the odds someone would later patch the code incorrectly.

(i don't have my 8051 bible handy and couldn't look up any opcode information so you'll have to answer the challenges in the comments).

you could also use your fixed text length as a control on a djnz loop:

;--------------------
init:
mov dptr,#table
clr r2 ;pointer
mov r3,#8 ;string length
jp begin

loop:
call careful.of.registers.changed.comm
inc r2 ;bump protected for next loop

begin:
mov a,r2 ;load pointer
movc a,@a+dptr ;fetch from table
djnz r3,loop ;jif more, exif done
;else done
;--------------------

duh


List of 39 messages in thread
TopicAuthorDate
Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD display            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
ISA card            01/01/70 00:00      
RE: Converting my o/p to drive LCD disp            01/01/70 00:00      
Up/Doen counting inat89c52            01/01/70 00:00      

Back to Subject List