flat assembler
Message board for the users of flat assembler.

Index > Windows > Another Question: Regarding The Output of Math Operations

Author
Thread Post new topic Reply to topic
Misha06



Joined: 18 May 2009
Posts: 8
Misha06
Code:
Include '%fasminc%/win32ax.inc'
.data

Three   db 3
Four     db 4

xor eax,eax

ToPrint dd ?

.code 
        start:

               add al,[Three]
               add al,[Four]
               add al,30h 
               mov [ToPrint],eax

                invoke  MessageBox, NULL,[ToPrint],"Math", MB_OK
                invoke  ExitProcess,0
.end start 
    


I remember from Java that it was necessary to do some arithmetic- add a displacement value- before it was possible to output as a String. I am having some trouble doing this in FASM because I am unsure of the offset on UTF16 and I am generally unsure if this is the correct approach.
Post 19 May 2009, 05:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
You need to initialise your register first:
Code:
...
start:
mov eax,0 ;<--- start with a known value (can use 'xor eax,eax' if you want)
add al,[Three]
...    
There are some advanced instructions you can use also:
Code:
...
start:
movzx eax,[Three] ;<--- zero the upper part of EAX
...    
Post 19 May 2009, 05:43
View user's profile Send private message Visit poster's website Reply with quote
Misha06



Joined: 18 May 2009
Posts: 8
Misha06
That was what I originally tried to do, but every time I run the file Windows tells me the program has crashed.

Code:
 start:
              mov eax,0
              mov al,[Three]
              ...
    
Post 19 May 2009, 05:56
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Madis731
I will help you out - the working code:
EDIT: Moving eax-zeroing to the correct place
Code:
include 'win32ax.inc'
.data

Three   db 3
Four     db 4

ToPrint dd ?

.code 
        start:
               xor eax,eax
               add al,[Three]
               add al,[Four]
               add al,30h 
               mov [ToPrint],eax

                invoke  MessageBox, NULL,ToPrint,"Math", MB_OK
                invoke  ExitProcess,0
.end start
    


Last edited by Madis731 on 19 May 2009, 07:06; edited 1 time in total
Post 19 May 2009, 06:00
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Misha06



Joined: 18 May 2009
Posts: 8
Misha06
Thank you for your time, but I believe thats what I originally had, and to my chagrin it gives me the same results Sad

Here, is a print screen of the crash that happens when I try to zero out eax register:
http://yfrog.com/e9crashj
Post 19 May 2009, 06:05
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Oh, this also needs to be:
Code:
 invoke  MessageBox, NULL,ToPrint,"Math", MB_OK    
Note the removal of the square brackets.
Post 19 May 2009, 06:07
View user's profile Send private message Visit poster's website Reply with quote
Misha06



Joined: 18 May 2009
Posts: 8
Misha06
Oh thank you but, the results are still odd - I get something like "^?xv"
Post 19 May 2009, 06:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
The string in ToPrint needs to be null terminated. So setting the high part of EAX to zero gives you this.
Post 19 May 2009, 06:10
View user's profile Send private message Visit poster's website Reply with quote
Misha06



Joined: 18 May 2009
Posts: 8
Misha06
Okay, thank you now everything is working perfectly.
Post 19 May 2009, 06:11
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
One other little thing, the 'xor eax,eax' will never get executed in your data section, you should put that just below the 'start:' label.
Post 19 May 2009, 06:25
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Madis731
EDIT: a little too late Smile
Post 19 May 2009, 06:56
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.