Q1: do_begin: # do { movl i,%eax # if (i < j) cmpl j,%eax jnl else addl $1,i # ++i jmp endif else: # else subl $1,j # --j endif: movl i,%eax # } while (i + k < j); addl k,%eax cmpl j,%eax jl dO_begin Q2: oldEbp = 0 retAddr = oldEbp + 4 x = retAddr + 4 p = x + 4 myX = oldEbp - X_size # myX versus y is not important, but y = myX - 4 # the amount of space allocated together is Q3: movl p(%ebp),%eax # eax points to whatever p points to movl X_i(%eax),%eax # copy field i of that to eax addl x(%ebp),%eax # add x to that pushl %eax # save it for later movl $X_size,%eax # compute offset to element movl x(%ebp),%ebx mull %ebx # eax is now the offset to element popl myX+X_i(%ebp,%eax) # myX+%ebp is the base of the array # myX+%ebp+%eax is the base of the # element # myX+%ebp+%eax+X_i is the address # of field i of the element Q4: X_f1 = 0 X_f2 = X_f1 + 4 X_f3 = X_f2 + 16 X_size = X_f3 + 4 # f3 is a pointer, not a struct X! Y_buffer = 0 Y_f2 = X_size * 4 # this is the tricky part Y_size = X_f2 + 4 Q5: movl i(%ebp),%eax # eax is i movl $X_size,%ebx mull %ebx # eax is offset to element from array base addl $Y_buffer,%eax # eax is offset to element from # the base of a struct Y addl py(%ebp),%eax # py is the base of a struct Y, so now # eax is the address of element i of the # field "buffer" of whatever py points to pushl %eax # push it as parameter call sub1 # call addl $4,%esp # clean up the stack (popl %eax is fine) movl py(%ebp),%eax # eax points to a struct Y addl $1,Y_f2(%eax) # add one to field "f2" of whatever py points to Q6: pushl pSecond(%ebp) # save the pointer value, not what it points to movl pFirst(%ebp),%eax # eax points to a struct X popl X_f3(%eax) # update field "f3" of whatever pFirst points # to using whatever we saved on the stack