#72268 - aaronphughes - Fri Feb 17, 2006 8:04 am
I have the following code that calculates an IP checksum, as in the checksum found in an IP header. I have included the code. Can it be optimzed any better?
Thanks,
AH
b MainFunction
UnitTest1:
@DCW 0x0100, 0xF203, 0xF4F5, 0xF6F7
@DCW 0x0000, 0x0000, 0x0000, 0x0000 ;; ChkSum = 0x210E
UnitTest2:
@DCW 0x45C0, 0x0044, 0xad22, 0x0159
@DCW 0xAC14, 0x7143, 0xE000, 0x0005 ;; ChkSum = 0x0E22
UnitTest3:
@DCW 0x45C0, 0x0044, 0xDC15, 0x0159
@DCW 0xAC14, 0x7142, 0xE000, 0x0005 ;; ChkSum = 0xDF2F
MainFunction:
ldr R1,=UnitTest1 ;; This is the ADDRESS of my UnitTest Data
ldr R2,=8 ;; Size of the array of 16 bit words
mov R3,#0 ;; clear this guy out
ldr R4,=0xFFFF ;; MASK for lower 16 bits
lbl_AddTheData1:
ldr R5,[R1]+2!, ;; get value @ R1, put into R4, inc R1 by 2 - moves to next word
and R5, R5, R4 ;; only want lower 16 bits
add R3, R3, R5 ;; sum these values
subs R2, R2, 1 ;; dec by 1
bne lbl_AddTheData1 ;; Repeat until we hit the end of the array
lbl_AdditionComplete:
;;mov R2, R3, LSR #16 ;; The upper 16-bits are the carries
;;add R3, R3, R2 ;; Add the carries to the sum in R3
add R3, R3, R3 LSR #16 ;; The above two lines in one command
EOR R3, R3, R4 ;; NOT R3
and R3, R3, R4 ;; Only want the lower 16-bits
EndOfProgram:
B EndOfProgram
_________________
urpNO_SPAM_MAN@canerdian.ca
http://www.canerdian.ca
Thanks,
AH
b MainFunction
UnitTest1:
@DCW 0x0100, 0xF203, 0xF4F5, 0xF6F7
@DCW 0x0000, 0x0000, 0x0000, 0x0000 ;; ChkSum = 0x210E
UnitTest2:
@DCW 0x45C0, 0x0044, 0xad22, 0x0159
@DCW 0xAC14, 0x7143, 0xE000, 0x0005 ;; ChkSum = 0x0E22
UnitTest3:
@DCW 0x45C0, 0x0044, 0xDC15, 0x0159
@DCW 0xAC14, 0x7142, 0xE000, 0x0005 ;; ChkSum = 0xDF2F
MainFunction:
ldr R1,=UnitTest1 ;; This is the ADDRESS of my UnitTest Data
ldr R2,=8 ;; Size of the array of 16 bit words
mov R3,#0 ;; clear this guy out
ldr R4,=0xFFFF ;; MASK for lower 16 bits
lbl_AddTheData1:
ldr R5,[R1]+2!, ;; get value @ R1, put into R4, inc R1 by 2 - moves to next word
and R5, R5, R4 ;; only want lower 16 bits
add R3, R3, R5 ;; sum these values
subs R2, R2, 1 ;; dec by 1
bne lbl_AddTheData1 ;; Repeat until we hit the end of the array
lbl_AdditionComplete:
;;mov R2, R3, LSR #16 ;; The upper 16-bits are the carries
;;add R3, R3, R2 ;; Add the carries to the sum in R3
add R3, R3, R3 LSR #16 ;; The above two lines in one command
EOR R3, R3, R4 ;; NOT R3
and R3, R3, R4 ;; Only want the lower 16-bits
EndOfProgram:
B EndOfProgram
_________________
urpNO_SPAM_MAN@canerdian.ca
http://www.canerdian.ca