Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiplication algorithm in SPARC
    primarykey
    data
    text
    <p>been working for a few (straight) days on this multiplication algorithm in SPARC... Really can't figure out what's wrong. I've stepped through a few iterations of the code. It's doing what the proposed C algorithm wants it to. Here it is in C</p> <pre><code>negative = multiplier &gt;= 0 ? 0 : 1; product = 0; for (i = 0; i &lt; 32; i++) { if (multiplier &amp; 1) product += multiplicand; (product and multiplier registers combined as a unit) &gt;&gt; 1; } if (negative) product -= multiplicand; </code></pre> <p>And here it is in SPARC Assembly, note I haven't implemented functionality for negative numbers yet. The program runs the proposed number of times. So the loop is not the issue. I think my problem may be how I am accounting for the right shift across two 32 bit registers, which currently is just (in Psuedo-code)</p> <p>sra small register 1 if (rightmost bit of large register = 1) change leftmost bit of small register to a 1 sra larger register</p> <p>But it doesn't seem to be working out as planned, as I am getting really wonky numbers</p> <p>Here's the whole program in SPARC... any help you guys could offer would be appreciated. </p> <pre><code> fmt: .asciz "Multiplicand: %d, Product: %8.8X%8.8X Counter: %d\n" !output statement .align 4 !align formatting .global main main: save %sp, -96, %sp set 82732983, %l0 !move multiplicand into register %l0 set 120490892, %l1 !move multiplier into register %l1 set 0, %l2 !initialize product variable at 0 set 1, %l3 !initialize counter variable to 1 ba test mov 32, %l5 !put max loop value in a register loop: set fmt, %o0 !setup the format string for the print statement mov %l0, %o1 !moving variables for printing mov %l1, %o2 mov %l2, %o3 mov %l3, %o4 call printf nop postprint: and %l1, 1, %l6 !bitwise and between multiplier and 1, store result in %l6 cmp %l6, 0 !comparison statement comparing the above to 1 be else !skip the addition if rightmost bit of multiplier is 0 nop add %l0, %l2, %l2 !adding multiplicand and product sra %l1, 1, %l1 !shifting multiplier right and 1, %l2, %l6 !checking if rightmost bit of product is a 1 cmp %l6, 1 !conditional statement to check this bl endif !if it's not a one, branch to zero nop !non op clr %o4 set 0x40000000, %o4 !put 0x40000000 in a register or %l1, %o4, %l1 !if it is a one, bitwise do or with 0x40000000 to make a one in the leftmost bit of the multiplier sra %l2, 1, %l2 !shift product to the right by 1 inc %l3 !increment counter variable ba test !and branch to the testing statement nop endif: clr %o5 sra %l2, 1, %l2 !arithmetic shift product right by one (first line of endif) inc %l3 !increment counter variable ba test nop else: sra %l1, 1, %l1 !shift multiplier to the right and %l2, 1, %l6 !check if rightmost bit of product is 1 cmp %l6, 1 !conditional statement to check this bl endif !branch to endif if it's not nop !nop clr %o4 set 0x40000000, %o4 !put 0x40000000 in a register or %l1, %o4, %l1 !if the rightmost bit is one, we use a bitwise or to place a 1 in the leftmost bit of the multiplier sra %l2, 1, %l2 !then right arithmetic shift the product inc %l3 !and increment the counter ba test nop test: cmp %l3, %l5 bl loop done: mov 1, %g1 !Exit the program ta 0 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload