Q1 shieldMe: oldEbp = 0 retAddr = oldEbp + 4 pShielded = retAddr + 4 n = pShielded + 4 op = n + 4 // PROBLEM: shield = oldEbp - 256 pushl %ebp movl %esp,%ebp // PROBLEM: addl $shield,%esp pushl %eax pushl %ebx pushl %ecx pushl %edx movl n(%ebp),%ecx // ecx is n cmpl $256,%ecx // compare n with 256 jb L1 // jmp iff n < 256 movl $256,%ecx // else n <- 256 // end if L1: // ecx is n movl $0,%eax // eax is i, i <- 0 L2: cmpl $0,%ecx // jz L3 // iff n == 0 jmp L3 // PROBLEM PROBLEM PROBLEM!!!!! // movb pShielded(%ebp,%eax),%bl movl pShielded(%ebp),%edx movb (%edx,%eax),%bl // END PROBLEM movb %bl,shield(%ebp,%eax) addl $1,%eax // PROBLEM: subl $1,%ecx jmp L2 // end of for L3: pushl %ebp // PROBLEM // addl shield,(%esp) addl $shield,(%esp) // END PROBLEM call *op(%ebp) addl $4,%esp popl %edx popl %ecx popl %ebx popl %eax // NOT A PROBLEM: subl $shield, %esp movl %ebp,%esp popl %ebp ret Q2: strcat: oldEbp = 0 retAddr = oldEbp + 4 dest = retAddr + 4 src = dest + 4 pushl %ebp movl %esp,%ebp pushl %eax pushl %ebx pushl %ecx movl dest(%ebp),%eax // eax is dest L1: cmp (%eax),$0 // cmp should be cmpb // reverse the operands jz L2 addl $1,%eax jmp L1 // end while L2: movl src(%ebp),%ebx // ebx is src L3: // begin while movb (%ebx),(%eax) // this is not allowed movb (%ebx),%cl movb %cl,(%eax) cmpb %cl,$0 // reverse the operands jnz L4 // jnz should be jz addl $1,%ebx addl $1,%eax jmp L2 // end while // PROBLEM L3, not L2 L4: popl %ecx popl %ebx popl %eax movl dest(%ebp),%eax movl %ebp,%esp popl %ebp ret modX: oldEbp = 0 retAddr = oldEbp + 4 pX = retAddr + 4 pushl %ebp movl %esp,%ebp pushl %eax pushl %ebx pushl %ecx pushl %edx movl pX(%esp),%eax // eax is pX movl X_myValue(%eax),%ebx // ebx is pX->myValue movl (%ebx),%ebx // PROBLEM ebx is *(pX->myValue) // remove it addl X_peers,%eax // eax is &pX->peers // eax is the base address of // the peers array of the // struct X pointed to by // pX // the address of the first // element (says Willow) movl %eax,%edx // edx is &pX->peers addl $X_size*NPEERS,%edx // PROBLEM: X_size // should be 4 // edx points to the byte // immediately following // the peers array L1: cmpl %eax,%edx // compare eax with the // end address of the array jz L2 movl X_myValue(%eax),%ecx // PROBLEM // new code: movl (%eax),%ecx // this is the fix movl %ebx,X_myValue(%ecx) addl $4,%eax jmp L1 L2: popl %edx popl %ecx popl %ebx popl %eax movl %ebp,%esp popl %ebp ret