flat assembler
Message board for the users of flat assembler.

Index > DOS > My first "Hello_world" app

Author
Thread Post new topic Reply to topic
maton1200



Joined: 08 Oct 2010
Posts: 4
maton1200
Hi.

I'm newbie in X86 windows assembly programming, i have never programmed in assembly language for PCs, but i used to program PIC microcontrollers long ago, so i decided to give a try to X86 / X86-64 assembly for windows using FASM.

i've been reading online manuals and i think this is an alternative to .COM a hello world application :


org 100h
use16
ret
mov ah, 09h
SAY db 'hello_world'
mov dx,SAY
int 21h


However when I run this from CMD, nothing happens .

According to some info around the internet the INT 21h executes several functions depending on AH's value.

but why my code is not working?.

_________________
......
Post 08 Oct 2010, 15:05
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Hello........
Code:

org 100h
use16

   mov     ax,0003h
    int     10h

     mov     ah, 09h
     mov     dx,SAY
      int     21h 

    xor     ax,ax
       int     16h

     ret

SAY db 'hello_world',24h

    

_________________
Nil Volentibus Arduum Razz


Last edited by DJ Mauretto on 08 Oct 2010, 15:16; edited 3 times in total
Post 08 Oct 2010, 15:14
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
You need a 16- or 32-bit OS. However, the most likely problem by which your program didn't do anything was just because the very first instruction is RET (i.e. return).

The proper way is this:
Code:
mov ah, 09h
mov dx,SAY
int 21h
int 20h ; Use this to exit program instead of plain RET for COM files

; x86 is not Harvard arquitecture, therefore you must be careful not to put data in places where it could get executed.
; Placing data just after an unconditional branch (like Int 20h above) is enough
SAY db 'hello_world'    
Post 08 Oct 2010, 15:14
View user's profile Send private message Reply with quote
maton1200



Joined: 08 Oct 2010
Posts: 4
maton1200
@DJ Mauretto : thanks, those interrupts are very helpful, but why do you put 24h at the end of text?.

@locodelassembly: thanks but your code compiles as .BIN and it runs weird after I rename it to .COM, weird smileys show up onscreen
Post 08 Oct 2010, 16:24
View user's profile Send private message Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto
Quote:
thanks, those interrupts are very helpful, but why do you put 24h at the end of text?.

Dos function use 24h or '$' as end of string Rolling Eyes

_________________
Nil Volentibus Arduum Razz
Post 08 Oct 2010, 16:28
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
maton1200, sorry, I stripped the "org 100h" by accident, it should be the first thing in the source. And the wierd stuff is because I forgot to terminate the string with the dollar sign as DJ Mauretto mentions.
Post 08 Oct 2010, 18:10
View user's profile Send private message Reply with quote
maton1200



Joined: 08 Oct 2010
Posts: 4
maton1200
Thanks.

I'm trying to run my app in Windows 7 ultimate X64 command line but i get this message.

"This version of ( my app) is not compatible with the version of Windows you are running. Check your computer.." etc.

I dont know if the interrupts are not valid in 64 bit OS.

Any ideas?

_________________
......
Post 11 Oct 2010, 02:50
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
NTVDM was removed from x64 Windows. You have to either run it in a DOS emulator, like DOSBox or DOSEmu, or rewrite it as 32 or 64 bit. The interrupts will not work as you want in 32 and 64bit mode, you will have to use some kind of API like WinAPI or libc.

Alternatively, if your processor supports hardware based vitalisation, you can install XP Mode, which is capable of running 16bit tasks.
Post 11 Oct 2010, 02:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17450
Location: In your JS exploiting you and your system
revolution
maton1200: Basically, Windows 7 64-bit does not support 16-bit programs. You need to download one of the DOS emulators or run a VM.

But perhaps a better option would be to write this as a 32-bit application:
Code:
include 'win32ax.inc'

.code

start:
 invoke  MessageBox,0,'Hello world!','Hello world!',0
    invoke  ExitProcess,0

.end start    
Post 11 Oct 2010, 04:55
View user's profile Send private message Visit poster's website Reply with quote
maton1200



Joined: 08 Oct 2010
Posts: 4
maton1200
@Tyler thanks, and yes, I do have an XP VM in VMWARE player but I want my codes to be executed in W7 32 and 64 bit.

@revolution : so basically I cant assemble MS-DOS code for W7 64 bit, and all I have to do is program code compatible with Window's API which is quite similar to that code you just wrote ?.
Post 11 Oct 2010, 13:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17450
Location: In your JS exploiting you and your system
revolution
maton1200 wrote:
@revolution : so basically I cant assemble MS-DOS code for W7 64 bit, and all I have to do is program code compatible with Window's API which is quite similar to that code you just wrote ?.
You can assemble 16-bit programs. But you can't run them on 64-bit Windows 7 without some form of emulation.
Post 11 Oct 2010, 13:59
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Installing and using DOSBox is extremely easy, and it works very well. But it's quite slow. It's not suitable for anything other than games and simple apps. (No compiling under it, that would be annoying even if it would, only sometimes, work.)

XP Mode doubles your HD and RAM requirements, and it's technically (legally?) only available to non-home users, e.g. Business, Enterprise, Ultimate. (Why??) But it doesn't need VT-X anymore, thankfully. At least if you're going to run 64-bit, you should have enough RAM for plenty of VMs. Wink
Post 11 Oct 2010, 19: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:  


< 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.