LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2006, 08:07 PM   #1
hedpe
Member
 
Registered: Jan 2005
Location: Boston, MA
Distribution: Debian
Posts: 380

Rep: Reputation: 30
modulo in assembly?


Hey guys,

I am programming on the Intel IXP platform in microcode, and need to get the modulo of two numbers but can't quite figure this one out. They have given a divide() macro to simplify a division operation, but nothing for getting a remainder.

For instance... I have a general purpose register with 18 in it... and another register with 8 in it.

I would like to get a result of 2, with 8 bits in a byte, I want to access the second bit in the third byte... however for now I just want to get "2", then i'll worry about bitwise operations to access it.

I'm not looking for anyone to look up the opcodes for IXP, just looking for a logic answer like "you have to shift left by blah and then do blah"

I'd greatly appreciate it.

Thanks!
George
 
Old 11-19-2006, 08:44 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
If you already know the quotient Q=N/D then the remainder can be calculated R=N-D*Q
 
Old 11-19-2006, 10:05 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
For X86 assembly, of course, it's really, really easy:

Quote:
DIV: unsigned division
Quote:
IDIV: signed division
Code:
Dividend  Dividend size  Quotient  Remainder
--------  -------------  --------  ---------
AX        16 bits        AL        AH
DX:AX     32-bits        AX        DX
EDX:EAX   64-bits        EAX       EDX
The "modulus" (C/C++ "%" operator) would just be the remainder of integer division (in X86 assembler!).

As far as your microcode (without a real "divide" operation): Randyding's suggestion sounds reasonable.

Last edited by paulsm4; 11-19-2006 at 10:13 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
assembly and c tokernizer Programming 8 04-16-2006 11:40 AM
modulo of 2 floating point numbers? jenna_h Programming 6 09-24-2004 09:39 AM
Assembly jinksys Programming 3 09-14-2003 04:33 PM
I need help for Assembly skb Programming 10 08-01-2003 04:51 PM
assembly genghis Programming 2 06-12-2003 07:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration