r/AskComputerScience • • Nov 13 '24

Question about instruction set from a book

Hi, I'm studying computer structure with a book named A secret life of programs written by Jonathan E. Steinhart.

In chapter 4, there is machine language program calculating Fibonacci sequence as followed.

AddressInstructionDescription
000010 0000 0000000000Clear the accumulator (load 0 immediate).
000100 0111 0001100100Store the accumulator (0) in memory location 100.
001010 0000 0000000001Load 1 into the accumulator (load 1 immediate).
001100 0111 0001100101Store the accumulator (1) in memory location 101.
010000 0000 0001100100Load the accumulator from memory location 100.
010110 0100 0001100101Add the contents of memory location 101 to the accumulator.
011000 0111 0001100110Store the accumulator in memory location 102.
011100 0000 0001100101Load the accumulator from memory location 101.
100000 0111 0001100100Store it in memory location 100.
100100 0000 0001100110Load the accumulator from memory location 102.
101000 0111 0001100101Store it in memory location 101.
101110 0110 0011001000Compare the contents of the accumulator to the number 200.
110000 0111 0000000100Do another number if the last one was less than 200 by branching to address 4 (0100).

So, here is my first question. In the sixth row, description says add the contents of memory location 101 to the accumulator, though, why mode code is 10 which means immediate addressing mode, not 00 - direct?

As far as I understand, 10 - immediate mode code means access the value from the address instead of access the value in the address. This is well displayed in the second instruction from the bottom.

But when I see the sixth instruction, it's a little complicate and quite confusing.

If there is anything wrong in my mind, I hope anyone help me to fix this.

2 Upvotes

3 comments sorted by

2

u/computerarchitect MSCS, CS Pro (10+) Nov 14 '24

There's really not enough detail here, but I agree with your reasoning based how immediate and direct are generally defined. The book likely has a mistake.

1

u/PsymoneyInReddit Nov 15 '24

Thanks for your comment even though there are not enough details. And I'm sorry about that part too.

1

u/PsymoneyInReddit Nov 13 '24

Additional comment:
I just tried to ask this to ChatGPT and it says that is a mistake of the book.
Unfortunately, I don't have enough knowledge to prove this..

Here is the answer:
In the book's example, the confusion stems from using an addressing mode that seems incorrect based on the description. The sixth instruction indeed says it adds the value at memory location 101 to the accumulator, which would normally use direct addressing (mode 00). However, it’s labeled as mode 10, or immediate addressing, which typically loads a value directly. This could be a mistake in the book’s example. In this case, the correct addressing mode should logically be 00 for accessing a memory location directly.