Difference between revisions of "ARM: Sierpinski triangle"

From ScienceZero
Jump to: navigation, search
Line 25: Line 25:
 
         BNE    LOOP
 
         BNE    LOOP
  
 +
[[File:Sierpinskicodercolour.png]]
  
 
[[Category:Computing]]
 
[[Category:Computing]]

Revision as of 16:10, 11 July 2014

Draws the sierpinski triangle on a 320x256 screen with 8 bits per pixel.

       MOV     R9,#320                    ; Screen width
       MOV     R2,#5                      ; Random number generator seed
       MOV     R4,#160                    ; X position of top vertex
 
       MOV     R8,#1048576                ; Loop counter
       MOV     R11,#160                   ; Set start position to middle of the screen
       MOV     R12,#128                   

.LOOP  RSB     R2,R2,R2,ROR #21           ; Generate random number in the range 0 to 2
       MOVS    R3,R2,LSR #31              ; LSB in carry, MSB in R3
       BHI     LOOP                       ; Repeat if 3

       ADDCC   R11,R11,R4,LSL R3          ; Calculate position which is halfway
       ADDCC   R12,R12,R3,LSL #8          ; between the old and the new vertex
       ADDCS   R12,R12,#256
 
       MOV     R11,R11,LSR #1
       MOV     R12,R12,LSR #1
 
       MLA     R7,R12,R9,R11              ; R7 = (R12 * 320) + R11
       STRB    R12,[R0,R7]                
       SUBS    R8,R8,#1
       BNE     LOOP

Sierpinskicodercolour.png