In: Computer Science
explain why a computer needs to use memory (registers, stacks, heaps) when executing assembly language instructions using the computer's architecture?
explain why a computer needs to use memory (registers, stacks, heaps) when executing assembly language instructions using the computer's architecture?
Ans:
Since instructions are simply bit patterns, they can be stored in memory. The instruction pointer register always has the memory address of (points to) the next instruction to be executed. In order for the control unit to execute this instruction, it is copied into the instruction register.
The situation is as follows:
A sequence of instructions is stored in memory.
The memory address where the first instruction is located is copied to the program counter.
The CPU sends the address in the program counter to memory via the address bus.
Memory responds by sending a copy of the state of the bits at that memory location on the data bus, which the CPU then copies into its instruction register.
The instruction pointer is automatically incremented to contain the address of the next instruction in memory.
The CPU executes the instruction in the instruction register.
Go to step 3.
While executing assembly language instruction, computer needs to use memory in order to complie, execute and save the code in the memory storage. In memory, we have stack, heap, and main memory. Stack is used to store the variables, arrays etc all the things which was initialized in the program, heap is used for dynamic storage, and main memory is responsible to store the entire code. RAM is also used to compile and run the code.
Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! ===========================================================================