Graphics Examples

Drawing and plotting with Romasm

Drawing Shapes

Draw a Line

; Draw line from (-5, -5) to (5, 5)
CLEAR
LOAD R0, -500    ; x1 = -5 (scaled by 100)
LOAD R1, -500    ; y1 = -5
MOVE R0, R1      ; Move to start point
LOAD R0, 500     ; x2 = 5
LOAD R1, 500     ; y2 = 5
DRAW R0, R1      ; Draw line to end point
STROKE           ; Render it

Draw a Square

; Draw square from (-3, -3) to (3, 3)
CLEAR
; Bottom-left
LOAD R0, -300
LOAD R1, -300
MOVE R0, R1
; Top-left
LOAD R0, -300
LOAD R1, 300
DRAW R0, R1
; Top-right
LOAD R0, 300
LOAD R1, 300
DRAW R0, R1
; Bottom-right
LOAD R0, 300
LOAD R1, -300
DRAW R0, R1
; Close square
LOAD R0, -300
LOAD R1, -300
DRAW R0, R1
STROKE

Plotting Functions

Plot y = x²

; Function to plot: y = x²
; Input: R0 = x (scaled by 100)
; Output: R0 = x² (scaled by 100)
LOAD R1, R0      ; Copy x to R1
MUL R0, R1       ; R0 = x * x = x²
LOAD R1, 100
DIV R0, R1       ; Scale down
RET

Use this in the calculator's Y= editor to plot a parabola.

Plot y = sin(x)

; Function to plot: y = sin(x)
; Input: R0 = x in degrees (scaled by 100)
; Output: R0 = sin(x) (scaled by 1000, then scaled down)
CALL sin          ; Call stdlib sin function
; sin returns value scaled by 1000
LOAD R1, 10
DIV R0, R1       ; Scale down to match graph scale
RET

Plots a sine wave. Requires stdlib linking.

Polar Curves

Rose Curve: r = cos(3θ)

; Polar function: r = cos(3θ)
; Input: R0 = θ in degrees (scaled by 100)
; Output: R0 = r (scaled by 100)
LOAD R1, R0      ; Copy θ
LOAD R2, 3
MUL R1, R2       ; 3θ
LOAD R0, R1      ; Prepare for cos
CALL cos         ; cos(3θ)
; cos returns scaled by 1000
LOAD R1, 10
DIV R0, R1       ; Scale to match polar scale
RET

Cardioid: r = 1 + cos(θ)

; Polar function: r = 1 + cos(θ)
; Input: R0 = θ (scaled by 100)
; Output: R0 = r (scaled by 100)
CALL cos         ; cos(θ)
; cos returns scaled by 1000
LOAD R1, 10
DIV R0, R1       ; Scale down
LOAD R1, 100     ; 1.00 (scaled by 100)
ADD R0, R1       ; r = 1 + cos(θ)
RET

Console Plotting

Plot Points by Output

; Output (x, y) pairs that auto-plot
; Plot y = x² from x=-5 to x=5
LOAD R2, -500    ; x counter
LOAD R3, 500     ; max x
LOAD R4, 50      ; step

plot_loop:
    ; Calculate y = x²
    LOAD R0, R2  ; x
    LOAD R1, 100
    DIV R0, R1   ; Unscale x
    LOAD R1, R0
    MUL R0, R1   ; x²
    MUL R0, R1   ; Scale back
    
    ; Output (x, y) pair
    PRINT R2     ; x
    PRINT R0     ; y
    
    ; Increment x
    ADD R2, R4
    CMP R2, R3
    JLE plot_loop

In the calculator console, PRINTing pairs of numbers automatically plots them on the graph.

Related Documentation