From owner-freebsd-mips@FreeBSD.ORG Thu Oct 9 19:47:38 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 3B950106568A for ; Thu, 9 Oct 2008 19:47:38 +0000 (UTC) (envelope-from zbeeble@gmail.com) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.238]) by mx1.freebsd.org (Postfix) with ESMTP id E30DA8FC2D for ; Thu, 9 Oct 2008 19:47:37 +0000 (UTC) (envelope-from zbeeble@gmail.com) Received: by wr-out-0506.google.com with SMTP id c8so36651wra.27 for ; Thu, 09 Oct 2008 12:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type:references; bh=2UIFKUGODvIYd9YMryk3HmX7+ORUvUWxJAzeINsJj7M=; b=wzS86Pyl+FNKYMY6tZxjbioylumTmCReLBU4akDPIBNDw5O8oKsSDaimCAQtQTtIlY GSW9WEAXs+oB7WKeblzSy0kBHZwddz7v8cXt/gorp7ZER6DTtNn0RWDITm5W7D9DWERj CTGSY0jXnNjGTQN21WJCfAXfZIuiOgq5hCiwI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:references; b=KWNbDdTrCJgbePTGdZkdk05rC1rCi2Kqnp1IED61mW/ib+iSXTzqvVBu5RlpzstHjT fOWugWoJsfH04igNPPIWw7dAuIwG2qGDT49QgcrvjQkP07KwJRGDJ9F19nL11fajZ3Rj Dnhh/hfuEH81HkZDRSLVuJ97oV09b+3tEiQnU= Received: by 10.151.107.8 with SMTP id j8mr608150ybm.163.1223578719290; Thu, 09 Oct 2008 11:58:39 -0700 (PDT) Received: by 10.150.137.11 with HTTP; Thu, 9 Oct 2008 11:58:39 -0700 (PDT) Message-ID: <5f67a8c40810091158y4a334f17g7ee25f67888e84e8@mail.gmail.com> Date: Thu, 9 Oct 2008 14:58:39 -0400 From: "Zaphod Beeblebrox" To: "Izzy K." In-Reply-To: <19900967.post@talk.nabble.com> MIME-Version: 1.0 References: <19900967.post@talk.nabble.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-mips@freebsd.org 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:47:38 -0000 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?