flat assembler
Message board for the users of flat assembler.

Index > DOS > Smallest Mandelbrot ever?

Author
Thread Post new topic Reply to topic
kourin



Joined: 04 Oct 2012
Posts: 4
kourin
Hello,

First of all this code is not mine: I found it on a CD-ROM, years ago, when PC magazines used to give one. And according to the comments, it comes from FIDO-Net. The compiled code is 79 bytes long!! It draws a view of the Mandelbrot surface in 320x200 VGA mode. It's a real gem, and I like to read the code once in a while. =)
Enjoy!

Code:
; Mandelbrot found in the FIDO-Net. Very nice.
        org 100h
start:  mov ax,13h
        int 10h         ; set 320x200 256 color mode
        mov ax,0a000h
        mov ds,ax       ; load ds with video segment
        xor di,di       ; zero out screen offset
        mov bp,-200     ; load y with -(screen height)
l1:     mov si,-320     ; load x with -(screen width)
l2:     push di         ; save screen offset
        xor bx,bx       ; val1 = 0
        xor di,di       ; val2 = 0
l3:     push bx
        lea ax,[bx+di]  ; ax = val1 + val2
        sub bx,di       ; bx = val1 - val2
        imul bx         ; ans = val1^2 - val2^2
        mov bl,ah
        mov bh,dl
        lea bx,[bx+si-64]   ; val1 = (ans/256) + x - 64
        pop ax
        imul di         ; ans = val1 * val2
        mov al,ah
        mov ah,dl
        add ax,ax
        xchg ax,di
        lea di,[bp+di-56] ; val2 = (ans/128) + y - 56
        cmp bh,4
        jg draw         ; if val1 > 1024 then draw point
        inc cl          ; increment color
        jne l3
draw:   pop di          ; restore screen offset
        xchg [di],cl    ; store color, and make color = 0
        inc di          ; increment screen offset
        inc si          ; increment x
        jne l2          ; if x <> 0 then continue lp2
        inc bp          ; increment y
        jne l1          ; if y <> 0 then continue lp1
        xor ax,ax
        int 16h
        mov ax,3
        int 10h         ; set text mode
        ret             ; exit program
    


k.
Post 22 Oct 2012, 06:51
View user's profile Send private message Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 311
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan
Thank you kourin.
This code can be optimised to 78 bytes. Smile
Code:
Start:  mov     ax,13h
        int     10h             ; set 320x200 256 color mode
        push    0xA000
        pop     ds              ; load ds with video segment
        xor     di,di           ; zero out screen offset    

_________________
smaller is better
Post 22 Oct 2012, 13:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17352
Location: In your JS exploiting you and your system
revolution
CandyMan wrote:
Code:
;...
        push    0xA000
;...    
Only if you want to drop support for 8086 & 8088 CPUs Wink
Post 22 Oct 2012, 13:39
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.