7. Using only a SBN destination,source,target, (subtract source from destination and branch to target on negative) instruction, implement the following primitives
a. MOVE X,Y ; copy the contents of memory location Y to location X
b. ADD X,Y ; add the contents of memory location Y to location X
c. IF (X ? 0)Y ? 2Y ; if the contents of location X are greater than zero, then Y? 2Y.
SBN a,b,c is defined as: [a] = [a] ? [b]; if [a] ? 0, then branch to c.
a. To perform MOVE X,Y we can write
SBN T,T,*+1 ;set temporary value T to 0; do next instruction
SBN T,Y,*+1 ;subtract Y from T to get T ? Y = 0 ? Y = ?Y; do next instruction
SBN X,X,*+1 ;set value of X to 0; do next instruction
SBN X,T,*+1 ;set value of X to X ? T = 0 ? (?T) = Y ; do next instruction
Here we have cleared values, negated values and used a subtract from zero as a move.
b. To perform ADD X,Y we can write
SBN T,T,*+1 ;set temporary value T to 0; do next instruction
SBN T,X,*+1 ;subtract X from T to get ?X; do next instruction
SBN Y,T,*+1 ;subtract T from Y to get Y ? (?X) = Y + X; do next instruction
c. To perform IF (X ? 0) Y = 2Y we can write
SBN T,T,*+1 ;set temporary value to 0
SBN X,T,*+3 ;subtract X ? 0 to test for negative. If negative, skip next two instructions
SBN T,Y,*+1 ;subtract Y from T to get ?Y; do next instruction
SBN Y,T,*+1 ;subtract T from Y to get Y ? (?Y) = 2Y; do next instruction
You might also like to view...
In a condition str1 == str2, where str1 and str2 are String handles, the == operator compares the Strings to which the handles refer.
Answer the following statement true (T) or false (F)
What is the event when a value is selected?
a) ValueChanged b) DateTimeModified c) DateModified d) TimeModified
What is the difference between status meetings and decision meetings? Should they always be kept separate in a meeting?
What will be an ideal response?
If bulk candy costs $10.00 a kilogram, how much will 3 pounds cost? (There are 2.2 pounds in a kilogram.)
Let x equal what you are trying to find x = ($ / purchase) Note: The unit "purchase" is made up.