Remove Ads

Share on Facebook Share on Twitter

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tutorial] MASM Adding Numbers (DUP, ADD, DWTOA)
#1
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)[/code]

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[/code]

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[/code]

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.
Reply
#2
I fail at assembly and I understood that, so good job. I would rep if I could find the button.
Reply
#3
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
Reply
#4
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.
Reply
#5
I PMed Ironside an hour ago. I'll wait for his response.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)