Assembly programming question

Started by
20 comments, last by TheUnbeliever 16 years ago
This was my solution:
Quote:Original post by prtc22
STO A,1 // [1] = A
SUB A,1 // A = 0
SUB A,0 // A = -v (where v = original value at memory location 0)
STO A,1 // [1] = A = -v
SUB A,1 // A = -v - (-v) = 0
SUB A,1 // A = 0 - (-v) = v
STO A,1 // [1] = v

You don't need to use both registers for this question because you don't need to hold more than one subtraction result at a time to complete the task.
Advertisement
I came up with this:

Instruction |	State____________________________________________	    |	A: x	B: y	0: v	1: ?STO A, 1    |	A: x	B: y	0: v	1: xSUB A, 1    |	A: 0	B: y	0: v	1: xSTO B, 1    |	A: 0	B: y	0: v	1: ySUB B, 1    |	A: 0	B: 0	0: v	1: ySUB A, 0    |	A: -v	B: 0	0: v	1: ySTO A, 1    |	A: -v	B: 0	0: v	1: -vSUB B, 1    |	A: -v	B: v	0: v	1: -vSTO B, 1    |	A: -v	B: v	0: v	1: v


(effectively NerdInHisShoe's solution, from a quick look)
[TheUnbeliever]

This topic is closed to new replies.

Advertisement