Page 1 of 1
"hello, world" purely in FASM for PureBasic?
Posted: Tue Mar 09, 2010 8:10 am
by Nituvious
Does anyone happen to have an example of a hello world done entirely in assembly for purebasic?
I am interested in understanding a little about Assembly

Re: "hello, world" purely in FASM for PureBasic?
Posted: Tue Mar 09, 2010 8:23 am
by djes
Re: "hello, world" purely in FASM for PureBasic?
Posted: Tue Mar 09, 2010 8:44 am
by Nituvious
Hi djes! Thank you for the reply!
I tried your code:
Code: Select all
MOV AH, 09
MOV DX, 0108
INT 21
RET
DB "Hello World!$"
But I receive:
"Error: Line 3
Error: Invalid Memory access. (read error at address 4294967295)"
I am a complete newbie at programming, and I was hoping this could be done entirely in PureBasic using only FASM code.
Re: "hello, world" purely in FASM for PureBasic?
Posted: Tue Mar 09, 2010 9:08 am
by flaith
This code must be run under a console window cause it's a DOS program only so it must be created via the program DEBUG to make a .COM program

Re: "hello, world" purely in FASM for PureBasic?
Posted: Tue Mar 09, 2010 9:13 am
by djes
Legacy code, designed to work even on a 8086, in DOS mode. PB is using fasm on 32/64 bits plateforms, so obviously this code is not made to work directly; the thread explain all of that, but it's in french, sorry
Anyway, a good start to learn asm with PB is to download and install the great PureASM of our talented french coder Erix14 :
http://www.rx14.info/archives/PureASM_Install.exe
With this, you can load a normal PB source and see how it looks in assembly language.
To test the above example, you should try this (doesn't work with some antivirus)
Code: Select all
;Machine code 'Hello World'
;djes 2010
;http://www.purebasic.fr/french/viewtopic.php?f=4&t=10283
If CreateFile(0, "C:\hello.com")
WriteByte(0, $B4) : WriteByte(0,$09) : WriteByte(0,$BA) : WriteByte(0,$08)
WriteByte(0, $01) : WriteByte(0,$CD) : WriteByte(0,$21) : WriteByte(0,$C3)
WriteString(0, "Hello World!$")
EndIf
CloseFile(0)
End
It creates a little executable in c:\ named hello.com. This proggy writes "hello world" if you launch it in a dos box.
Re: "hello, world" purely in FASM for PureBasic?
Posted: Tue Mar 09, 2010 12:37 pm
by c4s
Nituvious wrote:I am a complete newbie at programming
Well, then learn PureBasic itself first?!
Re: "hello, world" purely in FASM for PureBasic?
Posted: Wed Mar 10, 2010 6:16 pm
by Thorium
Actualy you have to use some kind of API for that if your program don't runs in kernel mode.
In the 16bit example, they use a interrupt on 32bit and 64bit you can use the windows API. Basicly the same thing. But that does not make any sense. You learn nothing from it if you want assembler for PureBasic.
So try things that are actualy usefull like calculate something. For displaying your calculations use PureBasic, there is no sense in using assembler for that because you will just call a API doing it for you.
Re: "hello, world" purely in FASM for PureBasic?
Posted: Thu Mar 11, 2010 8:22 am
by flaith
Several examples of "Hello World" here :
Hello World/x86/Windows/Fasm
Re: "hello, world" purely in FASM for PureBasic?
Posted: Thu Mar 11, 2010 12:49 pm
by MikeM
A simple hello.fasm in DOS-mode:
Code: Select all
org 100h ; code starts at offset 100h(256 bytes)
mov ah,9 ; number of DOS-function display_text = 9
mov dx,hello
int 21h
ret
hello db 'Hello world!',24h
Open console(cmd.exe) and:
>fasm.exe hello.fasm hello.com
>hello.com
You'll get:
Hello world!
( fasm.exe in c:\PureBasic\compilers\fasm.exe ).
Re: "hello, world" purely in FASM for PureBasic?
Posted: Tue May 25, 2010 11:04 am
by brianO
if you want to see Hello World!... try this hack
Code: Select all
hw.s=programparameter(0)
if not hw.s
hw.s="Hello World!"
endif
ProcedureDLL ConsoleWrite(t.s)
stdout=GetStdHandle_(#STD_OUTPUT_HANDLE)
written.l
msg.s=t.s+Chr(13)+Chr(10)
size.l=Len(msg.s)
res=WriteFile_(stdout,@msg.s,size, @written, #Null)
res=FreeConsole_()
EndProcedure
EnableASM
!Extrn _strstr
Procedure StringAddress(s1)
Shared s2
p.l
s2=s1
PUSH s2
PUSH s2
CALL _strstr
ADD esp, 8
MOV p, eax
ProcedureReturn p
EndProcedure
ConsoleWrite(peekS(StringAddress(@hw.s)))
Declare.l aadd()
Declare.l asub()
Declare.l amul()
Declare.l adiv()
Procedure.l aadd()
MOV ebx,dword [v_a]
MOV eax,dword [v_b]
ADD eax,ebx
ProcedureReturn
EndProcedure
Procedure.l asub()
MOV ebx,dword [v_a]
MOV eax,dword [v_b]
SUB eax,ebx
NEG eax
ProcedureReturn
EndProcedure
Procedure.l amul()
MOV ebx,dword [v_a]
IMUL ebx,dword [v_b]
MOV eax,ebx
ProcedureReturn
EndProcedure
Procedure.l adiv()
MOV ebx,dword [v_a]
PUSH dword [v_b]
MOV eax,ebx
POP ecx
CDQ
IDIV ecx
MOV ebx,eax
MOV eax,ebx
ProcedureReturn
EndProcedure
a.l=val(programparameter(1))
b.l=val(programparameter(2))
if a=-1
a=10
b= 2:endif
if b>0
ConsoleWrite(str(a)+"+"+str(b)+"="+str(aadd()))
ConsoleWrite(str(a)+"-"+str(b)+"="+str(asub()))
ConsoleWrite(str(a)+"*"+str(b)+"="+str(amul()))
ConsoleWrite(str(a)+"/"+str(b)+"="+str(adiv()))
endif
1] save the code as hello.pb
2] compile it (it doesn't matter if it is console mode or not)
3] if you have an editor such as scite you will see the output... if not
4] create a batch file named test_hello.bat (make sure the extension is not hidden via control panel folder options)
A.) if you want the console to popup in your face try...
Code: Select all
@echo off
cmd /c hello.exe
cmd /c hello.exe "and then some..."
cmd /c hello.exe "add/sub/mul/div" 1234 2
cmd /c hello.exe "add/sub/mul/div" -1
pause
exit
B.) if you have some time on your hands and want notepad to popup up in your face try...
Code: Select all
@echo off
cmd /c hello.exe > hello.txt
cmd /c hello.exe "and then some..." >> hello.txt
cmd /c hello.exe "add/sub/mul/div" 1234 2 >> hello.txt
cmd /c hello.exe "add/sub/mul/div" -1 >> hello.txt
echo ------------------------------------------- >> hello.txt
echo CommandLine=%CmdCmdLine% >> hello.txt
echo FullPath =%~fn0 >> hello.txt
echo CmdParams =%*there are none >> hello.txt
echo FileDir =%~dp0 >> hello.txt
echo FileName =%~nn0 >> hello.txt
echo FileExt =%~x0 >> hello.txt
echo ------------------------------------------- >> hello.txt
@hostname >> hello.txt
echo %date% %time% >> hello.txt
WHOAMI >> hello.txt
echo ------------------------------------------- >> hello.txt
SYSTEMINFO >> hello.txt
echo ------------------------------------------- >> hello.txt
DRIVERQUERY >> hello.txt
echo ------------------------------------------- >> hello.txt
REG QUERY HKCU\Software >> hello.txt
REG QUERY HKLM\SYSTEM\MountedDevices >> hello.txt
REG QUERY HKLM\SYSTEM\CurrentControlSet\services >> hello.txt
REG QUERY HKLM\SYSTEM\CurrentControlSet\Enum\STORAGE\Volume >> hello.txt
REG QUERY HKLM\SYSTEM\CurrentControlSet\Enum\SCSI >> hello.txt
REG QUERY HKLM\SYSTEM\CurrentControlSet\Enum\IDE >> hello.txt
REG QUERY HKLM\SYSTEM\CurrentControlSet\Control\Print\Printers >> hello.txt
cmd /c start /max notepad.exe hello.txt
exit
Re: "hello, world" purely in FASM for PureBasic?
Posted: Tue May 25, 2010 3:25 pm
by Thorium
Or you just invoke a MessageBox, but makes no sense for me. Thats not what inline assembler is good for.