Public feed
#890987
register map
{
t0 M
t1 Q (Q in high) (QQQQ QQQQ QQQQ QQQQ (b0)000 0000 0000 0000 b)
t2 A (A in high) (AAAA AAAA AAAA AAAA 0000 0000 0000 0000 b)
t3 B1
t4 B0
t5 C (counter)
t6 TEMP
t7 1
t8 0
}
start
{
//t7 = constant 1
or t7,t7, 1
and t7,t7, 1
//t8 = constant 0
and t8,t8, 0
//INPUT: t5 C counter (16)
lh t5, C
//INPUT: t0 M multiplicand
lh t0, M
//INPUT: t1 Q (multiplier) (in high)
lh t1, Q
sll t1,t1, 16
//INPUT: t2 A (zero) (in high)
lh t2, A
sll t2,t2, 16
j booth_mult[test]
}
booth_mult
{
test
{
//checks b1 b0
//b1 is t1 bit 16 (Q bit 0)
//b0 is t1 bit 15
// case 00,11 -> shift
// case 10 -> substract && shift
// case 01 -> add && shift
and t3,t1 1 0000 0000 0000 0000 b
srl t3,t3, 16 //t3 = b1
and t4,t1, 1000 0000 0000 0000 b
srl t4,t4, 15 //t4 = b0
beq t3,t4, shiftstep //jumps if (00 or 11)
beq t3,t7, step1minus //jumps if 10
j step1plus //jumps if 01
}
step1minus
{
//A = t2 high
//M = t0
//new A = A - M
srl t6,t2, 16 //temp = A
sub t6,t6,t0 //temp = temp - M
sll t2,t6, 16 //A = temp
j shiftstep
}
step1plus
{
//A = t2 high
//M = t0
//new A = A + M
srl t6,t2, 16 //temp = A
add t6,t6,t0 //temp = temp + M
sll t2,t6, 16 //A = temp
j shiftstep
}
shiftstep
{
//treat A,Q,b0 as 1 reg and arithmeticshift it
sra t2,t2, 1 //arithm. shift A
//since A is in high , bit 15 is carrity
and t6,t2, 1000 0000 0000 0000 b //bit 15 of temp = carrity
srl t6,t6, 15 //bit 0 of temp = carrity
and t2,t2, 1111 1111 1111 1111 0000 0000 0000 0000 b //tidy A(t2) reset carrity
srl t1,t1, 1 //shift Q
//bit 15 of Q(t1) = carrity
//= new value of b0
sll t6,t6, 31 //temp LSB shifts into temp MSB = carrity
or t1,t1,t6 //propagate carrity A -> Q
sub t5,t5,t7 //counter(t5) = counter - 1
bne t5,t8, test //counter > 0 -> test
j finished //... else -> finished
}
finished
{
//halt / nop
}
}