Sunday, February 22, 2015

DBNZ -> CLEAR & NEGATE


You given and instruction called DBNZ ( Decrement and Branch if Not Zero)
which can be used as "DBNZ X L10".
This instruction decrement X by one and checks X, if X is not zero than branches line 10,
if it is zero than continue to next instructions.
By using DBNZ instruction implement CLEAR instruction.
CLEAR can be used as "CLEAR X" which means set X to zero.

By using DBNZ and CLEAR instructions implement NEGATE instruction
NEGATE can be used as "NEGATE X Y" which means set Y to negative of X ( Y = -X)
Well, to understand this question, I have to start with what does "branch" mean.

A branch is an instruction in a computer program that may, when executed by a computer, cause the computer to begin execution of a different instruction sequence. A branch instruction can be either an unconditional branch, which always results in branching, or a conditional branch, which may or may not cause branching depending on some condition. 
For example, GOTO.

Now the actual problem. The CLEAR instruction will set the given parameter to 0. Assuming X is positive at first, then

L1 : DBNZ L1

will decrement L1 until it is zero, and then continues to the next instruction.

Let Y be any number, then

CLEAR Y -> set Y to zero
L1: DBNZ Y L2 -> decrement Y, it will not be zero, then branches to L2
L2: DBNZ X L1 -> decrement X, if it is not zero, then branches to L1

This instruction will decrement X times of Y from zero, thus will give us -X.

These instructions are initially instructions from One instruction set computer (OISC), which is an abstract machine that uses only one instruction. With a judicious choice for the single instruction and given infinite resources, an OISC is capable of being a universal computer in the same manner as traditional computers that have multiple instructions.








No comments:

Post a Comment