Join 136,812 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,194 people online right now. Registration is fast and FREE... Join Now!
This code prints out 1-20, but it's suppose to print out the prime numbers.
The teacher also says: "Prior to calling IsPrime, put the value you want to test in the BX register. After the procedure returns the value of the DX register will tell you if the number is prime or not."
It seems so simple but I can't understand what I'm suppose to do. I've looked in the text for as much info as I could find but it doesn't help.
Can anyone help me?
This post has been edited by KelliB: 11 Aug, 2008 - 01:50 PM
The teacher gave us this code to start out with: This code prints out 1-20, but it's suppose to print out the prime numbers.
The teacher also says: "Prior to calling IsPrime, put the value you want to test in the BX register. After the procedure returns the value of the DX register will tell you if the number is prime or not."
It seems so simple but I can't understand what I'm suppose to do. I've looked in the text for as much info as I could find but it doesn't help.
Can anyone help me?
The code is just looping through the numbers from 1 to max which in this case is 20. The loop never calls the procedure isPrime. What you need to do is modify the section between :LoopStart and jle (JumpLessThanOrEqualTo) to call IsPrime. You'll need to do this before the call print_num. The value needs to be PUSHed into the BX register, it already is. Then call IsPrime. Then you'll need to CMP(compare) the DX register with 1. If DX is equal to 1 the number is prime so print it out otherwise continue the loop...
JW
This post has been edited by jwwicks: 11 Aug, 2008 - 05:55 PM
Ugh.. That's so simple.. I can't believe I didn't realize it didn't call the procedure... Thanks
Well I've called IsPrime... but I still can't get it to print out the right numbers.. ; I really suck at this.. but at least assembly isn't all that important for me to know..
This post has been edited by KelliB: 12 Aug, 2008 - 08:08 AM
That's what my code looks like now but it's not printing out prime numbers. It counts 1 2 3 and then seems to get stuck in a loop. I don't know what to do...
To be honest I cant be bothered to check your code.
But I like to debug it for you anyhow and tell you were the error is. So, well I'd like it if you can Assemble that with whatever assembler you use so I can convert it back to Assembler using my Copy of IDA Free
Well I guess technically it is an error.. but what I meant is the complier doesn't tell me there's an error when it puts it all together.. I don't know.. I'm new to programming...
Well I guess technically it is an error.. but what I meant is the complier doesn't tell me there's an error when it puts it all together.. I don't know.. I'm new to programming...
Compile it. And give the Compiled file to me. Ill check were the Neverending loop happens for you then
Sorry, KelliB, it's late and I am not in mood to check your code, but i can give you advice. Try downloading TASM 5.0 (or MASM better). to make .OBJ file, use tasm.exe, and to link the prog, use tlink.exe. This way you will be able to make it work on your computer. And actually, since it is 16 bit assembly, it will run on virtual machine anyway because Windows is 32 bit.