Could someone please tell me if you can Subtract a number using standard Reg. EAX and so on with ASM code.

Example:

Buffer1 has the number 1000 in it
Buffer2 is empty

I just need to Subtract 200 from 1000 so i can put the balance of 800 in buffer2

mov eax, Buffer1
mov edx, Buffer2
I have no idea!!!

This is new to me and i have not seen Subtraction other that subing byte. If it is possible can someone show an example or direct me to a Post that done it already.

Will very much apreaciate it...
Posted on 2002-04-22 14:24:26 by cmax
:)
mov eax,Buffer1
sub eax,200
mov Buffer2,eax

I assume that data in Buffers is DWORD size.
If it is word - replace eax with ax
if it is bytes replace eax with al
Posted on 2002-04-22 14:39:54 by The Svin
Are these ascii numbers?
Posted on 2002-04-22 14:41:35 by bdjames
No, After you have subbed you must convert dword value to ascii with something like:
invoke dwtoa, buffer2, addr buffer2
This is in masm32.inc adn masm32.lib.....Then buffer2 will have an ascii value. To sub ascii values they must first be converted to DWORD or something with:
invoke atodw,ADDR buffer2
Do you see? I had trouble to when I first started playing with asm. Everything is very manual.
Posted on 2002-04-22 14:49:51 by emonk
Everything is very manual.


That is the spirit of ASM!!! ;)
Posted on 2002-04-22 16:02:53 by CodeLover
The Svin

Believe me. I wanted to mension you or bitRake Name but i know that you guys expect by Law for us to study HARD & seriouly first. So i backed down. I uses to read your opt Wars tell sleep, but i just said it will kick in one day...And you know you when someone disturb Marvick, NaN or flonder we might mess up a Master Piece.I know what to do first. There some preety heavy hitter questing now and they are not afraid. I should be talking code and i hope it don't stop, but I am just proud of all the work you guy have done for us all of this time. I got a LONg Lissssst. And i have learned a lot behind it. No more love letter.

I got an handle on it now...Thanks to these words..Thats all i need to know but should have known :)

CodeLover, you are correct, specially when we make masm itself do for Windows what we want it to do. The Right Way, the Coders Way...It want be long...
Posted on 2002-04-22 17:51:34 by cmax
I tried but i can get it to work. I useing numbers that is all ready in BYTE size Buffer and want to put the sum in the Sum_Buffer1.

Could you help me out with this. I tried with DWORD Buffers but i know im not doing something right, all i get is #@K%. I would really like to know how to do it with DWORD and BYTE Buffers. But i prefer BYTE Buffers.

.data

Sub1 db '1000',0
Sub2 db '2000',0

.data?

Sum_Buffer1 BYTE 5 dup(?)
Sum_Buffer2 BYTE 5 dup(?)

.code
Main:


mov eax, offset Sub1
sub eax,200
mov Sum_Buffer1, eax

invoke MessageBoxA, 0, offset Sum_Buffer1, 0, 0

invoke ExitProcess,0

end Main
Posted on 2002-04-23 18:30:25 by cmax
First, realize that numbers come in several formats.

Second, know that the processor works with numbers in binary form.

Third, know that the assembler will save something like this:
buffer1 dd 1000

in binary form.

Fourth, know that the assembler will save something like this:
buffer1 db '1000'

in ASCII form.

Therefore:
Convert ascii form to binary using MASM32Lib's atodw.

Have fun.

If you don't have MASM32Lib.... Just post and you can learn how to make atodw yourself!
Posted on 2002-04-23 18:48:40 by AmkG
What do you think about this.... The above is just to give an idea of what i am trying to do...Edvidently it was not the kind of example to present.

In my program I reading real numbers into a buffer at runtime.....1000 is in a BYTE BUFFER...I use the message box to make sure it is there. so I am dealing with straight-up numbers and i want to click a button to subtract 200 from 1000 to get 800 in real number from in a seprate BYTE buffer. It seem to me that it can be done easly, but i just don't know how to do it...
Posted on 2002-04-23 19:06:39 by cmax
cmax,


...
include masm32.inc
includelib masm32.lib
.data
Num1 dd 1000
.data?
Balance dd ?
SymbolicNumber db 12 dup (?)
.code
mov eax,Num1
sub eax,200
mov eax,Balance
;dwtoa - convert number to decimal symbolic represantation
;params: number, addr buffer for numeric symbolic string
invoke dwtoa,eax,offset SymbolicNumber
invoke MessageBox,0,offset offset SymbolicNumber,0,0
call ExitProcess

Posted on 2002-04-23 19:11:01 by The Svin
Svin, I used it and it only returned the number 0... So i put all the stuff under one file and it still returned the number 0 ... So i change stuff around a lot and it still returned 0... What do you think is missing.

.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:SWORD


include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\masm32.lib


wsprintfA PROTO C :DWORD,:VARARG
wsprintf equ <wsprintfA>



.data
Num1 dd 1000
;;;;Num1 db "1000",0

s_FormatText1 db "%lu",0

.data?
Balance dd ?
SymbolicNumber db 128 dup (?)

.code

start:

mov eax,Num1
sub eax,200
mov eax, Balance

invoke wsprintf,offset SymbolicNumber, offset s_FormatText1,eax

invoke MessageBox,0, offset SymbolicNumber,0,0
call ExitProcess
end start
Posted on 2002-04-23 20:13:11 by cmax

mov eax,Num1
sub eax,200
mov eax, Balance

You throw away your calculated number right after the calculation...
sleep more, take less drugs before programming ;)
Posted on 2002-04-23 20:48:23 by f0dder
PS:

I need this to work on a 386 or 486 thats why i was afraid of floats but if it work on those basic machines I can deal with it. Anything that can make it work I Will be Happy...

Thanks again
Posted on 2002-04-23 20:54:16 by cmax
floats wont work on a 386sx unless there's math emu software
running, but I doubt you'll find a 386 running windows. 486's
are capable of doing it (though it's not too much fun), and I doubt
you'll find a 486 without a coprocessor. But using floats for something
as simple as this would be making your task harder than it is.

You just have to understand the difference between a "number
in memory" (as in a number your machine understands and can
operate on), and ASCII (or whatever other) representations of
this number. A string like "1000" is ASCII, and there's just no way
for your machine to directly work with this as a number. The ASCII
sequence "1000" would be seen by your computer as the number
0x30303031, which is clearly not what you want ;).
Posted on 2002-04-23 21:04:07 by f0dder
Svin, I used it and it only returned the number 0...

It is my fault - I exchange number of params :)
f0dder's right it is needed to be
mov Balance,eax

Do it this way


...
include masm32.inc
includelib masm32.lib
.data
Num1 dd 1000
.data?
Balance dd ?
SymbolicNumber db 12 dup (?)
.code
mov eax,Num1
sub eax,200
mov Balance,eax
;dwtoa - convert number to decimal symbolic represantation
;params: number, addr buffer for numeric symbolic string
invoke dwtoa,eax,offset SymbolicNumber
invoke MessageBox,0,offset offset SymbolicNumber,0,0
call ExitProcess

Posted on 2002-04-24 00:07:06 by The Svin
But i could never be suprize. I played with it all night. Now i understand much more than i ever knew about DWORDS and BYTE. You will never hear me crying anymore about Windows. There always a work around with ASM. This explain it ALL... I hope you know you and many others here are GOD Gift to the World.

Thank You
Posted on 2002-04-24 06:25:06 by cmax