How to resolve the algorithm Chaos game step by step in the X86 Assembly programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Chaos game step by step in the X86 Assembly programming language
Table of Contents
Problem Statement
The Chaos Game is a method of generating the attractor of an iterated function system (IFS). One of the best-known and simplest examples creates a fractal, using a polygon and an initial point selected at random.
Play the Chaos Game using the corners of an equilateral triangle as the reference points. Add a starting point at random (preferably inside the triangle). Then add the next point halfway between the starting point and one of the reference points. This reference point is chosen at random. After a sufficient number of iterations, the image of a Sierpinski Triangle should emerge.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Chaos game step by step in the X86 Assembly programming language
Source code in the x86 programming language
1 ;Assemble with: tasm, tlink /t
2 0000 .model tiny
3 0000 .code
4 .386
5 org 100h
6 ;assume: ax=0, bx=0, cx=00FFh, dx=cs, si=0100h
7
8 0100 B0 12 start: mov al, 12h ;set 640x480x4 graphic screen
9 0102 CD 10 int 10h
10
11 0104 69 04 4E35 cha10: imul ax, [si], 4E35h ;generate random number
12 0108 40 inc ax
13 0109 89 04 mov [si], ax ;save seed
14 010B 8A C4 mov al, ah ;use high byte
15 010D D4 03 aam 3 ;al:= rem(al/3)
16 010F 8A D8 mov bl, al
17 0111 02 DB add bl, bl ;double to index words
18
19 0113 03 8F 0130r add cx, [bx+Tx] ;X:= (X+Tx(R)) /2
20 0117 D1 E9 shr cx, 1
21
22 0119 03 97 0136r add dx, [bx+Ty] ;Y:= (Y+Ty(R)) /2
23 011D D1 EA shr dx, 1
24
25 011F B8 0C02 mov ax, 0C02h ;write green (2) graphics pixel
26 0122 CD 10 int 10h ;(bh=0)
27
28 0124 B4 01 mov ah, 01h ;loop until keystroke
29 0126 CD 16 int 16h
30 0128 74 DA jz cha10
31
32 012A B8 0003 mov ax, 0003h ;restore normal text-mode screen
33 012D CD 10 int 10h
34 012F C3 ret ;return to DOS
35
36 0130 0140 002B 0255 Tx dw 320, 320-277, 320+277 ;equilateral triangle
37 0136 0000 01DF 01DF Ty dw 0, 479, 479
38 end start
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the 11l programming language
You may also check:How to resolve the algorithm Greatest common divisor step by step in the ActionScript programming language
You may also check:How to resolve the algorithm Sierpinski triangle/Graphical step by step in the Java programming language
You may also check:How to resolve the algorithm Zeckendorf number representation step by step in the Raku programming language
You may also check:How to resolve the algorithm Write entire file step by step in the Standard ML programming language