Example of an ARM assembly language program using the MASD compiler

"!NO CODE !RPL

( turn

into RPL mode)

::

(

open

a

RPL

program )

TURNMENUOFF

(

remove

the

menu line )

CODE

%open an assembly program

%this program takes control of the screen and

%displays a Mandelbrot set using the standard algorithm

%ie: for each point from x=1.5 to 0.5,

%for each point from y=1 to 1

%if any an, n<256 in the series

%a0=x+iy (complex number), an+1=a0+an²

%has an absolute value > 2, the point is not part of the set

%the numbers are stored on 32 bits.

%the numbers are shifted by 12 bits, the lower 12 bits representing

%the decimal part of the number (in 1/4096)

SAVE

 

 

 

% save

the RPL pointers

INTOFF

 

 

 

% disable keyboard interrupts

SKUB {

 

 

 

% jump

over

the ARM code

*start

 

 

 

 

 

 

!ARM

 

 

 

% switch to

ARM mode

STMDB

sp! {R4 R5 R6 R7 R8 LP}

% save

registers in the stack

LDR R2, [R1, #2324]

% load

R2=x

(content of saturn

 

 

 

 

% reg B, nibbles 07)

LDR R3, [R1, #2340]

% load

R3=y

(content of saturn

 

 

 

 

% reg B, nibbles 07)

MOV R7 R2

 

 

% copy

X in

r7

MOV R8 R3

 

 

% copy

Y in

r8

MOV R6 256

 

% copy

256 in R6

{

 

 

 

 

 

 

MUL

R4, R2, R2

% r4= x² <<

12

MOV

R4

R4

>> 12

% r4= x²

 

MUL

R5, R3, R3

 

 

 

MOV

R5

R5

>> 12

% r5= y²

 

ADD

LP

R4

R5

% LP =

x² +

CMP

LP

$4000

% if abs² an > 4

EXITGT

 

 

% exit

 

 

SUB

R4

R4

R5

% r4= x²y²

 

MUL

R3

R2

R3

% R3= X*Y

 

ADD

R2

R7

R4

% r2= X + x²y² = new x

MOV

R3

R3

>> 11

% r3= x*y*2

 

ADD

R3

R8

R3

% r3= Y+2*x*y = new Y

SUBS R6 R6 1

% decrement

loop counter

UPNE

 

 

 

% up if not

0

% we

have

looped

256 times and abs(An)<2, the point is in the set!

LDRB

R6

[R1

2408]

%

clear the flag ST0

BIC R6 R6

1

 

 

 

STRB

R6

[R1

2408]

 

 

LDMIA sp!

{R4 R5

R6 R7 R8 PC} %

restore all registers and return

}

% we have reached a An where abs(An)>2,the point is out of the set

The Development Library 639

Page 537
Image 537
HP 48gII Graphing, 50g Graphing manual Turnmenuoff