Peer review
At the time of writing this issue, you haven't finished the lab. Neither codgen()
nor decode()
has been implemented in C. Because of this there isn't really anything to review unfortunately.
unsigned int seed = 0;
unsigned int codegen(unsigned int *seed_addr) {
unsigned int seed = seed * 0x343FD + 0x269EC3;
*seed_addr = seed
return (seed >> 16) & 0x7FFF;
}
I could at least mention that you're initializing seed
before the codegen()
function, but in the codegen()
function you declare it again, which I think leads to you multiplying with an uninitialized variable. I'm also not sure what you're trying to do here, I recommend implementing the pseudocode line by line:
FUNCTION codgen(): UNSIGNED INTEGER;
LOCAL SIGNED INTEGER n;
LOCAL UNSIGNED INTEGER x, y;
BEGIN
n := [count the number of 0's in word "seed"];
x := [multiply "seed" by the constant 2];
y := [divide "seed" (unsigned !) by the constant 32];
seed := x + y + n; [ignore overflow condition]
RETURN( seed XOR 0x1e4aea1c );
END;
Feel free to ask if you need any help or if you have any questions, also keep in mind that there is a #lab-help
channel on Discord where you can request help for the lab.
Good luck!