flat assembler
Message board for the users of flat assembler.

Index > Windows > newbie needs help with windows 64

Author
Thread Post new topic Reply to topic
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95
Hello everyone, I studied assembly for DOS for a while and now I'd like to start writing windows programs but I encountered various problems.

First of all I have a 64bit version of windows 7 and googling around I found only w32 tutorials, for the moment I don't really care about writing w64 programs, is it possible to write, compile and run 32 bit programs on a 64 bit OS?

Wether the answer is yes or no what is the basic structure of a windows program? The windows 64 examples are all quite advanced (at least for me!), can someone show me a basic "hello world" program written for w64? I mean, is there something I must include? how am I supposed to end the program? and basic stupid stuff like that.

I guess my question may look extremely obvious or stupid but as I told I'm a complete beginner regarding windows programming (and not a ninja regarding assembly in general), thank in advance for answers (and for the patience, I have the feeling I'll ask you some thousands of question Razz)

Alessandro

p.s.
I hope I didn't slaughter english grammar too much since it isn't my motherlanguage
Post 24 Mar 2013, 02:53
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 21:21; edited 1 time in total
Post 24 Mar 2013, 03:01
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2913
Location: [RSP+8*5]
bitRAKE
Regarding win64, a search for my posts will turn up some basic examples. Definitely get FDBG by ferno!

Shameless self promotion:

Hilbert curve - plotter template
http://board.flatassembler.net/topic.php?p=80896#80896

sub-classing control
http://board.flatassembler.net/topic.php?p=94910#94910

use of nmake (two examples)
http://board.flatassembler.net/topic.php?p=95073#95073

exception handling console app
http://board.flatassembler.net/topic.php?p=109871#109871
Post 24 Mar 2013, 22:26
View user's profile Send private message Visit poster's website Reply with quote
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95
Thank you both, I'm looking at bitRAKE's links right now, truly interesting!

By the way, I'm pretty sure I have already seen your nick somewhere, project euler?
Post 25 Mar 2013, 01:43
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2913
Location: [RSP+8*5]
bitRAKE
Yeah, that's me. Very Happy
Welcome!
Post 25 Mar 2013, 02:58
View user's profile Send private message Visit poster's website Reply with quote
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95
And here I am with the noob question #2:

Right now I have Internet access only from my phone so I'll steal some bitRAKE's code from project euler:
Code:
        ; for each integer from 1 to 1000
        mov ecx, 3

        mov esi, 3
        mov edi, 5

        xor ebx, ebx    ; sum

_0:     mov eax, ecx
        xor edx, edx
        div esi
        test edx, edx
        je _yes

        mov eax, ecx
        xor edx, edx
        div edi
        test edx, edx
        jne _no

_yes:   add ebx, ecx

_no:    inc ecx
        cmp ecx, 1000
        jne _0    


OK, the code is very clear but how do you print or read the value of ebx once it.finished the calculations?
Post 28 Mar 2013, 01:22
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2913
Location: [RSP+8*5]
bitRAKE
I ran it in OllyDbg. Cliick at the end and push F2 or put an INT3 in the code, and push F9. Look at the register window. Wink

Of course, you could write a console template to display results, but why? Get comfortable with the debugger - it's there to help and it speaks your language.

http://www.ollydbg.de/ - is an excellent 32-bit debugger, works in Win64 on 32-bit code.
Post 28 Mar 2013, 01:27
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2913
Location: [RSP+8*5]
bitRAKE
Not sure where you are in the n00b-ness. Thought I'd post the minimal wrapper for you:
Code:
format PE GUI 4.0 ; tell FASM what's up

{put code HERE}

  int3 ; force debugger to stop
  retn ; lazy quit to Windows    
Definitely read the FASM manual to get all the other Windows bells and whistles going.
Post 28 Mar 2013, 15:41
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2913
Location: [RSP+8*5]
bitRAKE
...and use this to debug with FDBG in 64-bit:
Code:
format PE64 GUI 5.0 ; tell FASM what's up 

{put code HERE} 

  int3 ; force debugger to stop 
  retn ; lazy quit to Windows    
...see virtually the same.
Post 28 Mar 2013, 15:44
View user's profile Send private message Visit poster's website Reply with quote
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95
thank you, this evening I'll finally have time to experiment a bit around, which means tomorrow I'll have a lot of other questions probably Razz
Post 29 Mar 2013, 07:39
View user's profile Send private message Reply with quote
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95
Ok, I played with the x87 FPU for a while, looks messy but was working, then I was trying another program and i encountered this (extremely stupid) problem:

Code:
format PE GUI 4.0 

  number dd ?

  mov ecx,15
  mov [number],ecx

  int3
  retn     


the code compiles properly but doesn't do what it is supposed to, why?
Post 30 Mar 2013, 01:42
View user's profile Send private message Reply with quote
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95
Was my question that embarassing not to deserve an answer Razz?
Post 31 Mar 2013, 03:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
alessandro95: You never explained what your code is supposed to do.

But perhaps the problem is that you are executing from the address 'number' at program start?

Anyhow, ollydbg would be an excellent way to see what is happening with the code. You can follow through one instruction at a time and watch it.
Post 31 Mar 2013, 03:21
View user's profile Send private message Visit poster's website Reply with quote
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95
I just want to move the value of a register to somewhere in the memory (to pass it to the FPU later since it cannot be loaded directly from a register).

I looked at the program in olly but I cannot understand what's going on during the first 2 instruction (I'm posting from my mobile phone because I don't have internet access on my computer and I don't have my computer with me, otherwise I would post these 2 instruction), I'm just trying to reserve some space and move a value into it, nothing more than this
Post 31 Mar 2013, 03:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
Perhaps the first two instruction are not what you expect. The CPU starts executing at 'number' (which contains four 0x00 bytes).
Post 31 Mar 2013, 03:32
View user's profile Send private message Visit poster's website Reply with quote
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95
They definetely aren't what I expect Razz

and I now understood what you mean, I need to specify that the entry point is mov ecx,15 , right?
Post 31 Mar 2013, 03:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
alessandro95 wrote:
... I need to specify that the entry point is mov ecx,15 , right?
I think so.

But maybe better if you move the variables to a different section from the code. That way when your code expands you will already have a good program layout to work from.
Post 31 Mar 2013, 04:27
View user's profile Send private message Visit poster's website Reply with quote
alessandro95



Joined: 24 Mar 2013
Posts: 62
alessandro95
Ok, thank you!
Post 31 Mar 2013, 04:37
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1409
Location: Toronto, Canada
AsmGuru62
alessandro95:
You can find a 64-bit code example in FASM folder EXAMPLES\WIN64\PE64DEMO.
Notice the 'entry' statement, where label is specified where to start the program.
Also, notice that variables are in its own section, and code is in its own section too.
Post 31 Mar 2013, 12:06
View user's profile Send private message Send e-mail 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.