There is a computer with a single instruction:

**sbn a b c**

where a,b,c are addresses. Constants are also not allowed in this instruction – only addresses. This instruction subtracts b from a and stores the result in a. If the result is less than zero, then it branches to address c, else it continues with the next instruction.

Also, if no c is given in the instruction, then it defaults to the next instruction. Assume that there is a location in the memory called **one** that has the number **1** stored in it.

*Initialize a variable to zero*

sbn temp temp

*Add two numbers*

sbn temp temp

sbn temp b

sbn a temp

*Left shift a number a(is equivalent to multiplying the number by 2)*

sbn temp temp

sbn temp a

sbn a temp

*Implement an unconditional jump*

sbn temp temp

sbn temp one <label>

*Implement an assignment operation i.e. assign b to a
*

sbn a a

sbn temp temp

sbn temp b

sbn a temp

*Multiply a with b and store the result in c:*

sbn temp temp

sbn c c

sbn temp b

sbn a one out

label:sbnc temp

sbn temp2 temp2

sbn temp2 one label

out: <Done>

*Mark a number Negative:*

sbn temp1 temp1

sbn temp2 temp2

sbn temp1 num

sbn temp2 temp1

sbn num num

sbn num temp2

*Multiply when both a and b can be negative numbers:*

This can be done by first multiplying the two numbers with the above procedure and then applying the sign later by checking the sign of both the numbers.

sbn pos-a pos-a

sbn pos-b pos-b

sbn is-A-Zero is-A-Zero

sbn is-B-Zero is-B-Zero

sbn pos-a a assign-A-Done

sbn temp temp

sbn temp one

sbn is-A-Zero temp

sbn temp temp

sbn a a

sbn temp pos-a

sbn a temp

assign-A-Done: sbn pos-b b assign-B-Done

sbn temp temp

sbn temp one

sbn is-B-Zero temp

sbn temp temp

sbn b b

sbn temp pos-b

sbn b temp

assign-B-Done:

<Follow the same as multiply procedure>

sbn temp temp

sbn is-A-Zero one a-Positive

<Follow the make a number negative procedure to reverse the sign of c>

a-Positive: sbn is-B-Zero one b-Positive

<Follow the make a number negative procedure to reverse the sign of c>

b-Positive: <Done>

* Implement sign checking: load an address b with true if it is negative, false otherwise*

sbn temp temp

sbn b b

sbn temp a <a-is-not-less-than-zero>

sbn temp temp

sbn temp one

sbn b temp

a-is-not-less-than-zero: <Done>

* Implement compare-to-zero:*

sbn temp temp

sbn temp a <a-is-positive>

sbn b b

sbn temp temp

sbn temp one <EOP>

a-is-positive: sbn temp temp

sbn temp a <a-is-non-zero>

sbn b b

sbn temp temp

sbn temp one

sbn b temp

sbn temp temp

sbn temp one <EOP>

a-is-nonzero: sbn b b

EOP: <Done>

Still to do: *left rotate, right rotate, signed arithmetic*