News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Greatest common divisor of two intergers

Started by spaarkz, November 08, 2007, 03:46:49 PM

Previous topic - Next topic

spaarkz

I need to write a program that accepts a word via the screen then codes the word by shifting the first letter down one, the second letter down 2 and so on, I then need to write a program that reverses this process.  Both programs need to display the result on the screen.  Can anyone give me a few pointers?

Thanks

TNick

How do YOU think that this may be done? Any ideas? What walls did you knocked with your head???

Nick

spaarkz

If I knew I would not be asking you would I??? Whats this got to do with heads and walls????
If you have nothing constructive to say then please refrain from doing so.

spaarkz

#3


Thanks

Mark Jones

Hi, have you tried "viewing" your code in a debugger yet? Try debugging with OllyDbg (http://www.ollydbg.de/) then try steps listed here:

http://www.masm32.com/board/index.php?topic=7861.msg57718#msg57718

This will show you what all the registers do as each instruction is executed.  :U


And just curious... what does any of this have to do with the GCF of two integers?
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

MichaelW

I also cannot see how this relates to GCD, or how the posted code, which will not assemble BTW, is doing anything that even resembles the description. The code is copying bytes from the address specified by edx+esi to the address specified by ebx+esi, continuing until the addressed byte is a carriage return character (0dh). What it does beyond that is dependent on the intended syntax for:

.if al.1fh ;if al = 1fh go to next line what is 1fh

If the intended syntax was:

.if al ==1fh

Then this statement will return true only if the first byte at the source address is a space (20h), the second 21h, the third 22h, etc, and the value 1fh will be copied to the destination address. Otherwise, the value (7eh - alter) will be copied to the destination address. This behavior does not match the description, and for most of the characters the process cannot be reversed.

I think you need to start over at square one, and break the assignment up into small, manageable pieces. First figure out how to accept a word input, then write and test the necessary code, and once you have it working proceed to the next piece. How to accept a word input would depend on what sort of library and/or pre-coded procedures you are allowed to use (MASM32, Irvine, Detmer, etc). Make a significant effort to write your own code, then if you have problems post the code and ask specific questions. You can maximize the possibility of getting useful help by making it easy for the people providing the help, and that means focusing on small, manageable pieces. Avoid posting a big chunk of messy code that does multiple things and likely contains multiple errors.
eschew obfuscation

TNick

As far as I understand the idea of this forum, it is intended to help newbies to assembly language and to ease communication between more advanced guys concerning more advanced problems related to this.
However, this is not a place where people are doing your work.

"What walls did you knocked with your head??" mean what problems did you tried to resolve and were unable to manage it?! What tutorial did you read and don't understand. What mnemonic you did not understand? Why did I ask this? Let's analyse your question:
- I need to write a program that accepts a word via the screen
If you read Iczelion's tutorials you must be able to read a number the user enters in a EDIT box.
If you read Win32 help file you will see that there is a easy way to get directly the number from there (GetDlgItemInt)
If you read MasmLib help file you will see that you have there a function to convert a decimal string to dword (atodw)

-...then codes the word by shifting...
Shift. A superficial reading of Intel Manuals or of op-codes.hlp file that ships with Masm32 package will reveal you some interesting instructions: shl and shr. You will also find that you are not looking for a shift, but for a rotation (rol and ror)

-... the first letter down one, the second letter down 2 and so on...
any tutorial that you read will start with numerical representation, number in hex format and so on. So, you will find out that all you have to do is:
mov esi, pBytesToCode
or ecx, -1
xor eax, eax
LoopHere:
add ecx, 1
mov al, byte ptr [esi+ecx]
rol al, cl
test eax, eax
mov byte ptr [edi+ecx],al
jnz LoopHere

Just so you know, I didn't help you with this post. Why? Because you would learn much better if you would "knocked walls with your head", if you would use your brain to figure out a solution before posting. And all reading mentionate here is basic reading


QuoteIf you have nothing constructive to say then please refrain from doing so.

If I feel that I have something to say I will say it, whether you like it or not, whether is constructive (in your opinion) or not. The only persons entitled here to tell me if one of my post is "out of bounds" or not are the administrators/moderators. You may alert them about any post/reply using "Report to moderator" link at the bottom of each message.

Nick