flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > Fun with CPP - APP (Assembly language PreProcessor) |
Author |
|
revolution 23 Mar 2016, 23:40
Interesting.
But, umm, why would I want to run NASM when I already have FASM? |
|||
23 Mar 2016, 23:40 |
|
Mike Gonta 23 Mar 2016, 23:59
revolution wrote: Interesting. Mike Gonta wrote: (try both to confirm that this does indeed work or have a look at the *.2 file which is sent to the assembler) I have FASM and I also have NASM, but I prefer FASM. It's simply a matter of writing one set of assembly language files that will assemble on both FASM and NASM and probably some other intel syntax assemblers (but not MASM or GAS). |
|||
23 Mar 2016, 23:59 |
|
Mike Gonta 24 Mar 2016, 00:06
Here's a self preprocessing, self assembling "Hello World!" Windows command script.
Make a folder and place the script in it. Edit the "path" command in the script or make additional folders to contain the programs needed. FASM, the CPP (in this case cpp.exe and cc1.exe from GCC) and QEMU (BOCHS won't emulate a 512 byte hard drive). The "hello.inc" file is also required. This file is #include"(d) by and contains the "#define" used in the "hello.cmd" file. hello.cmd Code: ; @echo off ; set current_path=%~p0 ; path=%current_path%;%current_path%cpp;%current_path%fasm;%current_path%nasm;%current_path%qemu;%path% ;:: for some linux reason cpp needs to be told where it is ; if exist %~n0.2 del %~n0.2 ; cpp.exe %0 > %~n0.1 ;:: pre-process cpp to get rid of cpp comments that begin ;:: with "#" ; for /f "delims=" %%a in (%~n0.1) do ( ; set AA=%%a ; setlocal enabledelayedexpansion ; if not "!AA:~0,1!"=="#" ( ; echo !AA! >> %~n0.2 ; ) ; @endlocal ; ) ; del %~n0.1 ;:: uncomment your assembler of choice and fix up the ;:: command line for your format if not "bin" ; fasm %~n0.2 ;rem nasm %~n0.2 -o %~n0.bin ; del %~n0.2 ; pause ; start %current_path%qemu\qemu -L %current_path%qemu\ -name "Assembly language PreProcessor" -m 1000 -localtime -hda %~n0.bin -display sdl ; goto finish /*************************************** this is a simple Hello World! example ***************************************/ org 0x7C00 start: #include "hello.inc" xor ax, ax mov ds, ax mov si, hello mov ah, 0xE xor bx, bx .1: lodsb test al, al je $ int 0x10 jmp .1 hello db HELLO times 510-($-$$) db 0 dw 0xAA55 ;:finish Code: #define HELLO "Hello Assembly Language PreProcessor World!",0 Code: org 0x7C00 start: xor ax, ax mov ds, ax mov si, hello mov ah, 0xE xor bx, bx .1: lodsb test al, al je $ int 0x10 jmp .1 hello db "Hello Assembly Language PreProcessor World!",0 times 510-($-$$) db 0 dw 0xAA55 Last edited by Mike Gonta on 24 Mar 2016, 15:16; edited 1 time in total |
|||
24 Mar 2016, 00:06 |
|
revolution 24 Mar 2016, 00:37
Mike Gonta wrote: And you don't need to run NASM. Mike Gonta wrote: (but not MASM or GAS). So all I need is fasm, right? But perhaps this is more useful for someone who mixes C/C++ with fasm? |
|||
24 Mar 2016, 00:37 |
|
Mike Gonta 24 Mar 2016, 00:54
revolution wrote: So all I need is fasm, right? Code: org 0x7C00 start: include "hello.inc" xor ax, ax mov ds, ax mov si, hello mov ah, 0xE xor bx, bx .1: lodsb test al, al je $ int 0x10 jmp .1 hello db HELLO times 510-($-$$) db 0 dw 0xAA55 Code: org 0x7C00 start: %include "hello.inc" xor ax, ax mov ds, ax mov si, hello mov ah, 0xE xor bx, bx .1: lodsb test al, al je $ int 0x10 jmp .1 hello db HELLO times 510-($-$$) db 0 dw 0xAA55 This will assemble on both after preprocessing with CPP: Code: /*************************************** this is a simple Hello World! example ***************************************/ org 0x7C00 start: #include "hello.inc" xor ax, ax mov ds, ax mov si, hello mov ah, 0xE xor bx, bx .1: lodsb test al, al je $ int 0x10 jmp .1 hello db HELLO times 510-($-$$) db 0 dw 0xAA55 Last edited by Mike Gonta on 24 Mar 2016, 15:15; edited 1 time in total |
|||
24 Mar 2016, 00:54 |
|
revolution 24 Mar 2016, 01:32
Okay, further to this, how does this handle macro blocks? Postpone? Format? Register arithmetic?
|
|||
24 Mar 2016, 01:32 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.