| ??? 04/22/05 14:38 Read: times |
#92161 - Examining the assembly Responding to: ???'s previous message |
When in doubt, it is not necessary to rewrite in asm, just have a look at the asm generated by the compiler. I have found many reasons that my C did not work by looking at the assembler and then slapping my forehead, saying Oh .... I don't yet know if my C is faulty, but the below sequence looks a little strange to me, in respect to the clearing of the variable "c", which is - as far as I can tell, used nowhere, neither in this snippet nor anywhere below it. Or is the "c" the carry-bit? -------------------------------------- ; while(1)
; SOURCE LINE # 58
; {
; SOURCE LINE # 59
; P1 ^= 0x10; // Toggles every 8th usec, 125 kHz
; SOURCE LINE # 60
XRL P1,#010H
;
; if(timer0_tick >= 14) /* Timer input = OSC/12 = 921.600 kHz */
; SOURCE LINE # 62
MOV DPTR,#timer0_tick
MOVX A,@DPTR
CLR C
XRL A,#080H
SUBB A,#08EH
JC ?C0006
; { /* => 14 overflows per second */
; SOURCE LINE # 63
; secs++;
; SOURCE LINE # 64
MOV DPTR,#secs+01H
MOVX A,@DPTR
INC A
MOVX @DPTR,A
JNZ ?C0011
MOV DPTR,#secs
MOVX A,@DPTR
INC A
MOVX @DPTR,A
?C0011:--------------------------------------
Why would we want to only continue mangling with "secs" if the accumulator is not zero? Incrementing it makes it "never zero", doesn't it? But then again - why does this piece of code try to access "secs" at an address 1 bit higher than it ought to be (#secs+01h)? -------------------------------------- ; timer0_tick = 0; ; SOURCE LINE # 65 CLR A MOV DPTR,#timer0_tick MOVX @DPTR,A ; P1 ^= 0x01; ; SOURCE LINE # 66 XRL P1,#01H ; } ; SOURCE LINE # 67 ?C0006:-------------------------------------- I understand the last part and it seems logical - resetting the accumulator to zero, moving the address of "timer0_tick" into a pointer and then moving the contents of the accumulator to the gathered address. Or'ing P1 with 01 hex toggles P1.0. /Thomas |



