From owner-freebsd-mips@FreeBSD.ORG Thu Oct 9 19:55:35 2008 Return-Path: Delivered-To: freebsd-mips@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7ED22106568B for ; Thu, 9 Oct 2008 19:55:35 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (bsdimp.com [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id 377788FC20 for ; Thu, 9 Oct 2008 19:55:35 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from localhost (localhost [127.0.0.1]) by harmony.bsdimp.com (8.14.2/8.14.1) with ESMTP id m99Jr7Om057421; Thu, 9 Oct 2008 13:53:07 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Thu, 09 Oct 2008 13:54:10 -0600 (MDT) Message-Id: <20081009.135410.1613257537.imp@bsdimp.com> To: zbeeble@gmail.com From: "M. Warner Losh" In-Reply-To: <5f67a8c40810091158y4a334f17g7ee25f67888e84e8@mail.gmail.com> References: <19900967.post@talk.nabble.com> <5f67a8c40810091158y4a334f17g7ee25f67888e84e8@mail.gmail.com> X-Mailer: Mew version 5.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: freebsd-mips@FreeBSD.org, rjdfhorn_06@yahoo.com Subject: Re: MIPS...detecting least significant bit. X-BeenThere: freebsd-mips@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to MIPS List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Oct 2008 19:55:35 -0000 In message: <5f67a8c40810091158y4a334f17g7ee25f67888e84e8@mail.gmail.com> "Zaphod Beeblebrox" writes: : On Thu, Oct 9, 2008 at 11:09 AM, Izzy K. wrote: : : > : > I'm working on an assignment and have reached a road block. If I have a 16 : > bit integer like: : > : > 0000 0000 0000 0100 : > : > how would I check to see what the value in the LEAST significant bit is? : > Basically, how would I check to see if the least significant bit is 0 or 1? : > How would I code it? I am a beginner at MIPS...is there a simple : > instruction : > that detects this? Please help me. : : : My first guess at the solution (and forgive me for not knowing the MIPS : instruction set --- so I'm just speaking in general machine language terms) : is to loop while left shifting and testing with an AND 0x01. You need to : count the loops to know when you encountered the first bit set. Now... : often the result of the left shift sets a status register based on the : previous value of the 0 bit (carry or underflow?) ... so your loop might be : an instruction shorter --- not requiring the AND --- if this is the case. : : Now... this all seems rather fundamental. Even the brute force case of : AND'ing with a bunch of values might pipeline well. Are you sure you should : be taking this course? Or you could just call ffs. FFS(3) FreeBSD Library Functions Manual FFS(3) NAME ffs, ffsl, fls, flsl -- find first or last bit set in a bit string Warner