News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Division and modulo

Started by vasiqshair, January 11, 2012, 03:03:55 PM

Previous topic - Next topic

vasiqshair

The goal here is to write a algorithm that finds the square root of a non-negative integer. my assembler does not support modulo (the square root method that i am using requires a modulo consistently), so I came up with one on my own. How would you make this more efficient/faster/smaller? I am using the Mars assembler

li   $t1,645
li   $t2,10
li   $t3,1

functionOne:
mul   $t4,$t2,$t3
sub   $t5,$t1,$t4
blt   $t5,$t2,functionTwo
addi   $t3,$t3,1
b   functionOne

functionTwo:
li   $v0,1
move   $a0,$t5
syscall

dedndave

this is a MASM forum - meaning intel x86 code under windows, primarily
only a few members will understand that code   :P
there are a few, though - if you're lucky, one of them will pop in

welcome to the forum   :U

clive

Wouldn't DIVU give you both the quotient and remainder (modulo)?

But seriously, there are far better integer methods
http://eetimes.com/discussion/other/4219659/Integer-Square-Roots
It could be a random act of randomness. Those happen a lot as well.

bozo

If you know C or C++ already, I'd recommend generating output using GCC -S flag to see how it generates square root...lazy true, but it'll give you good idea.

I was able to run a MIPS port of Debian in QEMU if you wanted some way to develop code.