Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   Remainder (http://www.programmingforums.org/showthread.php?t=1322)

Mjordan2nd Nov 28th, 2004 5:40 PM

Sorry for all these questions in a row, but I want to get some practice on assembly. I was thinking about writing a program that would calculate prime numbers up to a certain number, but couldn't think of any way to find the remiander of a number. Anyone want to point me in a direction I could learn?

Eggbert Nov 28th, 2004 6:00 PM

Your assembler doesn't have a MOD operator or something similar? It's a fairly common arithmetic operation.

Mjordan2nd Nov 28th, 2004 6:56 PM

Doesn't seem to recognize the mod instruction. I'm using NASM if that helps.

lostcauz Nov 29th, 2004 1:59 AM

I've had a few cocktails but I'll do my best. Using a div instruction, load (e)ax with the number being tested then load cx with the divisor. Then use the instruction - div cx. The quotient will be in ax while the remainder, if any, will be left in dx.
:

mov cx, 3
mov ax, 31
div cx

You could try this code in debug and watch the registers to see whats going on.
At command line type 'debug'
type 'a'
enter the code above
when done click enter twice then type 'r'
type 't' to execute the next instruction and see the registers change.
In the end ax should be 10 while dx contains the remainder of 1.
Forgive if this makes no sense. :mrgreen:


All times are GMT -5. The time now is 6:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC