flat assembler
Message board for the users of flat assembler.
Index
> Programming Language Design > On my new assembler Goto page Previous 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Next |
Author |
|
Tomasz Grysztar 28 Mar 2015, 18:41
I have updated the package once again - I decided to switch to version number based on the timestamp.
|
|||
28 Mar 2015, 18:41 |
|
JohnFound 28 Mar 2015, 19:41
Tomasz Grysztar wrote: I have updated the package once again - I decided to switch to version number based on the timestamp. Tomasz, do you use some version control system? If so, have you thought about publishing the repository? The chance to follow the creation of something good is really interesting and useful. _________________ Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9 |
|||
28 Mar 2015, 19:41 |
|
Tomasz Grysztar 28 Mar 2015, 19:49
JohnFound wrote: Tomasz, do you use some version control system? If so, have you thought about publishing the repository? The chance to follow the creation of something good is really interesting and useful. |
|||
28 Mar 2015, 19:49 |
|
JohnFound 28 Mar 2015, 21:02
Tomasz Grysztar wrote: ... but after you recommended Fossil I decided to give it a try... That is why I asked. It is great, because if there is an existing repository, regardless of your decision in this very moment, there is always a hope it will be published later. _________________ Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9 |
|||
28 Mar 2015, 21:02 |
|
revolution 31 Mar 2015, 04:12
For this test program:
Code: shift = 35 x = (1 shl (1 shl shift)) + 1 display (y and 1) + '0' y = x shr (1 shl shift) display y + '0' Code: shift result memory-usage 30 11 ~500MB 31 11 ~1000MB 32 Error: not enough memory to complete the assembly. 33 Error: not enough memory to complete the assembly. 34 Error: not enough memory to complete the assembly. 35 02 ~0.5MB 36 Error: not enough memory to complete the assembly. I'm using "flat assembler g version 0.90.1427567760" |
|||
31 Mar 2015, 04:12 |
|
Tomasz Grysztar 31 Mar 2015, 12:52
I updated the package with a related correction.
|
|||
31 Mar 2015, 12:52 |
|
revolution 03 Apr 2015, 10:00
The .exe file in the 1427806225 download declares itself as "flat assembler g version 0.90.1427567760" but appears to have had the two small changes included. So it is a hybrid new version which pretends it is an older version.
|
|||
03 Apr 2015, 10:00 |
|
codestar 04 Apr 2015, 14:34
Tomasz: Thanks. Would you mind answering a few more questions? Whenever you have time:
Quote: * No format? Is there a way to specify .EXT in source? Code: macro push? sequence local seq define seq sequence while 1 match car= cdr, seq push car redefine seq cdr else push seq break end match end while end macro |
|||
04 Apr 2015, 14:34 |
|
codestar 05 Apr 2015, 17:31
My first try at FASMG. Adam CPU: Assembler + disassembler.
Code: ; ADAM DISASSEMBLER: EXAMPLE.BIN 00000000 $003F nop 00000002 $AA87 go +$00000010 00000004 $0001 mov a1, a2 00000006 $0023 mov ip, a4 00000008 $002E mov bp, sp 0000000A $0800 mov a1, $00000000 0000000C $0805 mov a2, $00000001 0000000E $080B mov a3, $00000004 00000010 $A088 go e, +$00000020 00000012 $0601 mov4 *a1, a2 00000014 $0108 mov1 a2, *a1 00000016 $0701 mov4 *a1, *a2 00000018 $0281 mov1 *a1++, a2 0000001A $0869 mov1 *a3++, $00000001 0000001C $0548 mov4 a2, *a1++ 0000001E $07C8 mov4 *a2++, *a1++ 00000020 $A18A go ne, +$00000034 00000022 $1341 cmp1 *a1, *a2++ 00000024 $2001 add a1, a2 00000026 $3201 sub1 *a1, a2 00000028 $4013 and a3, a4 0000002A $517B or1 sf, *a4++ 0000002C $6701 shl4 *a1, *a2 0000002E $7281 shr1 *a1++, a2 00000030 $8548 sar4 a2, *a1++ 00000032 $97C8 mul4 *a2++, *a1++ 00000034 $0903 mov a4, $00000ABC 00000036 $DABC $data 00000038 $09DB mov4 *a4++, $00CAFE77 0000003A $DCAF $data 0000003C $DE77 $data 0000003E $0A01 mov a1, (a2+$00000ABC) 00000040 $DABC $data 00000042 $0AD3 mov1 *a3, *(a4+$00000123) 00000044 $D123 $data 00000046 $AA09 go -$00000034 00000048 $AAC0 go +$00000ABC 0000004A $D53A $data
Last edited by codestar on 07 Apr 2015, 00:48; edited 3 times in total |
|||||||||||
05 Apr 2015, 17:31 |
|
Tomasz Grysztar 05 Apr 2015, 18:53
codestar wrote: * No format? Is there a way to specify .EXT in source? codestar wrote: * How to "if x eqtype 0"? Use "if x>=0 & x<=9"? codestar wrote: * How to "if x in <l,i,s,t>"? Use "while ... match x,"? Search with irp? codestar wrote: * How to process [group] arguments? codestar wrote: * Does FASMG have the capability to define a real compiler like C? Almost? C-ish? codestar wrote: * Are {}!? now like standard operators? +-*/ codestar wrote: * Example/s of "eval"? I wonder if this will be the solution to the problem of having to resolve partial constant expressions: r1+(W*H*4) = r1+N Code: a1 = 'A' a2 = 'B' a3 = 'C' x = 2 virtual at 0 db 'display a' db '0'+x load src : $ from 0 eval src end virtual codestar wrote: In 8086.inc, is this the manual equivalent of "forward push x"? Why "match car= cdr"? Next [x]? Then "else push seq"? Last? |
|||
05 Apr 2015, 18:53 |
|
codestar 09 Apr 2015, 01:32
Wrote some macros today: a[]={1,2,3}, foo(1,a2,&n,a7)
Code: ; process "group arguments" macro my p& ; forward irp x, p display x, ':' end irp end macro macro my_r p& ; reverse irp x, p indx 1+%%-% ; x=parameter[#] display x, ':' end irp end macro RET equ $D,$A display RET, '* Result: ' my 'A','B','C','D' my_r 'A','B','C','D' display RET ; enumerated constants macro enum p& local n n=0 irp x, p match a==b, x a=b n=b else match a, x a=n else err 'Name expected' end match n=n+1 end irp end macro enum BLACK, GRAY25,\ GRAY50, GRAY75, WHITE enum ZERO=0, ONE, TWO,\ FOUR=4, FIVE, SIX, SEVEN display '* Constants: ' display TWO+'0', '.', SEVEN+'0' display '.', WHITE+'0', RET, RET ; create integer variable/s macro int p& irp x, p match a==i, x display `a, ': dd ', `i else match a, x display `a, ': dd 0' end match display RET end irp end macro macro test_int p& display '* Variables: ' display `p, RET, RET int p end macro test_int i=7, x, y='Z', n=$CAFEBABE display RET ; create integer array ; inta array1[8] ; inta array2[]={1,2,3} macro inta p& match a[]=={i}, p display `a, ': dd ', `i else match a[n], p display `a, ': rd ', `n else err 'Syntax' end match display RET end macro macro test_inta p& display '* Array: ' display `p, RET, RET inta p display RET end macro test_inta array1[8] test_inta array2[]={1,2,3} ; high-level "call f(...)" macro hl_call p& match name(ps), p irp x, ps indx 1+%%-% ; x=ps[#] match &a, x display 'lea a7, ', `a, RET display 'push a7', RET else match a, x display 'push ', `a, RET end match end irp display 'call ', `name, RET end match end macro macro test_call p& display '* Call function: ' display `p, RET, RET hl_call p end macro test_call foo(1,2,3,i,&v,a1,a2) |
|||
09 Apr 2015, 01:32 |
|
codestar 04 May 2015, 14:28
New: Toy Macro Language. Untested.
Code: ; EXAMPLE include 'toy' asm 'jmp main' int i=7, n='Z', j=$CAFEBABE int array[2] class POINT int x, y endc POINT point function foo let eax=point.x, eax+point.y, eax*n endf function rgb, r, g, b let eax=r, eax<<16,\ ecx=g, ecx<<8, eax|ecx, eax|b endf asm 'main:' foo rgb $AA, $BB, $CC Code: ;;;;;;;;;;;;;;;;;;;; FUNCTION ;;;;;;;;;;;;;;;;;;;; its_name equ 0 its_parameters equ 0 its_locals equ 0 n_parameters=0 parameters_size=0 n_locals=0 locals_size=0 macro function name, p& local n n=0 match =0, its_name its_name equ name its_parameters equ p else err 'endf expected' end match n=0 match any, p irp x, p n=n+1 end irp end match n_parameters=n parameters_size=n*4 @#name: asm `name, ':' macro name q& n=0 irp x, q n=n+1 end irp if n>1 if n<>n_parameters display `name, ': ' display 'Invalid # parameters', RET err '' end if irp x, q ; pushr... indx 1+%%-% ; x=q[#] asm 'push ', `x end irp end if asm 'call ', `name ; call f end macro if n_parameters asm 'push ebp' ; db $55 asm 'mov ebp, esp' ; db $89, $E5 n=8 irp x, q ; parameter x equ [ebp+n] ; names n=n+4 end irp end if scope='f' end macro macro return v& match any, v asm 'mov eax, ', `v end match if n_parameters \ | n_locals asm 'mov esp, ebp' ; db $89, $EC asm 'pop ebp' ; db $5D end if if n_parameters asm 'ret n' ; db $C2, dw n else asm 'ret' ; db $C3 end if end macro macro endf! v& return v restore its_name irp x, its_parameters restore x end irp scope=0 end macro
|
|||||||||||
04 May 2015, 14:28 |
|
codestar 04 May 2015, 22:25
Write PE executable + imports. Standalone .EXE, 1K.
Code: ; EXAMPLE: WRITE EXECUTABLE @rva equ ($1000-$200) @base equ ($400000+@rva) macro align n db ((n-1)-($+n-1) mod n) dup(0) end macro ; example assembler eax=0 ecx=1 edx=2 ebx=3 macro int3 db $CC end macro macro push_r r db $50+r end macro macro push_i i if i<=$FF db $6A, i else db $68 dd i end if end macro macro mov_r32_i r, i db $B8+r dd i end macro macro call_p a db $FF, $15 dd @base+a end macro ; image size = (section rva+size) rounded to 1000h image_size_a =\ ((($1000+one_end-one) shr 12)+1) shl 12 macro write_exe dw 'MZ' db $3A dup(0) dd $40 db 'PE', 0, 0 ; signature dd $1014C, 0, 0, 0 ; cpu (.I386+), # sections, etc dd $10F00E0, $10B ; n/a dd 0, 0, 0 ; code/idata/data sizes dd $1000, 0, 0 ; entry, code/data offsets dd $400000 ; image base dd $1000, $200 ; alignment in memory/file dd 1, 0, 4, 0 ; versions dd image_size_a ; image size aligned dd $200, 0 ; section 1 offset dw 2, 0 ; subsystem dd $1000, $1000 ; stack/heap dd $1000, 0 ; reserve/commit dd 0, 16 ; flags, # directories dd 0, 0 ; data directories... dd it+@rva ; import table rva, size dd exe_end-it dq 14 dup(0) dq '.one' ; section dd exe_end-one_end ; size dd $1000 ; rva dd exe_end-$200 ; size rounded to 200h dd $200, 0, 0, 0 ; file offset, etc dd $0E0000020 ; attributes: readable, etc db $200-$ dup(0) ; proceed to 200h/1000h end macro macro library p& irp x, p dd 0,0,0, @rva+x#_name, @rva+x#_table end irp dd 0,0,0,0,0 end macro macro import name, p& name#_name db \ ; text DLL_name='NAME.DLL' `name, '.DLL', 0 name#_table: ; DLL_table: irp x, p x dd @rva+_#x ; import name RVAs end irp dd 0 ; end irp x, p _#x dw 0 ; import names db `x, 0 ; 'import' end irp end macro exe: write_exe one: mov_r32_i eax, @base+.a push_i 0 push_r eax push_r eax push_i 0 call_p MessageBoxA push_i 0 call_p ExitProcess .a: db 'Windows Example for FASMG', 0 align 16 it: library KERNEL32, USER32 import KERNEL32, ExitProcess import USER32, MessageBoxA one_end: align $200 exe_end: |
|||
04 May 2015, 22:25 |
|
codestar 06 May 2015, 15:31
Intel32 Examples:
One-Byte Instructions Code: irp <name,value>,\ cbw,$98, clc,$F8, cld,$FC, cli,$FA,\ cmc,$F5, cmpsb,$A6, cmpsd,$A7, cwd,$99,\ hlt,$F4, int3,$CC, lodsb,$AC, lodsd,$DC,\ movsb,$A4, movsd,$A5, popf,$9D, pushf,$9C,\ sahf,$9E, scasb,$AE, scasd,$AF, stc,$F9,\ std,$FD, sti,$FB, stosb,$AA, stosd,$AB,\ xlat,$D7 macro name db value end macro end irp irp <name,value>,\ aso,$67, lock,$F0, nop,$90, oso,$66,\ rep,$F3, repne,$F2, wait,$9B macro name p& db value match next, p next end match end macro end irp Code: irp <name,o>,\ jo,$70, jno,$71, jc,$72, jb,$72,\ jnae,$72, jnc,$73, jnb,$73, jae,$73,\ jz,$74, je,$74, jnz,$75, jne,$75,\ jna,$76, jbe,$76, ja,$77, jnbe,$77,\ js,$78, jns,$79, jp,$7A, jpe,$7A,\ jnp,$7B, jpo,$7B, jl,$7C, jnge,$7C,\ jnl,$7D, jge,$7D, jng,$7E, jle,$7E,\ jg,$7F, jnle,$7F macro name i if i<$80 & i>=-$80 db o, (i-$-1) else db $0F, (o+$10) dd (i-$-4) end if end macro end irp Code: numeric al, cl, dl, bl, ah, ch, dh, bh numeric ax, cx, dx, bx, sp, bp, si, di numeric eax, ecx, edx, ebx, esp, ebp, esi, edi macro is_in is, x, p& is=0 irp q, p match =x, q is=1 break end match end irp end macro macro if_is x, p& local is is=0 is_in is, x, p esc if is end macro macro is_r is, x is=0 if_is x,\ al, cl, dl, bl,\ ah, ch, dh, bh is='1' else if_is x,\ ax, cx, dx, bx,\ sp, bp, si, di is='2' else if_is x,\ eax, ecx, edx, ebx,\ esp, ebp, esi, edi is='4' end if end if end if end macro Code: element register element r8 : register+1 element r16 : register+2 element r32 : register+3 element eax : r32+0 element ecx : r32+1 element edx : r32+2 ; ... if x is register ; ... end if Idea: Extension of `, s/printf style asm 'add eax, ' # ...: Something like this? Code: `x ; quote ``x ; dequote `+x ; uppercase `-x ; lowercase `x%d ; decimal `x%h ; hexadecimal `x%b ; binary `x%d=2 ; alignment... `x%h=8 `x%b=4 Code: asm 'add eax, ' # `n%d asm 'mov al, ' # `n%h=2 # 'h' asm 'and cx, ' # `n%b=16 # 'b' An asm keyword could set current format: Code: format asm file ; write to file (db) format asm display ; write to console format asm virtual p: ; write to memory (p::) |
|||
06 May 2015, 15:31 |
|
Tomasz Grysztar 15 May 2015, 11:37
codestar wrote: Should I use the new "element" keyword for this? I would think it would be faster than searching lists. |
|||
15 May 2015, 11:37 |
|
codestar 23 May 2015, 16:07
I've been having fun with FASMG lately. Easy to use, definitely an improvement of FASM1.
Quote: I feel that this project, though a fun thing to play with, consumed way too much of my time recently, a time that maybe would be better spent on implementing AVX512 into fasm Code: ; inc rm8 ; $FE /0 ; inc r32 ; oso $40+r ; inc rm32 ; oso $FF /0 define_opcode_1 inc, 1,\ rmb=<$FE,/0>, rx=<o,$40+r>, rmx=<o,$FF,/0> |
|||
23 May 2015, 16:07 |
|
MIHIP 23 May 2015, 18:27
Hey, Tomasz, you are no longer work at new version of flat assembler? You work at fasm 2.0? Yes?
|
|||
23 May 2015, 18:27 |
|
codestar 23 May 2015, 23:13
MIHIP: FASM1 is nothing compared to FASMG
Quote: Please use element For now, my method of searching names works, takes .1 second to compile EXAMPLE.EXE on my MiniX Z64. Notice the optimization: name_length name, n | if n=3. If the name is not exact size, it will not search. All names which are 1 or 4+ characters will be skipped. Code: macro name_length name, n virtual at 0 db `name n=$ end virtual end macro name_length name, n if n<>length ; do nothing end if Last edited by codestar on 26 May 2015, 07:45; edited 1 time in total |
|||
23 May 2015, 23:13 |
|
shutdownall 24 May 2015, 12:07
Congratulations, Tomasz.
Finally you did it, release a first version of fasm g which makes a stone rolling. Your concept is interesting but the main purpose of assemblers are creating binaries using an instruction set for a specific target processor. Theretically nearly all could be done with macros but with the price of a bad performance and a more or less hard work creating the macros for a specific target. So - just a proposal to think about: Wouldn't it be interesting to develop a kind of "instruction definition language" as a specific macro language but with some focus of most used types of statements (instruction, register, address space, size like byte/word/dword/qword) which can be handled faster than interpretation of general purpose macros AND are more easy to define by users ? As I did implement the Z80 instructions and I think revolution (?) for the ARM processor and you for the main x86 target, wouldn't it be helpful to have an (more or less) easy to use assembly engine which can be adapted to nearly any new processor or microcontroller with minimal work ? So only some basic definitions - if there are instructions to complex they can be generated with the all purpose macro language as well. This attempt would offer maybe a better speed (at least for the most used instructions) and a wide range of available targets for assembly. The less work necessary for implementing a new target, the more targets you will have at the end for FASM G. I think the reason why you develop this way is, that you doubt there won't be too much assembly programming for x86 systems in the future and the range of upcoming new cpu's, microcontrollers and so on maybe more interesting. This would be a nice project. Maybe a quite different project than FASM G - but maybe not too much. |
|||
24 May 2015, 12:07 |
|
Goto page Previous 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.