0

So here I am facing a problem.I have only 25 instructions in my instruction set.(no multiply,divide,subtract, increment instruction). now, I am trying to preform a binary division.My problem is, how can I know if the divisor is smaller then the dividend in order to subtract them both (in 2's compliment form)?

INSTRUCTION SET: enter image description here

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
joey rohan
  • 3,505
  • 5
  • 33
  • 70
  • 1
    How would we be able to tell you if we don't know what instructions you *do* have? – us2012 Sep 29 '13 at 15:27
  • @us2012 ok will upload. – joey rohan Sep 29 '13 at 15:30
  • @us2012 updated, please have a look. – joey rohan Sep 29 '13 at 15:34
  • Looks like the architecture is [this](http://en.wikipedia.org/wiki/Mano_machine). Let me retag. – Seva Alekseyev Sep 29 '13 at 15:55
  • Yes, this is it.But how can I conclude when AC would be zero?As far as subtraction is concerned ? – joey rohan Sep 29 '13 at 15:58
  • 1
    There's a reference [here](http://192.220.10.64/duchon/cs311/ManoTutorial/ManoIntroduction.html). SPA/SNA are operand-less commands that skip the next instruction if the condition is true. You should not run the dividend down to zero; you should run it down to nonpositive. Since this is homework, I'm not spelling out the whole program. – Seva Alekseyev Sep 29 '13 at 16:05

2 Answers2

2

Many instructions can be decomposed into simpler instructions.

It seems like you need a compare instruction.

If you don't have a compare instruction, you can simulate it using a subtract and checking the status of the processor flags after the subtract.

You don't have a subtract instruction, so you can simulate it by adding the negative of the subtracted value.

If you don't have a negate instruction, you can simulate it in two's complement arithmetic by flipping the values of all the bits and adding 1.

Ferruccio
  • 98,941
  • 38
  • 226
  • 299
  • In 2's compliment, how will I know if the divisor is less?There wont be any extra 1 bit for the sign? – joey rohan Sep 29 '13 at 15:38
  • 1
    Subtract the divisor from the dividend, if the result is less than zero then the divisor is less than the dividend. It looks like you can use the SPA or SNA instructions for that. – Ferruccio Sep 29 '13 at 15:41
  • I am not sure about SPA and SNA that at what time the should have 0 ot 1 – joey rohan Sep 29 '13 at 15:53
2

I'm assuming AC is a register (accumulator). So what you need is a SPA command while AC has the result of the subtraction of the two numbers. Or a SNA, depends on what you're subtracting from what.

Again, you don't have subtraction. Replace it with addition of one number and a negative of another. Negative is complement plus two, like Ferruccio said.

EDIT: SPA/SNA works by skipping the next command if the AC is positive/negative. So if you want to have an if statement with a nontrivial body, you'd want to put an Sxx followed by a BUN (branch unconditionally). If the condition is true, the branch is skipped, if the condition is false - branch is executed.

Note that it's an inversion of the conventional logic of assembly. Normally, it's "branch if condition is true"; on this machine, it's "branch if the condition is false".

For the record, your instruction set is deliberately stunted. Real life CPUs are more programmer friendly than that, even the RISC kind.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281