flat assembler
Message board for the users of flat assembler.

Index > Windows > NEW TO ASSEMBLY

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 03:39
Hello I am new to assembly and I downloaded FASM to run Assembly code.

I need to write a small program like this

Sum:

push; %ebp
movl %esp, %ebp
movl 8(%ebp), %ecx
movl 12(%ebp), %edx
xorl %eax, %eax
testl %edx, %edx
je .L34

.L35:
addl (%ecx), %eax
addl $4, %ecx
decl %edx
jnz .L35

.L34:

movl %ebp, %esp
popl %ebp
ret

The problem is that i am not sure how to run it in FASM, do i need to do a include somewhere or something? my pc is a 64bit and also when i compile something it gives me an error, but if i import one of the examples it works fine.,..

Thank you for your help

Regards
Post 07 Feb 2011, 03:39
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 07 Feb 2011, 03:53
That's GAS syntax. Fasm uses Intel syntax. But, even if you were to run that, it wouldn't do anything you could see because it has no output.

Intel:
Code:
Sum:
push ebp
mov  ebp, esp
mov  ecx, ebp + 8 ; I think
mov  edx, ebp + 12 ; I think
xor  eax, eax
test edx, edx
je   .L34

.L35:
add  eax, ecx
add  ecx, 4
dec  edx
jnz  .L35

.L34:
mov  esp, ebp
pop  ebp
ret
    
Post 07 Feb 2011, 03:53
View user's profile Send private message Reply with quote
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 04:25
Thank you Sir, But i do get errors, It also complains about the labels, do i need to put em some where?, I just need to make this compile correctly.


Description: Error Shown Here
Filesize: 31.89 KB
Viewed: 7458 Time(s)

example.jpg


Post 07 Feb 2011, 04:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 07 Feb 2011, 04:26
edprog: What you have there is AT&T syntax and fasm can't assemble that.

And what you have is a function, not a program. You have to have a full program before you can run anything. fasm does not run code, it only assembles code for running later in your OS.

BTW Tyler:
Code:
mov  ecx, [ebp + 8]
mov  edx, [ebp + 12]    
Post 07 Feb 2011, 04:26
View user's profile Send private message Visit poster's website Reply with quote
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 04:35
Thank you revolution

Yes it is the code generated (per the book) from the function in C

int Sum(int *Start, int Count)
{

int sum = 0;
while(Count) {
sum += *Start;
Start++;
Count--;
}
return sum;
}

I need to make it run somewhere, there is another program i will need to write with arrays but thats a topic for later,... so basically is there anyway I could see output when running this type of code?, like a manifest of how the data is allocated in memory or something.. some sort of output file?

Thank you Gentlemen
Post 07 Feb 2011, 04:35
View user's profile Send private message Reply with quote
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 04:37
Or what can I use to run thes e programs, they give me two options

IA32 Code or Y86 Code.. I am jus tlost on where and how to run these programs..

Thank you
Post 07 Feb 2011, 04:37
View user's profile Send private message Reply with quote
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 04:44
After I ran the program with FASM, with your correction it compiles perfectly, is there anywhere i could see in more detail what the program is doing?, or how can I pass some parameters to this function to show me an output?, I know C, C++ but its the first time I am doing assembly.

Thank you
Post 07 Feb 2011, 04:44
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 07 Feb 2011, 04:55
Have a look at OllyDbg. You can follow the execution one instruction at a time. But you will need a small wrapper section to call the function with some values for it to make sense.
Code:
include 'win32ax.inc'

.data

values:
    dd      34,78,12,3535,66
    count   =5

.code

start:
   ccall   Sum,values,count
    ;return value is in eax
     invoke  ExitProcess,eax

Sum:
     push    ebp
 mov     ebp,esp
     mov     ecx,[ebp+8]
 mov     edx,[ebp+12]
        xor     eax,eax
     test    edx,edx
     je      .L34
    .L35:
       add     eax,[ecx]
   add     ecx,4
       dec     edx
 jnz     .L35
    .L34:
       mov     esp,ebp
     pop     ebp
 ret

.end start    
Post 07 Feb 2011, 04:55
View user's profile Send private message Visit poster's website Reply with quote
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 05:01
Thank you Revolution for helping me so mucch with this, I do get the following exception... I will also look at the link you provided.


Description:
Filesize: 39.85 KB
Viewed: 7447 Time(s)

Error example.jpg


Post 07 Feb 2011, 05:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 07 Feb 2011, 05:09
You forgot the 'x'. WIN32AX.INC. And you forgot the data defined for values. You can copy and paste the code from the forum into the fasm editor. I posted a complete source, you don't need to add anything else like 'format' to get it running.


Last edited by revolution on 07 Feb 2011, 05:10; edited 1 time in total
Post 07 Feb 2011, 05:09
View user's profile Send private message Visit poster's website Reply with quote
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 05:10
Hello Revolution, I am sorry, I had other things there that were causing the compilation error. Now it works fine.. so I suppose it wont show the out-put right?

Thank you
Post 07 Feb 2011, 05:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 07 Feb 2011, 05:12
The exit code is the output sum. Not easy to use though.

But try OllyDbg anyway to help you understand what is happening.
Post 07 Feb 2011, 05:12
View user's profile Send private message Visit poster's website Reply with quote
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 05:34
revolution wrote:
The exit code is the output sum. Not easy to use though.

But try OllyDbg anyway to help you understand what is happening.



Thank you revolutiuon, and how would i be able to see the exit code?
Post 07 Feb 2011, 05:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 07 Feb 2011, 05:37
edprog wrote:
... how would i be able to see the exit code?
OllyDbg shows you the exit code.
Post 07 Feb 2011, 05:37
View user's profile Send private message Visit poster's website Reply with quote
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 05:37
edprog wrote:
Or what can I use to run thes e programs, they give me two options

IA32 Code or Y86 Code.. I am jus tlost on where and how to run these programs..

Thank you


Which one should I download

Download

Download OllyDbg 1.10 (final version)

Download Plugin Development Kit 1.10 (requires OllyDbg 1.10)

Download free source of command line plugin (requires OllyDbg 1.08 or 1.10 and Borland's BCB 5.0)


Older versions

Download OllyDbg 1.08b (previous "official" release)


Download Plugin Development Kit 1.08



Version 1.00 (mostly of historical value)
Post 07 Feb 2011, 05:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 07 Feb 2011, 05:40
Download OllyDbg 1.10 (final version), it is enough to start with.
Post 07 Feb 2011, 05:40
View user's profile Send private message Visit poster's website Reply with quote
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 05:44
Hello revolution,

I downloaded it, any tips on how to use it?

Thank yoi
Post 07 Feb 2011, 05:44
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 07 Feb 2011, 05:46
You have to download OllyDbg 1.10 final.
OllyDbg is a debugger. It will load your program and will show you the instructions, registers and will execute the program instruction by instruction in order to show you how it works.
Post 07 Feb 2011, 05:46
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
edprog



Joined: 07 Feb 2011
Posts: 19
edprog 07 Feb 2011, 05:56
Thank you Guys

So, this shall be my last question for the dat and I do appreciate your patience,

by looking below, if I wanted to see at the result which line would it be it?

Regards


Description:
Filesize: 105.04 KB
Viewed: 7419 Time(s)

OdbgShot.jpg


Post 07 Feb 2011, 05:56
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 07 Feb 2011, 05:58
You didn't post enough of the picture. The exit code is at the bottom in the status bar. But you have to press F9 to run the program first.
Post 07 Feb 2011, 05:58
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.