Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The answer of 3.63 seems wrong #83

Open
nishuiq opened this issue Aug 8, 2022 · 2 comments
Open

The answer of 3.63 seems wrong #83

nishuiq opened this issue Aug 8, 2022 · 2 comments

Comments

@nishuiq
Copy link

nishuiq commented Aug 8, 2022

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
@paradox181
Copy link

paradox181 commented Aug 8, 2022 via email

@SydCS
Copy link

SydCS commented Nov 27, 2023

true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants