??? 09/07/06 10:19 Read: times |
#123810 - quiz of the week |
In '51 asm, when moving a multi-byte variable from internal location say "Source" to "Destination", the following loop is often used (for example, let the variables be 4-byte long, LSB first): mov r0,#Source mov r1,#Destination ;set up pointers mov r2,#4 ;set up counter (4 bytes per word) Loop: mov a,@r0 ;pick a byte from source inc r0 ; and advance pointer mov @r1,a ;store the byte to destination inc r1 ; and advance pointer djnz r2,Loop ;loop until end However, a register, and one cycle can be spared using the following equivalent loop - the point is, that we know beforehand, where does the "Source" field (and also Destination) end: mov r0,#Source mov r1,#Destination ;set up pointers Loop: mov a,@r0 ;pick a byte from source inc r0 ; and advance pointer mov @r1,a ;store the byte to destination inc r1 ; and advance pointer cjne r0,#Source+4,Loop ;loop until end Now if we apply this to addition: mov r0,#Source mov r1,#Destination ;set up pointers clr c ;clear carry for the first (LSB) addc Loop: mov a,@r0 ;pick a byte from source inc r0 addc a,@r1 ;add the byte from destination mov @r1,a ;store back to destination inc r1 ; and advance pointer cjne r0,#Source+4,Loop ;loop until endsomething is wrong. Why? Jan Waclawek PS. It's easy, so "old boys", please give the others a chance and keep quiet until at least friday noon. |
Topic | Author | Date |
quiz of the week | 01/01/70 00:00 | |
All "old boys" | 01/01/70 00:00 | |
4 p.m. here - OK, "old boys", your go... | 01/01/70 00:00 | |
4 pm | 01/01/70 00:00 | |
Too easy, CJNE also modifies the carry flag. | 01/01/70 00:00 | |
yeah, easy; still... | 01/01/70 00:00 | |
solution | 01/01/70 00:00 | |
old boy test![]() | 01/01/70 00:00 |