Post Reply 
Social Buttons
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tutorial] MASM Adding Numbers (DUP, ADD, DWTOA)
Author Message
Hidden Dragon Offline
Amazing
*******

Trade Count: (0)
Posts: 63
Joined: Jan 2011
Reputation: 4
Post: #1
[Tutorial] MASM Adding Numbers (DUP, ADD, DWTOA)
Well this tutorial over adding numbers is going to cover a couple of new topics. These are DUP, ADD, and DWTOA. Let's start with a standard program.

Code:
include \masm32\include\masm32rt.inc

.data

AnswerTxt   db   'The answer is '
AnswerNum   db   11 dup(0)

Now in our data section we have our answer. AnswerNum is a part of AnswerTxt and we will use AnswerTxt to display our answer when we add. Now the DUP command stands for duplicate. We are duplicating 11 bytes. In the parentheses(), we hold the value we are going to put into those bytes. We do this duplication of 11 bytes filling them with zeros because they are going to be used later on in our program.

Code:
.code
start:   mov  eax,14
         add  eax,27
         push offset AnswerNum
         push eax
         call dwtoa

Alright so once we start our program we are moving the value 14 into our eax general purpose register. After that we are adding the value in eax and 27. This answer is stored in eax as it is the first register listed before the comma (,).

We then push AnswerNum's location onto the stack to be read. After that we push our eax register that now contains 41. Then we call dwtoa.

dwtoa converts DoubleWord TO Ascii. With this we can take a numeric value and convert it to an ascii string, then store it somewhere. We take the value at eax (41) and convert it to a string to be stored at AnswerNum.

Code:
push 0
     push offset AnswerTxt
     push offset AnswerTxt
     push 0
     call MessageBoxA
     call ExitProcess
end start

Next we push onto the stack everything that we need for a messagebox. In order, we push 0 for our messagebox style. 0 will give us a messagebox with just an ok button. Then we push our AnswerTxt twice. Once for the title, then again for the text of the messagebox. Finally, we push the handle window. Since we don't have a handle window we just put 0. After we have all the 'ingredients' for the messagebox, we call the messagebox command. Then we call ExitProcess to end execution of our program.

That's it for this tutorial. Hopefully you'll be able to add numbers now. I hope you've learned something.
(This post was last modified: 01-16-2011 03:26 AM by Hidden Dragon.)
01-16-2011 03:18 AM
Find all posts by this user Quote this message in a reply
Scorch Offline
Intermediate C++
********

Trade Count: (0)
Posts: 83
Joined: Jan 2011
Reputation: 15
Post: #2
RE: [Tutorial] MASM Adding Numbers (DUP, ADD, DWTOA)
I fail at assembly and I understood that, so good job. I would rep if I could find the button.
01-16-2011 03:22 AM
Find all posts by this user Quote this message in a reply
Hidden Dragon Offline
Amazing
*******

Trade Count: (0)
Posts: 63
Joined: Jan 2011
Reputation: 4
Post: #3
RE: [Tutorial] MASM Adding Numbers (DUP, ADD, DWTOA)
You have to click on the user and scroll down a little.

Glad you understood it, that's the whole goal of having a tutorial Smile
(This post was last modified: 01-16-2011 03:25 AM by Hidden Dragon.)
01-16-2011 03:25 AM
Find all posts by this user Quote this message in a reply
Hidden Dragon Offline
Amazing
*******

Trade Count: (0)
Posts: 63
Joined: Jan 2011
Reputation: 4
Post: #4
RE: [Tutorial] MASM Adding Numbers (DUP, ADD, DWTOA)
Woah. I looked in mod CP and it says your default user title is Moderator but your primary group is registered. You're both at the same time apparently. Open a topic in bug reports.
01-16-2011 03:36 AM
Find all posts by this user Quote this message in a reply
Scorch Offline
Intermediate C++
********

Trade Count: (0)
Posts: 83
Joined: Jan 2011
Reputation: 15
Post: #5
RE: [Tutorial] MASM Adding Numbers (DUP, ADD, DWTOA)
I PMed Ironside an hour ago. I'll wait for his response.
(This post was last modified: 01-16-2011 03:38 AM by Scorch.)
01-16-2011 03:37 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: