CSAPP-3e-Solutions icon indicating copy to clipboard operation
CSAPP-3e-Solutions copied to clipboard

The answer of 3.63 seems wrong

Open nishuiq opened this issue 3 years ago • 2 comments

In site/content/chapter3/code/3.63.c

case 64:
    x = x << 4 - x;
case 65:
    x = x * x;

Need to be modified to

case 64:
    result = (x << 4) - x;
    x = result;
case 65:
    x = x * x;

Because

x in %rdi, n in %rsi
....
case 64:
    4005b2: 48 89 f8                mov %rdi,%rax       ; result = x
    4005b5: 48 c1 e0 04             shl $0x4,%rax       ; result = x << 4
    4005b9: 48 29 f8                sub %rdi,%rax       ; result = (x << 4) - x
    4005bc: 48 89 c7                mov %rax,%rdi       ; x = result
case 65:
    4005bf: 48 0f af ff             imul %rdi,%rdi      ; x = x * x
case 61/default:
    4005c3: 48 8d 47 4b             lea 0x4b(%rdi),%rax ; result = x + 0x4b
    4005c7: c3                      retq

nishuiq avatar Aug 08 '22 15:08 nishuiq

我已收到您的邮件

paradox181 avatar Aug 08 '22 15:08 paradox181

true

SydCS avatar Nov 27 '23 14:11 SydCS