Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A made-up processor has one register, the accumulator. LDA loads a value from memory into the accumulator, ADD and SUB add or take away a value from memory, and STO stores the accumulator in memory.
Address 8 holds , address 9 holds and address 10 holds . The program is:
LDA 8
ADD 9
SUB 10
STO 11Give the value in the accumulator after each of the first three instructions, and the value stored at address 11 at the end.
Machine code is binary and is the language of the processor. Assembly language is low level: it uses mnemonics such as ADD, and an assembler translates it into machine code. A high-level language is easier to read, write and debug and is machine independent. A low-level language can manipulate the hardware directly.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Step 1. LDA 8. The accumulator takes the value at address 8: .
Step 2. ADD 9. .
Step 3. SUB 10. .
Step 4. STO 11. The value is stored at address 11.
Answer: , , , and address 11 holds .
What if? In a high-level language this whole program is one statement, such as Result ← A + B - C. That is one reason high-level code is easier to read.
Log in to join the discussion.
Loading…