0

I am doing an exercise from this question:

enter image description here

The solution is attached on the right hand side. I am just wondering is there a mistake in the solution in particular the part that I underlined?

Should line 7 be the following instead of the given underlined answer? 5(%rbx, %rcx), %rbx Compute x += y + 5

based on the original C code on the left where in the while loop it has this:

x += y; (*p ) += 5;

I thought there maybe a mistake in the solution? (the solution is the one that I underlined with red)

could someone comment? thank you

john_w
  • 693
  • 1
  • 6
  • 25
  • You're absolutely right. The solution matches the code in the comments. Looks like you got another case of a professor updating a book revision to extort money from the students and forgetting to update the solutions. – littleadv Jan 08 '22 at 07:02
  • 1
    @littleadv: What's happening here is that the publisher of CS:APP 3e global edition hired some incompetent people to make up a different set of practice problems. Notice the `idiv $9, %rcx` (which doesn't exist in x86-64), and use of qword operand-size for `short` types! [CS:APP example uses idivq with two operands?](https://stackoverflow.com/q/57998998) . The commented logic not even matching the source code is yet another problem. Basically a duplicate; the practice problems in that edition were made by people who don't know x86-64, apparently also carelessly / incompetently. – Peter Cordes Jan 08 '22 at 10:11
  • The claimed GCC output is hand-written, not actually from any GCC version (of course). Don't trust it any farther than you can throw it. The rest of the textbook is fine (and AFAIK quite good); only the practice problems were changed without consulting the authors. – Peter Cordes Jan 08 '22 at 10:13

0 Answers0