flat assembler
Message board for the users of flat assembler.
Index
> Projects and Ideas > Programmes and Examples for fasm Goto page 1, 2, 3, 4 Next |
Author |
|
ssp 23 Apr 2007, 16:02
Hi Brother! i m just posting here to let you know i can access this msg board from my mobile
|
|||
23 Apr 2007, 16:02 |
|
Dex4u 23 Apr 2007, 18:28
What type of examples ?, do you mean, simple fasm code snips ?, like a 265 byte AI game ?
Code: ; small AI game demo, compile with fasm.; Original written by Luks, for nasm.; c:\fasm game.asm game.comorg 0x100use16START:mov al,0x13int 0x10MAIN:push word 0x8000pop espush cspop dsmov cx,0xFFFFmov al,0rep stosbmov si,BALLYIcall PutLinemov bx,[si-6]mov dx,[si-4]cmp dx,195jb CMPYjmp NEGYCMPY:cmp dx,1jg ADDYNEGY:neg word[si]ADDY:add dx,[si]dec sidec sicmp bx,310jb CMPXjmp NEGXCMPX:cmp bx,6jg ADDXNEGX:neg word[si]ADDX:add bx,[si]sub si,8mov di,dximul di,320add di,bxmov cl,4BALL:mov [es:di], dword 0x0f0f0f0fadd di,320loop BALLmov [si+4],bxmov [si+6],dx; PADSmov bp,sicmp [si+9],byte 0je PAD2PAD1:call PADCHKjmp PADSPAD2:add bp,2call PADCHKPADS:mov ax,[si]mov di,2call DRAWPADmov ax,[si+2]mov di,314call DRAWPADpush espop dspush word 0xA000pop esmov cx,32000xor si,simov di,sirep movswmov ah,0x11int 0x16jz MAINmov ax,0x0003int 0x10DRAWPAD:imul ax,320add di,axmov cx,16PAD:mov [es:di], dword 0x0f0f0f0fadd di,320loop PADretPADCHK:cmp dx,[bp]jge PADDOWNdec word [bp]jmp ENDCHKPADDOWN:sub dx,12cmp dx,[bp]jbe ENDCHKinc word [bp]ENDCHK:retPutLine:mov al,15mov di,158mov cl,198@@:add di,319stosbloop @bxor di,dicall Hlinexor dx,dxxor di,dimov cl,199Gridlp3:stosbadd di,318stosbloop Gridlp3call Hlineret Hline:mov al,15mov cx,320rep stosbretPAD1Y dw 100PAD2Y dw 100BALLX dw 160BALLY dw 100BALLXI dw -1BALLYI dw -1 Last edited by Dex4u on 13 Jun 2007, 15:40; edited 2 times in total |
|||
23 Apr 2007, 18:28 |
|
vid 23 Apr 2007, 20:50
cool! you wrote it?
|
|||
23 Apr 2007, 20:50 |
|
Dex4u 23 Apr 2007, 23:48
No, i converted it to fasm, about 3 years ago, from tasm, i think.
I lost the original code. I have lots of code snips like this for fasm, mostly mine, but some converted, on old backup cd's, i may dig them out and post them. |
|||
23 Apr 2007, 23:48 |
|
YONG 24 Apr 2007, 12:28
Here is a .com game that I wrote almost two years ago for the 512b contest. Take a look at it.
Code: ;============================================================================= ; 1 2 3 4 5 6 7 ;23456789012345678901234567890123456789012345678901234567890123456789012345678 ;============================================================================= ; ; NumGun.asm - NumberGun 1.0 ; Copyright (C) 2005. All Rights Reserved. YONG. ; ; Features: ; ; . Just one line of text: ; . SPACE:Hit F:- J:+ \ ; . Level:0 Hits:00 \ ; . #0>!000000000000000000# \ ; . F1:Reboot/F2:Quit F8:NewGame ; ; . Description of the key component: ; ; <----------- Direction of movement of the number sequence ; #7> 7C03D6F29A15# ; ^ ^ ^ ; | | | ; | | +-- The left-most number of the number sequence ; | | ; | +-- Game status: ' ', '!' or '*', where ' ' = game in progress ; | '!' = game over ; | '*' = victory ; +-- num, controlled by the player ; ; . Navigation: ; . SPACE = Hit : Destroy the left-most number of the number sequence ; provided that num matches this number ; . F = - : num = num - 1 (e.g., 3 => 2, 2 => 1, etc.) ; . J = + : num = num + 1 (e.g., 8 => 9, 9 => A, etc.) ; . F1 = Reboot (in "bootSector" version) ; . F2 = Quit (in "dotcom" and "called_by_loserOS" versions) ; . F8 = NewGame ; ; . Game Over: ; . '!' will be shown as soon as the number sequence reaches NumGun '0>'. ; ; . Victory: ; . Starting from 0, level will be raised for every 13 hits. ; . '*' will be shown as soon as level 9 is reached. ; ; . Notes: ; . As level is raised, delay will be reduced, i.e., the number sequence ; will speed up. ; ; . Requires: ; . VGA ; . 386+ ; bootSector = 0 ; As a bootsector program dotcom = 1 ; As a DOS .com program called_by_loserOS = 2 ; As a program running on loserOS ;version2compile = bootSector version2compile = dotcom ;version2compile = called_by_loserOS delay = 30 ; Initial value hitsPerLevel = 13 ; 2 - 99 victoryLevel = '9' ; '1' - '9' numSeqLEN = 18 stackSize = 512 RN_seed = 52763 tSs = ((80 * 1) + 1) * 2 FxdColour = 09h VarColour = 0fh TwrColour = 0ah GssColour = 0ch BlkColour = 00h gameOverChar = '!' victoryChar = '*' IF version2compile = bootSector org 7c00h END IF IF version2compile = dotcom org 0100h END IF use16 mov ax, cs mov ds, ax IF version2compile = bootSector mov ss, ax mov sp, stack_ptr END IF mov ax, 0b800h mov es, ax xor ax, ax mov fs, ax ; Set video mode ; ============== mov ax, 0003h ; 80x25 TEXT Mode int 10h mov ch, 20h ; No cursor mov ah, 01h int 10h ; Initial colour setup ; ==================== call PRINT_Txt xor cx, cx ; New game begins here ; ==================== begins_here: mov byte [delayVar], delay mov word [RN], RN_seed mov ax, word [fs:046ch] mov word [lastTick], ax mov ax, '00' mov byte [level], al mov byte [num], al mov word [hits], ax mov byte [hitCount], 0 mov al, ' ' mov si, numSeqLEN-1 init_nS_LP: mov byte [numSeq+si], al dec si jns init_nS_LP mov byte [gameStatus], al mov bp, numSeqLEN ; Update number sequence ; ====================== update_numSeq: dec bp js GameOver mov si, numSeq add si, bp unS_LP: cmp si, numSeq+numSeqLEN-1 jae unS_qLP mov al, byte [si+1] mov byte [si], al inc si jmp unS_LP unS_qLP: ; si points at the right-most char ; of numSeq mov bx, 17 tryAgain: xor dx, dx mov ax, word [fs:046ch] add word [RN], ax ror word [RN], 1 xor ax, word [RN] div bx ; dx:ax / bx ; ax = Q | dx = R < 17 mov al, dl cmp al, 16 je tryAgain ; al is between 0 and 15 cmp al, 10 jb LT_10 add al, 'A' - 10 - '0' LT_10: add al, '0' after_cmp: mov byte [si], al jmp unS_q GameOver: mov byte [gameStatus], gameOverChar unS_q: ; Print text ; ========== pTxt: call PRINT_Txt cmp byte [gameStatus], ' ' jne wait_for_key ; Delay ; ===== DelayLP: mov ah, 01h int 16h jnz Check_key mov ax, word [fs:046ch] sub ax, word [lastTick] cmp al, byte [delayVar] jb DelayLP add word [lastTick], ax jmp update_numSeq ; Check key ; ========= Check_key: xor ax, ax int 16h or al, al jz cmp_ah cmp al, 'a' jb skip_convert_a2A sub al, 20h ; 'a' => 'A', ..., 'z' => 'Z' skip_convert_a2A: cmp al, 'F' ; 'F' je F_KEY cmp al, 'J' ; 'J' je J_KEY cmp al, ' ' ; ' ' je SPACE_KEY jmp pTxt wait_for_key: ; Game status = game over or victory xor ax, ax int 16h or al, al jnz wait_for_key cmp_ah: xchg al, ah IF version2compile = bootSector cmp al, 3bh ; F1 je REBOOT END IF IF version2compile = dotcom cmp al, 3ch ; F2 je QUIT END IF IF version2compile = called_by_loserOS cmp al, 3ch ; F2 je QUIT END IF cmp al, 42h ; F8 je begins_here cmp byte [gameStatus], ' ' jne wait_for_key jmp pTxt ; F F_KEY: mov al, byte [num] cmp al, 'A' je dec_A cmp al, '0' je dec_0 dec al jmp FK_next dec_A: mov al, '9' jmp FK_next dec_0: mov al, 'F' FK_next: mov byte [num], al jmp pTxt ; J J_KEY: mov al, byte [num] cmp al, '9' je inc_9 cmp al, 'F' je inc_F inc al jmp JK_next inc_9: mov al, 'A' jmp JK_next inc_F: mov al, '0' JK_next: mov byte [num], al jmp pTxt ; SPACE SPACE_KEY: mov al, byte [ds:numSeq+bp] cmp al, byte [num] jne pTxt mov byte [ds:numSeq+bp], ' ' inc bp mov al, byte [hitCount] inc al cmp al, hitsPerLevel jb skip_raise_level xor al, al inc byte [level] sub byte [delayVar], 2 skip_raise_level: mov byte [hitCount], al xor ah, ah mov bl, 10 div bl ; ax / bl ; al = Q | ah = R add ax, 3030h mov word [hits], ax cmp byte [level], victoryLevel jb skip_vL_reached mov byte [gameStatus], victoryChar skip_vL_reached: jmp pTxt IF version2compile = bootSector ; REBOOT REBOOT: jmp 0ffffh:0000h END IF IF version2compile = dotcom ; QUIT QUIT: mov ax, 0003h ; 80x25 TEXT Mode int 10h mov ah, 4ch int 21h END IF IF version2compile = called_by_loserOS ; QUIT QUIT: jmp 0000h:7c00h END IF PRINT_Txt: mov si, textStr mov di, tSs pT_LP: lodsb or al, al jz pT_q mov ah, byte [es:di+1] jcxz after_ah_set mov ah, VarColour cmp al, '0' je after_ah_set mov ah, TwrColour cmp al, '#' je after_ah_set cmp al, '>' je after_ah_set mov ah, GssColour cmp al, gameOverChar je after_ah_set mov ah, BlkColour cmp al, '_' je after_ah_set mov ah, FxdColour after_ah_set: stosw jmp pT_LP pT_q: ret ; ; Data definitions ; textStr db 'SPACE:Hit_F:-_J:+' db '_' db 'Level:' level db '0' db '_' db 'Hits:' hits db '00' db '_' db '#' num db '0' db '>' gameStatus db gameOverChar numSeq: times numSeqLEN db '0' db '#' db '_' IF version2compile = bootSector db 'F1:Reboot' END IF IF version2compile = dotcom db 'F2:Quit' END IF IF version2compile = called_by_loserOS db 'F2:Quit' END IF db '_' db 'F8:NewGame' db 0 times 510-($-$$) db 0 dw 0AA55h RN rb 2 lastTick rb 2 hitCount rb 1 delayVar rb 1 IF version2compile = bootSector align 2 rb stackSize stack_ptr: END IF ; END YONG |
|||
24 Apr 2007, 12:28 |
|
mattst88 24 Apr 2007, 17:36
Please do us a favor and stop capitalizing the first two letters of FASM and not the last. Either all or nothing.
It's just a little annoying. |
|||
24 Apr 2007, 17:36 |
|
m 26 Apr 2007, 07:51
Thanks Dex4u !
Thanks YONG ! Sorry mattst88 ! _________________ Attitude! |
|||
26 Apr 2007, 07:51 |
|
mattst88 26 Apr 2007, 16:29
I have a few AMD64-Linux C function calling examples I'll clean up and post later today
|
|||
26 Apr 2007, 16:29 |
|
mattst88 27 Apr 2007, 14:33
Here's a small example for AMD64/Linux. It shows how to make use of C calls.
Absolute Value Code: format ELF64 extrn printf extrn puts extrn scanf public main section '.text' executable main: push rbp mov rbp,rsp mov edi,prompt call puts sub rsp,16 mov rsi,rsp mov edi,readint xor eax,eax call scanf mov rax,[rsp] add rsp,16 cqo xor rax,rdx sub rax,rdx mov rsi,rax mov edi,msg xor eax,eax call printf leave ret section '.data' writable align 16 msg db "Absolute value is %ld",0xA,0 prompt db "Enter a negative integer. ",0 readint db "%ld",0 Factorial Code: format ELF64 extrn printf extrn scanf extrn puts public main section '.text' executable main: push rbp mov rbp,rsp mov edi,prompt call puts sub rsp,16 mov rsi,rsp mov edi,scan xor eax,eax call scanf mov rax,[rsp] add rsp,16 mov rsi,rax lea rcx,[rax-1] top: mul rcx sub rcx,1 jnz top print: mov edi,msg mov rdx,rax xor eax,eax call printf leave ret section '.data' writable msg db "Factorial of %d is %d",0xA,0 scan db "%d",0 prompt db "Enter an unsigned integer.",0 Leibniz Theory of Pi (calculates Pi) uses SSE2/3 Code: format ELF64 extrn printf public main section '.text' executable align 16 main: push rbp mov rbp,rsp movdqa xmm6,dqword[denom] movdqa xmm2,dqword[numer] movdqa xmm3,dqword[add4] movdqa xmm4,xmm2 movdqa xmm5,dqword[zero] mov r12,10000000 align 16 top: divpd xmm2,xmm6 addpd xmm5,xmm2 movdqa xmm2,xmm4 addpd xmm6,xmm3 divpd xmm2,xmm6 addpd xmm5,xmm2 movdqa xmm2,xmm4 addpd xmm6,xmm3 divpd xmm2,xmm6 addpd xmm5,xmm2 movdqa xmm2,xmm4 addpd xmm6,xmm3 divpd xmm2,xmm6 addpd xmm5,xmm2 movdqa xmm2,xmm4 addpd xmm6,xmm3 sub r12,1 jnz top mov r12,10000000 movdqa xmm1,xmm5 movdqa xmm0,xmm6 haddpd xmm1,xmm1 mov eax,2 mov edi,msg call printf jmp top leave ret section '.data' writable align 16 denom: dq 1.0,3.0 numer: dq 4.0,-4.0 add4: dq 4.0,4.0 zero: dq 0.0,0.0 msg db "1/%.0f - %52.50f",0xA,0 Next power of two (input of 37 results in return value of 64, etc. useful for SDL_Surface to OpenGL texture conversions) Code: format ELF64 extrn printf extrn scanf extrn puts public main section '.text' executable main: push rbp mov rbp,rsp mov edi,prompt call puts sub rsp,16 mov rsi,rsp mov edi,readint xor eax,eax call scanf mov r12,[rsp] add rsp,16 mov rax,r12 bsr rcx,rax mov eax,2 shl rax,cl mov rdx,rax mov rsi,r12 mov edi,msg xor eax,eax call printf leave ret section '.data' writable align 16 msg db "Next power of %lu is %lu",0xA,0 readint db "%lu",0 prompt db "Enter an integer.",0 If anyone sees anything that should be fixed, let me know. Last edited by mattst88 on 14 Jul 2007, 01:56; edited 1 time in total |
|||
27 Apr 2007, 14:33 |
|
vid 28 Apr 2007, 15:18
mattst88: it misses error handling for "scanf"
|
|||
28 Apr 2007, 15:18 |
|
LocoDelAssembly 28 Apr 2007, 15:39
And if 16 bytes alignment is needed "sub rsp, 8" should be "sub rsp, 16" (and "add rsp, 8" should be "add rsp, 16)
|
|||
28 Apr 2007, 15:39 |
|
m 28 Apr 2007, 19:25
vid wrote: mattst88: it misses error handling for "scanf" _________________ Attitude! |
|||
28 Apr 2007, 19:25 |
|
edfed 10 Jun 2007, 16:34
and this it is the line algorythm for screen 13h
to call the line: Code: macro liner x,y,x2,y2,color { mov ax,screen_segment mov fs,ax mov eax,x mov ebx,y mov ecx,x1 mov edx,x2 mov [x1],eax mov [y1],ebx mov [x2],ecx mov [y2],edx mov al,color mov [colorl],al call line } Code: db 'line32.inc' line: pushad ;save the registers from previous code mov ecx,1 ;initilise the increments mov edi,1 mov edx,320 mov esi,1 mov eax,[x2] ;calculate delta x sub eax,[x1] jge @f neg eax ;if negative then neg the increments neg ecx neg edi @@: mov ebx,[y2] ;calculate delta y sub ebx,[y1] jge @f ;if negative then neg the increments neg ebx neg edx neg esi @@: mov [.deltamax],ebx ;who is the biggest delta? mov [.deltamin],eax ;cause it will become the mov [.dinc1],edx ; basic increment for the line calculation mov [.sinc1],esi mov [.dinc2],ecx mov [.sinc2],0 mov [.xinc1],0 mov [.xinc2],edi cmp eax,ebx ;is delta x less than delta y? jl @f mov [.deltamax],eax ;no so the refernces changes mov [.deltamin],ebx mov [.dinc1],ecx mov [.sinc1],0 mov [.dinc2],edx mov [.sinc2],esi mov [.xinc1],edi mov [.xinc2],0 @@: mov esi,[y1] ;first pixel mov edi,320 imul edi,esi add edi,[x1] mov ebx,[x1] mov ecx,[.deltamax] shr ecx,1 mov dl,[colorl] mov eax,[.deltamax] ;initialise divide counter inc eax @@: cmp esi,[up] ;out of screen? jle .ignore cmp esi,[down] jge .ignore cmp ebx,[left] jle .ignore cmp ebx,[right] jge .ignore mov [fs:edi],dl ;fs is the screen memory or the buffer .ignore: dec eax ;next dot je @f add ebx,[.xinc1] ;increment pixel in highest axel add edi,[.dinc1] add esi,[.sinc1] ;it work like a reverse division add ecx,[.deltamin] cmp ecx,[.deltamax] jl @b add ebx,[.xinc2] ;increment pixel in lowest axel add edi,[.dinc2] add esi,[.sinc2] sub ecx,[.deltamax] jmp @b @@: popad ret align 4 to access data fasty .xinc1 rd 1 .xinc2 rd 1 .dinc1 rd 1 .dinc2 rd 1 .sinc1 rd 1 .sinc2 rd 1 .deltamin rd 1 .deltamax rd 1 x1 rd 1 y1 rd 1 x2 rd 1 y2 rd 1 colorp db 0 colorl db 32 |
|||
10 Jun 2007, 16:34 |
|
edfed 10 Jun 2007, 16:35
delete
Last edited by edfed on 26 Jun 2007, 15:01; edited 1 time in total |
|||
10 Jun 2007, 16:35 |
|
rugxulo 13 Jun 2007, 00:03
Dex4u wrote: No, i converted it to fasm, about 3 years ago, from tasm, i think. I lost the original code. It's NASM code, written by Luks, found at http://www.256b.com/demo/262 (though included twice, dunno why). EDIT: Remy Vincent has also modified this (see Tennis in Text+CGA+EGA+VGA+SVGA (One step done!!)). |
|||
13 Jun 2007, 00:03 |
|
Dex4u 13 Jun 2007, 15:42
Thanks rugxulo, i have up dated the post.
|
|||
13 Jun 2007, 15:42 |
|
m 01 Jul 2007, 08:54
Hey YONG can you explain what the code submitted by you does?
|
|||
01 Jul 2007, 08:54 |
|
m 12 Jul 2007, 08:38
A program to Reduce Rational Numbers.
It uses PE console format, and is for Windows32 only. The program does the following (a perl script): Code: #!/usr/local/bin/perl print " This program reduces the Rational Numbers. Enter number (eg: 125 / 625): "; my ($num, $den) = split(/\D+/, <>); my $a = $num > $den ? $num : $den; my $b = $den < $num ? $den : $num; (($a, $b) = ($b, $a % $b)) while ($b); $rnum = $num / $a; $rden = $den / $a; print "$num / $den -- $rnum / $rden\n";
_________________ Attitude! Last edited by m on 14 Jul 2007, 10:11; edited 1 time in total |
|||||||||||
12 Jul 2007, 08:38 |
|
m 12 Jul 2007, 11:52
Windows socket example.
Just sends a message to the client showing his IP address.
_________________ Attitude! |
|||||||||||
12 Jul 2007, 11:52 |
|
Goto page 1, 2, 3, 4 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.