wu :: forums (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)
riddles >> cs >> How to divide with SIC sbn instruction
(Message started by: MOR on Mar 25th, 2013, 2:26am)

Title: How to divide with SIC sbn instruction
Post by MOR on Mar 25th, 2013, 2:26am
Hello there,

I want to implement the C code

Code:
c = a div b;

on SIC with sbn instruction.
Any help with this?

The command does the following:

sbn a,b,c # Mem[a] = Mem[a] – Mem[b];if (Mem[a]<0) go to c

I am looking forward to hearing from you and i would appreciate any kind of help. thank you.

Title: Re: How to divide with SIC sbn instruction
Post by akasina9 on Apr 2nd, 2013, 9:29pm
You can look at division as a subtraction loop. The following code block assumes that the initial instruction starts at address n:


Code:
sbn u, u        # Initialize u to 0
sbn c, c        # Initialize c to 0
sbn u, ONE        # Initialize u to -1
sbn a, b, n+6        # Subtract b from a until it is less than  zero
sbn c, u        # increment c by one each time a is positive
sbn ZERO, ONE, n+3        # Unconditional jump to the subtraction step
exit



Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board