A computer has three registers, A, B and R. It has only three instructions:


A->R : Load R with A

B->R : Load R with B

A-R->A : Subtract R from A and store the result in A

Using these instructions how can you do the follwoing?

B->A : Load A with B


solution:-

A->R       // R ==  A
A-R->A   // A ==  0
B->R       // R ==  B
A-R->A   // A == -B
A->R       // R == -B
A-R->A   // A ==  0
A-R->A   // A ==  B

0 comments: