label_of_subroutine: # prologue of subroutine pushl %ebp # saves the old value of the EBP movl %esp,%ebp # freeze ebp so it is pointing # to a fixed point addl $offset_to_first_localvar,%esp # reserves space on the stack # for local variables .... # code of the subroutine # epilogue of subroutine movl %ebp,%esp popl %ebp # restore the ebp ret Mastermind scoring logic: each color is represented by an integer value 0-5 for 6 colors each element in the array represents a peg int original[4] int guess[4] int black = 0 int white = 0 # look for # of black pegs first for (i = 0; i < 4; ++i) if original[i] == guess[i] then ++black original[i] = -1 guess[i] = -2 end if end for # count the # of white pegs for (i = 0; i < 4; ++i) for (j = 0; j < 4; ++j) if (i <> j) and (original[i] == guess[j]) then ++white original[i] = -1 guess[j] = -2 end if end for end for struct Trial { int guess[4] int black int white }; void print10(unsigned int x) { char ch; ch = (x % 10) + '0'; if (x / 10 > 0) { print10(x / 10); } write(1, &ch, 1); }