need help understanding some Assembly code
The codes below are from an example found in this forum used for reading DS1302 timekeeping chip and displaying the values on an LCD .
I was analysing the ASM equiv of the SX/B code block below in order to fully understand the SHIFTOUT implementation in ASM coding.
FROM the· assembled output lst file
·179· =000000BF······ BurstRead···· EQU· $BF···
·.....
·......
·508· 015E· 0CBF······· MOV __PARAM1,#(BurstRead & 255)
······· 015F· 0028
·· 509· 0160· 0C00······· MOV __PARAM2,#(BurstRead >> 8)
······· 0161· 0029
·.......
·.......
·.......
What is the end value stored in __PARAM1 as well as __PARAM2 , and why the assembler used this technique instead of directly using the valye of the constant ?
What is the purpose of using __PARAM2 variable in the loop knowing that it is only referenced at line 517
with one command RR __PARAM2· only ?
--- Source SX/B· code
GetTimeAndDate:
·HIGH RTCCS····' start transaction
·SHIFTOUT Dta, Clk, LSBFIRST, BurstRead·' write address
·FOR Idx = Secs TO Ctrl···' read time registers
·SHIFTIN Dta, Clk, LSBPRE, TimeDate(Idx)
·NEXT
·LOW RTCCS
RETURN
End SX/B Code
Complete Block···
·· 491· =0000014B······ GetTimeAndDate:················· ;GetTimeAndDate:
·· 492·················
·· 493· 014B· 0545······· SETB RTCCS···················· ;····· HIGH RTCCS····························· ' start transaction
·· 494· 014C· 0CFA······· MOV FSR,#__TRISA·············
······· 014D· 0024
·· 495· 014E· 0440······· CLRB IND.2···················
·· 496· 014F· 005F······· MODE $0F·····················
·· 497· 0150· 0200······· MOV !RA,IND··················
······· 0151· 0005
·· 498· 0152· 0018······· BANK $00·····················
·· 499· 0153· 0545······· SETB RTCCS···················
·· 500·················
·· 501· 0154· 0C08······· MOV __PARAM3,#8············· ; SHIFTOUT Dta, Clk, LSBFIRST, BurstRead· ' writeadress
······· 0155· 002A
·· 502· 0156· 0CFA······· MOV FSR,#__TRISA·············
······· 0157· 0024
·· 503· 0158· 005F······· MODE $0F·····················
·· 504· 0159· 0420······· CLRB IND.1···················
·· 505· 015A· 0400······· CLRB IND.0···················
·· 506· 015B· 0200······· MOV !RA,IND··················
······· 015C· 0005
·· 507· 015D· 0018······· BANK $00·····················
·· 508· 015E· 0CBF······· MOV __PARAM1,#(BurstRead & 255)
······· 015F· 0028
·· 509· 0160· 0C00······· MOV __PARAM2,#(BurstRead >> 8)
······· 0161· 0029
·· 510· 0162· 0708······· MOVB Dta,__PARAM1.0··········
······· 0163· 0425 0608 0525
·· 511· 0166· 0C05······· MOV __PARAM4,#5··············
······· 0167· 002B
·· 512· 0168· 02EB······· DJNZ __PARAM4,@$·············
······· 0169· 0010 0B68
·· 513· 016B· 0C01······· XOR RA,#%00000001············
······· 016C· 01A5
·· 514· 016D· 0C05······· MOV __PARAM4,#5··············
······· 016E· 002B
·· 515· 016F· 02EB······· DJNZ __PARAM4,@$·············
······· 0170· 0010 0B6F
·· 516· 0172· 0C01······· XOR RA,#%00000001············
······· 0173· 01A5
·· 517· 0174· 0329······· RR __PARAM2··················
·· 518· 0175· 0328······· RR __PARAM1··················
·· 519· 0176· 02EA······· DJNZ __PARAM3,@$-20··········
······· 0177· 0010 0B62
·· ----
·· ----
·· ----
Regards
·
I was analysing the ASM equiv of the SX/B code block below in order to fully understand the SHIFTOUT implementation in ASM coding.
FROM the· assembled output lst file
·179· =000000BF······ BurstRead···· EQU· $BF···
·.....
·......
·508· 015E· 0CBF······· MOV __PARAM1,#(BurstRead & 255)
······· 015F· 0028
·· 509· 0160· 0C00······· MOV __PARAM2,#(BurstRead >> 8)
······· 0161· 0029
·.......
·.......
·.......
What is the end value stored in __PARAM1 as well as __PARAM2 , and why the assembler used this technique instead of directly using the valye of the constant ?
What is the purpose of using __PARAM2 variable in the loop knowing that it is only referenced at line 517
with one command RR __PARAM2· only ?
--- Source SX/B· code
GetTimeAndDate:
·HIGH RTCCS····' start transaction
·SHIFTOUT Dta, Clk, LSBFIRST, BurstRead·' write address
·FOR Idx = Secs TO Ctrl···' read time registers
·SHIFTIN Dta, Clk, LSBPRE, TimeDate(Idx)
·NEXT
·LOW RTCCS
RETURN
End SX/B Code
Complete Block···
·· 491· =0000014B······ GetTimeAndDate:················· ;GetTimeAndDate:
·· 492·················
·· 493· 014B· 0545······· SETB RTCCS···················· ;····· HIGH RTCCS····························· ' start transaction
·· 494· 014C· 0CFA······· MOV FSR,#__TRISA·············
······· 014D· 0024
·· 495· 014E· 0440······· CLRB IND.2···················
·· 496· 014F· 005F······· MODE $0F·····················
·· 497· 0150· 0200······· MOV !RA,IND··················
······· 0151· 0005
·· 498· 0152· 0018······· BANK $00·····················
·· 499· 0153· 0545······· SETB RTCCS···················
·· 500·················
·· 501· 0154· 0C08······· MOV __PARAM3,#8············· ; SHIFTOUT Dta, Clk, LSBFIRST, BurstRead· ' writeadress
······· 0155· 002A
·· 502· 0156· 0CFA······· MOV FSR,#__TRISA·············
······· 0157· 0024
·· 503· 0158· 005F······· MODE $0F·····················
·· 504· 0159· 0420······· CLRB IND.1···················
·· 505· 015A· 0400······· CLRB IND.0···················
·· 506· 015B· 0200······· MOV !RA,IND··················
······· 015C· 0005
·· 507· 015D· 0018······· BANK $00·····················
·· 508· 015E· 0CBF······· MOV __PARAM1,#(BurstRead & 255)
······· 015F· 0028
·· 509· 0160· 0C00······· MOV __PARAM2,#(BurstRead >> 8)
······· 0161· 0029
·· 510· 0162· 0708······· MOVB Dta,__PARAM1.0··········
······· 0163· 0425 0608 0525
·· 511· 0166· 0C05······· MOV __PARAM4,#5··············
······· 0167· 002B
·· 512· 0168· 02EB······· DJNZ __PARAM4,@$·············
······· 0169· 0010 0B68
·· 513· 016B· 0C01······· XOR RA,#%00000001············
······· 016C· 01A5
·· 514· 016D· 0C05······· MOV __PARAM4,#5··············
······· 016E· 002B
·· 515· 016F· 02EB······· DJNZ __PARAM4,@$·············
······· 0170· 0010 0B6F
·· 516· 0172· 0C01······· XOR RA,#%00000001············
······· 0173· 01A5
·· 517· 0174· 0329······· RR __PARAM2··················
·· 518· 0175· 0328······· RR __PARAM1··················
·· 519· 0176· 02EA······· DJNZ __PARAM3,@$-20··········
······· 0177· 0010 0B62
·· ----
·· ----
·· ----
Regards
·
Comments
You can actually shiftout WORD variables. SX/B uses the same code whether the variable is a word or a byte.
If you are converting to ASM you can just load __PARAM1 with the byte value and forget about __PARAM2.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.iElectronicDesigns.com
·