From: Maciej Witkowiak (ytm_at_elysium.pl)
Date: 2003-08-19 16:14:17
Well, all you people downloading ISOz on your 6502 machinez can check md5 sums
now :)
I didn't bother to write a full-featured md5sum program, just take a reference
implementation from RFC 1321, rewrite function headers and use cc65 on it.
The reason I write here about it is that one functions needs to be changed and
I don't know if it is or not cc65 bug or should I read the docs.
Here is the original code (UINT4 is unsigned long int):
static void Decode (UINT4 *output, unsigned char *input, unsigned int len) {
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
}
It doesn't work correctly.
Here is a version that works:
static void Decode (UINT4 *output, unsigned char *input, unsigned int len) {
unsigned int i, j;
union { char tab[4];
UINT4 tabl; } uni;
for (i = 0, j = 0; j < len; i++, j += 4) {
uni.tab[0]=input[j]; uni.tab[1]=input[j+1];
uni.tab[2]=input[j+2]; uni.tab[3]=input[j+3];
output[i]=uni.tabl;
}
}
There's more:
#define UINT4 unsigned long int
unsigned char input[4];
UINT4 output[1];
void foo(void) {
unsigned int i,j;
output[0]=i=j=0;
input[0]=0x01; input[1]=0x02; input[2]=0x03; input[3]=0x04;
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
printf("%lu ",output[i]);
output[i] = (UINT4)input[j];
printf("%lu ",output[i]);
}
With gcc I get:
67305985 1
With cc65 (CVS HEAD, with and without -Osir) I get:
3048407553 65537
ytm
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2003-08-19 16:19:23 CEST