Revision history for KeyPgAsm


Revision [21664]

Last edited on 2016-11-06 17:54:03 by fxm [Formatting]
Additions:



Revision [21626]

Edited on 2016-10-30 17:24:52 by fxm [Formatting]

No Differences

Revision [20823]

Edited on 2016-03-12 15:02:46 by fxm [Formatting]
Additions:














Revision [20053]

Edited on 2016-02-10 15:54:40 by DkLwikki [Update link format]
Additions:
The current ""FreeBASIC"" compiler currently only produces code for Intel [[x86|80x86]]-based machines; however, in the future, the compiler might be ported to a platform which does not support the same instruction set. Therefore, ##**Asm**## blocks should only be used when necessary, and a ""FreeBASIC""-only alternative should be provided if possible.
The return value of a function may be set by using the ##[[KeyPgFunction|Function]]## keyword within brackets as shown in the example below.
##**Asm**## block comments have the same syntax as usual ""FreeBASIC"" [[KeyPgRem|comments]] - use ""FreeBASIC""-like " ##'## " comments, not " ##;## " as usual in assembly code.
~- [[http://board.flatassembler.net/download.php?id=3093|Original Intel 80386 manual from 1986]]
~- [[http://developer.intel.com/design/Pentium4/documentation.htm|Latest Intel Pentium 4 manuals]]
~- [[http://home.comcast.net/~fbkotler/nasmdocb.html|NASM x86 Instruction Reference]] (Please note that NASM is not the assembler used by ""FreeBASIC"", but this page provides a good overview of x86 instructions)
- The error lines returned by FBC for ##**Asm**## blocks are not related the FB source file. As FBC simply displays the errors returned by AS , the lines are related to the assembly file. To make ""FreeBASIC"" preserve them, the compiler must be invoked with the //[[CompilerOptrupp|-R]]// option ("don't delete ASM files").
- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Asm""**##.
- ##[[KeyPgFunction|Function]]##
- ##[[KeyPgNaked|Naked]]##
Deletions:
The current ""FreeBASIC"" compiler currently only produces code for Intel [[x86 80x86]]-based machines; however, in the future, the compiler might be ported to a platform which does not support the same instruction set. Therefore, ##**Asm**## blocks should only be used when necessary, and a ""FreeBASIC""-only alternative should be provided if possible.
The return value of a function may be set by using the ##[[KeyPgFunction Function]]## keyword within brackets as shown in the example below.
##**Asm**## block comments have the same syntax as usual ""FreeBASIC"" [[KeyPgRem comments]] - use ""FreeBASIC""-like " ##'## " comments, not " ##;## " as usual in assembly code.
~- [[http://board.flatassembler.net/download.php?id=3093 Original Intel 80386 manual from 1986]]
~- [[http://developer.intel.com/design/Pentium4/documentation.htm Latest Intel Pentium 4 manuals]]
~- [[http://home.comcast.net/~fbkotler/nasmdocb.html NASM x86 Instruction Reference]] (Please note that NASM is not the assembler used by ""FreeBASIC"", but this page provides a good overview of x86 instructions)
- The error lines returned by FBC for ##**Asm**## blocks are not related the FB source file. As FBC simply displays the errors returned by AS , the lines are related to the assembly file. To make ""FreeBASIC"" preserve them, the compiler must be invoked with the //[[CompilerOptrupp -R]]// option ("don't delete ASM files").
- Not available in the //[[CompilerOptlang -lang qb]]// dialect unless referenced with the alias ##**""__Asm""**##.
- ##[[KeyPgFunction Function]]##
- ##[[KeyPgNaked Naked]]##


Revision [17831]

Edited on 2015-10-17 11:37:33 by CountingPine [Use Long instead of Integer, rename 'blah' to 'n']
Additions:
' Assuming "n" is a FB global or local ULONG variable
mov eax, [n] ' OK: size is apparent from eax
inc [n] ' Not OK: size is not given
inc dword [n] ' Not OK: size given, but still not accepted by GAS
inc dword ptr [n] ' OK: "ptr" is needed by GAS here%%
Function AddFive(ByVal num As Long) As Long
Dim i As Long = 4
Deletions:
' Assuming "blah" is a FB global or local UINTEGER variable
mov eax, [blah] ' OK: size is apparent from eax
inc [blah] ' Not OK: size is not given
inc dword [blah] ' Not OK: size given, but still not accepted by GAS
inc dword ptr [blah] ' OK: "ptr" is needed by GAS here%%
Function AddFive(ByVal num As Integer) As Integer
Dim i As Integer = 4


Revision [17290]

Edited on 2014-09-23 14:41:58 by CountingPine [Link to KeyPgNaked]
Additions:
- ##[[KeyPgNaked Naked]]##


Revision [15864]

Edited on 2012-01-26 18:58:07 by CountingPine [Formatting]
Additions:
The ##**Asm**## block is used to insert specific machine-code instructions in a program in order to perform operations that cannot be carried out using the features of the language or to hand-optimize performance-sensitive sections of code.
The current ""FreeBASIC"" compiler currently only produces code for Intel [[x86 80x86]]-based machines; however, in the future, the compiler might be ported to a platform which does not support the same instruction set. Therefore, ##**Asm**## blocks should only be used when necessary, and a ""FreeBASIC""-only alternative should be provided if possible.
##**Asm**## block comments have the same syntax as usual ""FreeBASIC"" [[KeyPgRem comments]] - use ""FreeBASIC""-like " ##'## " comments, not " ##;## " as usual in assembly code.
The syntax of the inline assembler is a simplified form of Intel syntax. Intel syntax is used by the majority of x86 assemblers, such as MASM, TASM, NASM, YASM and FASM. In general, the destination of an instruction is placed first, followed by the source. Variables and functions defined by a program may be referenced in an ##**Asm**## block. The assembler used by ""FreeBASIC"" is GAS, using the ##.intel_syntax noprefix## directive, and ##**Asm**## blocks are passed through unmodified, except for the substitution of local variable names for stack frame references, and commenting removal.
Instruction syntax is mostly the same as FASM uses, one important difference is that GAS requires size settings to be followed by the word "##ptr##".
When an ##**Asm**## block is opened, the registers ##ebx##, ##esi##, and ##edi## are pushed to the stack, when the block is closed, these registers are popped back from the stack. This is because these registers are required to be preserved by most or all OS's using the x86 CPU. You can therefore use these registers without explicitly preserving them yourself. You should not change ##esp## and ##ebp##, since they are usually used to address local variables.
~The names of the registers for the x86 architecture are written as follows in an ##**Asm**## block:
The segment registers (##cs##, ##ds##, ##es##, ##fs##, ##gs##) should not be changed from an ##**Asm**## block, except in certain cases with the DOS port (note that they do NOT work the same way as in real-mode DOS, see also [[FaqDOS]]). The operating system or DPMI host is responsible for memory management; the meaning of segments (selectors) in protected mode is very different from real-mode memory addressing.
- The error lines returned by FBC for ##**Asm**## blocks are not related the FB source file. As FBC simply displays the errors returned by AS , the lines are related to the assembly file. To make ""FreeBASIC"" preserve them, the compiler must be invoked with the //[[CompilerOptrupp -R]]// option ("don't delete ASM files").
- The label names are case sensitive inside ##**Asm**## blocks.
Deletions:
The ##Asm## block is used to insert specific machine-code instructions in a program in order to perform operations that cannot be carried out using the features of the language or to hand-optimize performance-sensitive sections of code.
The current ""FreeBASIC"" compiler currently only produces code for Intel [[x86 80x86]]-based machines; however, in the future, the compiler might be ported to a platform which does not support the same instruction set. Therefore, ##Asm## blocks should only be used when necessary, and a ""FreeBASIC""-only alternative should be provided if possible.
##Asm## block comments have the same syntax as usual ""FreeBASIC"" [[KeyPgRem comments]] - use ""FreeBASIC""-like " ##'## " comments, not " ##;## " as usual in ASM.
The syntax of the inline assembler is a simplified form of Intel syntax. Intel syntax is used by the majority of x86 assemblers, such as MASM, TASM, NASM, YASM and FASM. In general, the destination of an instruction is placed first, followed by the source. Variables and functions defined by a program may be referenced in an Asm block. The assembler used by ""FreeBASIC"" is GAS, using the ##.intel_syntax noprefix## directive, and ASM blocks are passed through unmodified, except for the substitution of local variable names for stack frame references, and commenting removal.
Instruction syntax is mostly the same as FASM uses, one important difference is that GAS requires size settings to be followed by the word "ptr".
When an ASM block is opened, the registers ##ebx##, ##esi##, and ##edi## are pushed to the stack, when the block is closed, these registers are popped back from the stack. This is because these registers are required to be preserved by most or all OS's using the x86 CPU. You can therefore use these registers without explicitly preserving them yourself. You should not change ##esp## and ##ebp##, since they are usually used to address local variables.
~The names of the registers for the x86 architecture are written as follows in an ##Asm## block:
The segment registers (##cs##, ##ds##, ##es##, ##fs##, ##gs##) should not be changed from an ##Asm## block, except in certain cases with the DOS port (note that they do NOT work the same way as in real-mode DOS, see also [[FaqDOS]]). The operating system or DPMI host is responsible for memory management; the meaning of segments (selectors) in protected mode is very different from real-mode memory addressing.
- The error lines returned by FBC for ASM blocks are not related the FB source file. As FBC simply displays the errors returned by AS , the lines are related to the assembly file. To make ""FreeBASIC"" preserve them, the compiler must be invoked with the //[[CompilerOptrupp -R]]// option ("don't delete ASM files").
- The label names are case sensitive inside ASM blocks.


Revision [14762]

Edited on 2010-08-10 17:34:36 by DkLwikki [Formatting]
Additions:
==x86 Specific:==

inc dword ptr [blah] ' OK: "ptr" is needed by GAS here%%
Deletions:
==x86 x86 Specific:==
inc dword ptr [blah] ' OK: "ptr" is needed by GAS here


Revision [14077]

Edited on 2009-01-06 06:05:27 by CountingPine [Formatting, minor changes]
Additions:
The current ""FreeBASIC"" compiler currently only produces code for Intel [[x86 80x86]]-based machines; however, in the future, the compiler might be ported to a platform which does not support the same instruction set. Therefore, ##Asm## blocks should only be used when necessary, and a ""FreeBASIC""-only alternative should be provided if possible.
##Asm## block comments have the same syntax as usual ""FreeBASIC"" [[KeyPgRem comments]] - use ""FreeBASIC""-like " ##'## " comments, not " ##;## " as usual in ASM.
==x86 x86 Specific:==
The syntax of the inline assembler is a simplified form of Intel syntax. Intel syntax is used by the majority of x86 assemblers, such as MASM, TASM, NASM, YASM and FASM. In general, the destination of an instruction is placed first, followed by the source. Variables and functions defined by a program may be referenced in an Asm block. The assembler used by ""FreeBASIC"" is GAS, using the ##.intel_syntax noprefix## directive, and ASM blocks are passed through unmodified, except for the substitution of local variable names for stack frame references, and commenting removal.
%%(freebasic)
' Assuming "blah" is a FB global or local UINTEGER variable
mov eax, [blah] ' OK: size is apparent from eax
inc [blah] ' Not OK: size is not given
inc dword [blah] ' Not OK: size given, but still not accepted by GAS
inc dword ptr [blah] ' OK: "ptr" is needed by GAS here
~- [[http://home.comcast.net/~fbkotler/nasmdocb.html NASM x86 Instruction Reference]] (Please note that NASM is not the assembler used by ""FreeBASIC"", but this page provides a good overview of x86 instructions)
~Note that the ""FreeBASIC"" compiler produces 32-bit protected-mode code for the x86 which usually runs in an unprivileged user level; therefore, privileged and sensitive instructions will assemble fine, but possibly won't work correctly or cause a runtime "General Protection Fault", "Illegal instruction", or SIGILL error. The following are the privileged and sensitive instructions as of the Intel Pentium 4 and Xeon:
The privileged instructions will work "correctly" in DOS when running on a Ring 0 DPMI kernel, like the (non-default) Ring 0 version of CWSDPMI, WDOSX or D3X, nevertheless most of them are not really useful and dangerous when executed from DPMI code. RDTSC (Read Time Stamp Counter) has been shown to be allowed by most, or all OS'es.
However the usefulness of RDTSC has been diminished with the advent of multi-core and hibernating CPUs. SSE2 and higher instructions are disabled "by default" after CPU initialization, Windows and Linux usually do enable them, in DOS it is business of the DPMI host: HDPMI32 will enable them, CWSDPMI won't. The INT instruction is usable in the DOS version/target only, note that it works slightly differently from real mode DOS, see also [[FaqDOS]].
The segment registers (##cs##, ##ds##, ##es##, ##fs##, ##gs##) should not be changed from an ##Asm## block, except in certain cases with the DOS port (note that they do NOT work the same way as in real-mode DOS, see also [[FaqDOS]]). The operating system or DPMI host is responsible for memory management; the meaning of segments (selectors) in protected mode is very different from real-mode memory addressing.
Note that those "unsafe" instructions are not guaranteed to raise a "visible" crash even when ran with insufficient privilege - the OS or DPMI host can decide to "emulate" them, either functionally (reading from some CRx works under HDPMI32), or "dummy" (nothing happens, instruction will pass silently, like a NOP).
""FreeBASIC""'s Assembler is AS / GAS, the assembler of GCC, so an external program. Some quirks apply:
- The error lines returned by FBC for ASM blocks are not related the FB source file. As FBC simply displays the errors returned by AS , the lines are related to the assembly file. To make ""FreeBASIC"" preserve them, the compiler must be invoked with the //[[CompilerOptrupp -R]]// option ("don't delete ASM files").
- New to ""FreeBASIC""
Deletions:
The current FreeBASIC compiler currently only produces code for Intel 80x86-based machines; however, in the future, the compiler might be ported to a platform which does not support the same instruction set. Therefore, ##Asm## blocks should only be used when necessary, and a FreeBASIC-only alternative should be provided if possible.
##Asm## block comments have the same syntax as usual ""FreeBASIC"" [[KeyPgRem comments]] - use FreeBASIC-like " ' " comments, not " ; " as usual in ASM.
[[x86 x86]] Specific:
The syntax of the inline assembler is a simplified form of Intel syntax. Intel syntax is used by the majority of x86 assemblers, such as MASM, TASM, NASM, YASM and FASM. In general, the destination of an instruction is placed first, followed by the source. Variables and functions defined by a program may be referenced in an Asm block. The assembler used by FreeBASIC is GAS, using the ##.intel_syntax noprefix## directive, and ASM blocks are passed through unmodified, except for the substitution of local variable names for stack frame references, and commenting removal.
## ' Assuming "blah" is a FB global or local UINTEGER variable ##
## mov eax,[blah] ' Fine, size obvious ##
## inc [blah] ' Bad, size not specified ##
## inc dword [blah] ' All said, but GAS still won't accept this ##
## inc dword ptr [blah] ' GAS needs "ptr" here ##
~- [[http://home.comcast.net/~fbkotler/nasmdocb.html NASM x86 Instruction Reference]] (Please note that NASM is not the assembler used by FreeBASIC, but this page provides a good overview of x86 instructions)
~Note that the FreeBASIC compiler produces 32-bit protected-mode code for the x86 which usually runs in an unprivileged user level; therefore, privileged and sensitive instructions will assemble fine, but possibly won't work correctly or cause a runtime "General Protection Fault", "Illegal instruction", or SIGILL error. The following are the privileged and sensitive instructions as of the Intel Pentium 4 and Xeon:
The privileged instructions will work "correctly" in DOS when running on a Ring 0 DPMI kernel, like the (non-default) Ring 0 version of CWSDPMI, WDOSX or D3X, nevertheless most of them are not really useful and dangerous when executed from DPMI code. RDTSC (Read Time Stamp Counter) has been shown to be allowed by most, or all OS'es. However the usefulness of RDTSC has been diminished with the advent of multi-core and hibernating CPUs. SSE2 and higher instructions are disabled "by default" after CPU initialization, Windows and Linux usually do enable them, in DOS it is business of the DPMI host: HDPMI32 will enable them, CWSDPMI won't. The INT instruction is usable in the DOS version/target only, note that it works slightly differently from real mode DOS, see also [[FaqDOS]]. The segment registers (##cs##, ##ds##, ##es##, ##fs##, ##gs##) should not be changed from an ##Asm## block, except in certain cases with the DOS port (note that they do NOT work the same way as in real-mode DOS, see also [[FaqDOS]]). The operating system or DPMI host is responsible for memory management; the meaning of segments (selectors) in protected mode is very different from real-mode memory addressing. Note that those "unsafe" instructions are not guaranteed to raise a "visible" crash even when ran with insufficient privilege - the OS or DPMI host can decide to "emulate" them, either functionally (reading from some CRx works under HDPMI32), or "dummy" (nothing happens, instruction will pass silently, like a NOP).
FreeBASIC's Assembler is AS / GAS, the assembler of GCC, so an external program. Some quirks apply:
- The error lines returned by FBC for ASM blocks are not related the FB source file. As FBC simply displays the errors returned by AS , the lines are related to the assembly file. To make FreeBASIC preserve them, the compiler must be invoked with the //[[CompilerOptrupp -R]]// option ("don't delete ASM files").
- New to FreeBASIC


Revision [13531]

The oldest known version of this page was created on 2008-07-17 05:39:11 by DoS386 [Formatting, minor changes]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode