Professional Documents
Culture Documents
1
Exercise - 1
Consider the following high level language instruction:
c=a+b
▪ This is an assignment statement in a high level language
▪ a, b, and c are variables ( named memory cells )
▪ This requires contents of a and b to be added
▪ Then the result to be assigned ( stored ) memory location c.
▪ Let’s write the machine instructions for 4 different types of CPUs
based in ISA architecture
2
Exercise – 1 (for Accumulator based CPU)
Important to Note
Load a Load a into accumulator
▪ CPU has only a single
Add b Add b into accumulator
general purpose register
Store c Store accumulator in c called the accumulator
3
Exercise – 1 (for Stack based CPU)
Important to Note
Load a a is pushed into stack
▪ General Purpose registers
Load b b is also pushed into stack
are implemented as a stack
Pop top 2 cells, add, push ▪ Load is Push operation,
Add result back to stack
Store is Pop operation.
Store c Pop stack and store in c ▪ Arithmetic operations are
zero operand instructions.
(As all operands implied to
be on the stack)
4
Exercise – 1 (for Register-Memory based CPU)
Important to Note
Load r1, a Load a into register r1
5
Exercise – 1 (for Register-Register based CPU)
Important to Note
Load r1, a Load a into register r1
▪ CPU has Larger General
Load r2, b Load b into register r2
purpose register set
Add r1 and r2 and
Add r3, r1, r2 store on register r3
▪ Arithmetic instructions can
refer to register operands
Store r3, c Store r3 on location c only
6
Exercise - 2
Consider the following high level language code:
sum = 0
For i = 1 to 10
sum = sum + A[i]
7
Exercise – 3 (for Register-Register based CPU)
MOV R1, #0 ; accumulate the sum in R1, initially 0
8
Exercise - 3
Consider the following scenario:
9
Exercise – 3 (for Register-Memory based CPU)
MOV R1, #0 ; accumulate the inner product in R1, initially 0
MOV R3, #4096 ; R3 is set to the highest offset value for arrays
10
Lesson Summary
11