Skip to content

Instantly share code, notes, and snippets.

@thata
Created June 3, 2022 15:05
Show Gist options
  • Save thata/b8b68efdcfae64f12680acf9a6d3fde4 to your computer and use it in GitHub Desktop.
Save thata/b8b68efdcfae64f12680acf9a6d3fde4 to your computer and use it in GitHub Desktop.
RISC-VでHELLO WORLD
# hello
#
# $ riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -Wl,-Ttext=0x00 -nostdlib -o hello.elf hello.S
# $ riscv64-unknown-elf-objcopy -O binary hello.elf hello.rom
# $ ruby rv32sim.rb hello.rom
.text
.globl _start
.type _start, @function
_start:
// 1024を18ビットシフトさせて gp へ 0x10000000 をセットする
addi gp, zero, 1024
slli gp, gp, 18
addi t0, zero, 'H'
sw t0, 0(gp)
addi t0, zero, 'E'
sw t0, 0(gp)
addi t0, zero, 'L'
sw t0, 0(gp)
addi t0, zero, 'L'
sw t0, 0(gp)
addi t0, zero, 'O'
sw t0, 0(gp)
addi t0, zero, ' '
sw t0, 0(gp)
addi t0, zero, 'W'
sw t0, 0(gp)
addi t0, zero, 'O'
sw t0, 0(gp)
addi t0, zero, 'R'
sw t0, 0(gp)
addi t0, zero, 'L'
sw t0, 0(gp)
addi t0, zero, 'D'
sw t0, 0(gp)
addi t0, zero, '!'
sw t0, 0(gp)
addi t0, zero, '!'
sw t0, 0(gp)
addi t0, zero, '\n'
sw t0, 0(gp)
nop
nop
nop
nop
nop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment