4.46 simplified --------------- Assume for example that a in in %esi and b in %edi, otherwise we would have to load the pointers. There is no cmp in Y86, we need a sub instead. In addition, we would need to "free" registers. 1) Version with 3 cmov. movmr (%esi),%eax ; eax = *a movmr (%edi),%ebx ; ebx = *b movrr %eax,%ecx ; copy ecx = eax sub %ebx,%ecx ; ecx -= ebx cmovl %eax,%ecx ; if < then ecx = eax cmovl %ebx,%eax ; if < then eax = ebx cmovl %ecx,%ebx ; if < then ebx = ecx movrm %eax,(%esi) ; *a = eax movrm %ebx,(%edi) ; *b = ebx 2) Version with 2 cmov. movmr (%esi),%eax ; eax = *a movmr (%edi),%ebx ; ebx = *b movrr %eax,%ecx ; copy ecx = eax sub %ebx,%ecx ; ecx -= ebx movrr %eax,%ecx ; copy ecx = eax movrr %ebx,%edx ; copy edx = ebx cmovl %edx,%eax ; if < then eax = edx cmovl %ecx,%ebx ; if < then ebx = ecx movrm %eax,(%esi) ; *a = eax movrm %ebx,(%edi) ; *b = ebx 4.47 ---- Stage | leave -----------+----------------------- Fetch | icode:ifun <- M1[PC] | valP <- PC+1 -----------+----------------------- Decode | valA <- R[%ebp] | valB <- R[%ebp] -----------+----------------------- Execute | valE <- valB+4 -----------+----------------------- Memory | valM <- M4[valA] -----------+----------------------- Write back | R[%esp] <- valE | R[%ebp] <- valM -----------+----------------------- PC update | PC <- valP 4.48 ---- Stage | iaddl V, rB -----------+----------------------- Fetch | icode:ifun <- M1[PC] | rA:rB <- M1[PC+1] | valC <- M4[PC+2] | valP <- PC+6 -----------+----------------------- Decode | valB <- R[rB] -----------+----------------------- Execute | valE <- valB+valC -----------+----------------------- Memory | -----------+----------------------- Write back | R[rB] <- valE -----------+----------------------- PC update | PC <- valP