Assembler in Freebasic
-
- Posts: 3
- Joined: Oct 13, 2017 1:55
Assembler in Freebasic
Does Freebasic support the assembler tutorials on Pete's Qbasic page?
Re: Assembler in Freebasic
You didn't tell us which tutorials exactly, but in general using Assembler with FreeBasic is a bit different than using it in QB:
- FreeBasic supports Inline Assembler while QB didn't
- FreeBasic is 32-bit or 64-bit while QB was 16-bit; so you'll have to use according assembly code
- FreeBasic runs in protected mode, while QB ran in real mode
- QB ran on DOS only; FB runs on Windows, Linux, DOS and others, so you can't rely on DOS APIs if you want a portable application; anyway you'd have to use DPMI even in DOS to access DOS APIs (due to the protected mode / real mode transition)
- FreeBasic supports Inline Assembler while QB didn't
- FreeBasic is 32-bit or 64-bit while QB was 16-bit; so you'll have to use according assembly code
- FreeBasic runs in protected mode, while QB ran in real mode
- QB ran on DOS only; FB runs on Windows, Linux, DOS and others, so you can't rely on DOS APIs if you want a portable application; anyway you'd have to use DPMI even in DOS to access DOS APIs (due to the protected mode / real mode transition)
-
- Posts: 3
- Joined: Oct 13, 2017 1:55
Re: Assembler in Freebasic
http://www.petesqbsite.com/sections/tut ... mbly.shtml
"Learn ASM In One Hour Flat" Series by abionnnn
It is down near the bottom of list.
Where are the Freebasic Assembler tutorials?
"Learn ASM In One Hour Flat" Series by abionnnn
It is down near the bottom of list.
Where are the Freebasic Assembler tutorials?
Re: Assembler in Freebasic
There is a page in the manual about ASM : https://www.freebasic.net/wiki/wikka.php?wakka=KeyPgAsm
You can also find an "Inlineassembler in FreeBASIC" tutorial here , but text is in German (though I doubt if the code cares ;-) :
https://www.freebasic-portal.de/tutoria ... ic-50.html
Also there is an Inline assembler discussion thread here :
viewtopic.php?t=25549
Then there is this , but I guess that you want something more advanced : Lil' ASM tutes: viewtopic.php?t=21574
You can also find an "Inlineassembler in FreeBASIC" tutorial here , but text is in German (though I doubt if the code cares ;-) :
https://www.freebasic-portal.de/tutoria ... ic-50.html
Also there is an Inline assembler discussion thread here :
viewtopic.php?t=25549
Then there is this , but I guess that you want something more advanced : Lil' ASM tutes: viewtopic.php?t=21574
Re: Assembler in Freebasic
Didn't ever look for those (anyway, not the core busyness, of FB, to teach ASM) ...SoCalTechnologies wrote:Where are the Freebasic Assembler tutorials?
FB's inline assembler is for programmers, that are used to code ASM (not beginners).
However, plenty examples can be found ... (searching this forum).
-
- Posts: 3
- Joined: Oct 13, 2017 1:55
Re: Assembler in Freebasic
Thank you.
Will keep you posted.
Looks like it is 'Learn Assembler in One Hour' for now.
Will keep you posted.
Looks like it is 'Learn Assembler in One Hour' for now.
-
- Posts: 862
- Joined: May 05, 2015 5:35
- Location: Germany
Re: Assembler in Freebasic
That's real optimism. <grin>"Learn ASM In One Hour Flat"
-
- Posts: 3908
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Assembler in Freebasic
If you are using a 32 bit machine the tutorial is perhaps a bit out of date. Also by using the FreeBASIC inline assembler code you can mix both worlds as opposed to learning assembler using a compiler like the old TASM. I used to use 16 bit assembler as my language of choice on the old MSDOS machines and before that 32 bit assembler on the old 68000 cpu Amiga machine. I often worked out the code in BASIC and then translated down to assembler code. For example this turns a 640x480 bitmap color image into a gray scale version. It is written only in FreeBASIC but does the same thing as the example that follows that is written using inline assembler. It may give you an idea of how you can use your knowledge of BASIC to leverage into Assembler code.SoCalTechnologies wrote:Looks like it is 'Learn Assembler in One Hour' for now.
You must have a 640x480 bitmap image in the same folder and change the source code below with your own bitmap file name.
I used a bitmap image called boat2.bmp
Bload "boat2.bmp", image 'place 640 x 480 image in same folder
Code: Select all
#include "fbgfx.bi"
screenres 640,480,32
Dim image As Any Ptr
image = imagecreate( 640, 480 )
Bload "boat2.bmp", image 'place 640 x 480 image in same folder
Put(0, 0), image
sleep
dim as ulong eax,edx 'variables with same name as the CPU 32 bit registers
for j as integer = 0 to 479
for i as integer = 0 to 639
eax = point(i,j,image) 'mov eax, [ebx+ecx*4]
eax = eax AND 255 'And eax, 255
edx = point(i,j,image) 'mov edx, [ebx,ecx*4]
edx = edx SHR 8 'shr edx, 8
edx = edx AND 255 'and edx, 255
eax = eax + edx '
eax = eax SHR 1
edx = point(i,j,image)
edx = edx SHR 16
edx = edx AND 255
eax = eax + edx
eax = eax SHR 1
edx = eax
eax = eax SHL 8
eax = eax OR edx
eax = eax SHL 8
eax = eax OR edx
pset image,(i,j),eax
next i
next j
Put(0, 0), image, Pset
imagedestroy(image)
Sleep
Code: Select all
#include "fbgfx.bi"
screenres 640,480,32
Dim buff As Any Ptr
buff = imagecreate( 640, 480 )
Bload "boat2.bmp", buff 'place 640 x 480 image in same folder
Put(0, 0), buff
'' Skip over image header.
Dim As Any Ptr ppix = buff + sizeof( fb.image )
Sleep
asm
mov ecx, 640*480 '
mov ebx, [ppix] '
L1:
mov eax, [ebx+ecx*4] '
And eax, 255 ' gets blue
mov edx, [ebx+ecx*4] '
Shr edx, 8 '
And edx, 255 '
add eax, edx ' add green
Shr eax, 1
mov edx, [ebx+ecx*4]
Shr edx, 16
And edx, 255
add eax, edx ' add red
Shr eax, 1
mov edx, eax
Shl eax, 8
Or eax, edx
Shl eax, 8
Or eax, edx
mov [ebx+ecx*4], eax
dec ecx
jnz L1
End asm
Put(0, 0), buff, Pset
imagedestroy( buff )
Sleep
Last edited by BasicCoder2 on Oct 16, 2017 8:03, edited 1 time in total.
Re: Assembler in Freebasic
© Copyright Nightwolf Productions 1999SoCalTechnologies wrote:"Learn ASM In One Hour Flat" Series by abionnnn
That is 16-bit assembly, won't work on any modern PC. For more recent x86 tutorials, see e.g. Help and tutorials, last four entries starting with Iczelion.