flat assembler
Message board for the users of flat assembler.

Index > Main > Please help and teach me :)

Author
Thread Post new topic Reply to topic
mastek



Joined: 29 Jun 2006
Posts: 17
mastek
Hello. I am new and beginner about assembler. I choose fasm because it is updating always.

I have C code simple program (source below). But I could not convert fasm code. Can you help me ?

I want to convert fasm 32 bit dos (I love DOS Smile and Win 32 Window application

Would you tech me ?

best regards


C code :

#include <stdio.h>

int main

{
printf(" Hello World 1 \n");
printf(" Hello World 2 \n");
printf(" Hello World 3 \n");

return 0;
}
Post 08 Apr 2015, 09:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17350
Location: In your JS exploiting you and your system
revolution
The "hello World" source codes for various systems are already included in the fasm download. See the folder named "examples".
Post 08 Apr 2015, 09:08
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 311
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
the simplest examples
Code:
        org     100h

        mov     bx,Hello
        call    PrintStr
        mov     byte [bx+12],'2'
        call    PrintStr
        mov     byte [bx+12],'3'
PrintStr:
        mov     ah,9
        mov     dx,bx
        int     21h
        ret

Hello   db      'Hello World 1',13,10,36
    

Code:
        org     100h

        call    PrintStr
        call    PrintInc
PrintInc:
        inc     byte [Hello+12]
PrintStr:
        mov     ah,9
        mov     dx,Hello
        int     21h
        ret

Hello   db      'Hello World 1',13,10,36
    

Code:
        org     100h

        mov     cx,3
      @@:
        mov     ah,9
        mov     dx,Hello
        int     21h
        inc     [Hello+12]
        loop    @B
        ret

Hello   db      'Hello World 1',13,10,36
    

_________________
smaller is better
Post 08 Apr 2015, 15:16
View user's profile Send private message Reply with quote
mastek



Joined: 29 Jun 2006
Posts: 17
mastek
CandyMan wrote:
the simplest examples
Code:
        org     100h

        mov     bx,Hello
        call    PrintStr
        mov     byte [bx+12],'2'
        call    PrintStr
        mov     byte [bx+12],'3'
PrintStr:
        mov     ah,9
        mov     dx,bx
        int     21h
        ret

Hello   db      'Hello World 1',13,10,36
    

Code:
        org     100h

        call    PrintStr
        call    PrintInc
PrintInc:
        inc     byte [Hello+12]
PrintStr:
        mov     ah,9
        mov     dx,Hello
        int     21h
        ret

Hello   db      'Hello World 1',13,10,36
    

Code:
        org     100h

        mov     cx,3
      @@:
        mov     ah,9
        mov     dx,Hello
        int     21h
        inc     [Hello+12]
        loop    @B
        ret

Hello   db      'Hello World 1',13,10,36
    


@CandyMan

thank you soo much. Can you show me 32 bit unreal mode and win32 window versions?
Post 08 Apr 2015, 20:17
View user's profile Send private message Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 311
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan

_________________
smaller is better


Last edited by CandyMan on 14 Apr 2015, 17:48; edited 1 time in total
Post 09 Apr 2015, 12:53
View user's profile Send private message Reply with quote
mastek



Joined: 29 Jun 2006
Posts: 17
mastek


Thank you candyman.

Time to work for me Smile
Post 10 Apr 2015, 12:50
View user's profile Send private message Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas
Here is an example for windows command line:

Code:
format PE console  ;this is a command line program

include 'win32ax.inc'  ;load standard fasm macros for windows


define  \n 13,10  ;define newline as convenience for C programmers Smile

.code
start:
        invoke  GetStdHandle,STD_OUTPUT_HANDLE    ;windows funtion that returns handle to STDOUT
        mov     [handle],eax                      ;save handle
        invoke  WriteFile,[handle],string1,str_len1,n_written,0   ;this windows functtion is similar to C "fwrite"
        invoke  WriteFile,[handle],string2,str_len2,n_written,0   ;since we are not using printf formating anyway
        invoke  WriteFile,[handle],string3,str_len3,n_written,0   ;there is a wsprintf function in windows if you really need it

        mov     eax,0   ;these 2 lines are C "return 0;"
        ret

.data

string1 db "Hello, World!!! 1",\n
str_len1 = $-string1   ;to calculate the lenght of the string

string2 db "Hello, World!!! 2",\n
str_len2 = $-string2

string3 db "Hello, World!!! 3",\n
str_len3 = $-string3

n_written dd 0   ;we don't use this variable, but WriteFile requires it...
handle dd 0

.end start      ;.end is a very convenient standard fasm macro Smile     
    


To get details on windows functions, you can check msdn. I used 3 strings instead of a dynamically modifying string like CandyMan did, for clearness. So, you can try to write the windows version of the modifying code as exercise Smile

BTW, I notice you registered here in 2006 Shocked lol, you post even less than me Laughing
Post 24 May 2015, 23:05
View user's profile Send private message 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. Also on YouTube, Twitter.

Website powered by rwasa.