Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Patrick Fitzgerald
Published © GPL3+

RISC-V Assembly Language with Ripes OnLine Simulator

Don't install any software. Go to the website and run your assembly code

AdvancedProtip3 hours1,320

Things used in this project

Software apps and online services

Ripes OnLine RISC-V Simulator

Story

Read more

Code

leds.s

Assembly x86
RISC-V assembly code demo from Ripes simulator program
# LEDs
# This program draws an animation on an LED matrix peripheral.
#
# To run this program, make sure that you have instantiated an "LED Matrix"
# peripheral in the "I/O" tab.


li a0 LED_MATRIX_0_BASE
li a1 LED_MATRIX_0_WIDTH
li a2 LED_MATRIX_0_HEIGHT

loop:
        addi    sp, sp, -16
        sw      s0, 12(sp)
        sw      s1, 8(sp)
        mv      t6, zero
        add     t3, a2, a1
        slli    a6, a1, 2
        lui     a3, 16
        addi    a7, a3, -256
        lui     t0, 4080
init:
        mv      t4, zero
        mv      t1, zero
        mv      t2, a0
nextRow:
        mv      a4, zero
        slli    a3, t1, 8
        sub     a3, a3, t1
        divu    a3, a3, a2
        add     a3, a3, t6
        slli    a3, a3, 8
        and     t5, a3, a7
        mv      a5, t2
        mv      a3, a1
nextPixel:
        divu    s0, a4, a1
        add     s0, s0, t6
        add     s1, t4, a4
        divu    s1, s1, t3
        add     s1, s1, t6
        slli    s0, s0, 16
        and     s0, s0, t0
        or      s0, t5, s0
        andi    s1, s1, 255
        or      s0, s0, s1
        sw      s0, 0(a5)
        addi    a3, a3, -1
        addi    a5, a5, 4
        addi    a4, a4, 255
        bnez    a3, nextPixel
        addi    t6, t6, 1
        addi    t1, t1, 1
        add     t2, t2, a6
        addi    t4, t4, 255
        bne     t1, a2, nextRow
        j       init

leds.txt

Assembly x86
disassembled code from Ripes leds.s demo
useful for understanding how processor executes our input
    0:        f0000537        lui x10 0xf0000
    4:        02300593        addi x11 x0 35
    8:        01900613        addi x12 x0 25

0000000c <loop>:
    c:        ff010113        addi x2 x2 -16
    10:        00812623        sw x8 12 x2
    14:        00912423        sw x9 8 x2
    18:        00000f93        addi x31 x0 0
    1c:        00b60e33        add x28 x12 x11
    20:        00259813        slli x16 x11 2
    24:        000106b7        lui x13 0x10
    28:        f0068893        addi x17 x13 -256
    2c:        00ff02b7        lui x5 0xff0

00000030 <init>:
    30:        00000e93        addi x29 x0 0
    34:        00000313        addi x6 x0 0
    38:        00050393        addi x7 x10 0

0000003c <nextRow>:
    3c:        00000713        addi x14 x0 0
    40:        00831693        slli x13 x6 8
    44:        406686b3        sub x13 x13 x6
    48:        02c6d6b3        divu x13 x13 x12
    4c:        01f686b3        add x13 x13 x31
    50:        00869693        slli x13 x13 8
    54:        0116ff33        and x30 x13 x17
    58:        00038793        addi x15 x7 0
    5c:        00058693        addi x13 x11 0

00000060 <nextPixel>:
    60:        02b75433        divu x8 x14 x11
    64:        01f40433        add x8 x8 x31
    68:        00ee84b3        add x9 x29 x14
    6c:        03c4d4b3        divu x9 x9 x28
    70:        01f484b3        add x9 x9 x31
    74:        01041413        slli x8 x8 16
    78:        00547433        and x8 x8 x5
    7c:        008f6433        or x8 x30 x8
    80:        0ff4f493        andi x9 x9 255
    84:        00946433        or x8 x8 x9
    88:        0087a023        sw x8 0 x15
    8c:        fff68693        addi x13 x13 -1
    90:        00478793        addi x15 x15 4
    94:        0ff70713        addi x14 x14 255
    98:        fc0694e3        bne x13 x0 -56 <nextPixel>
    9c:        001f8f93        addi x31 x31 1
    a0:        00130313        addi x6 x6 1
    a4:        010383b3        add x7 x7 x16
    a8:        0ffe8e93        addi x29 x29 255
    ac:        f8c318e3        bne x6 x12 -112 <nextRow>
    b0:        f81ff06f        jal x0 -128 <init>

Credits

Patrick Fitzgerald
118 projects • 40 followers

Comments