Add some sample files
This commit is contained in:
commit
e8b757e8b2
6 changed files with 87 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.o
|
||||
*.elf
|
13
Makefile
Normal file
13
Makefile
Normal file
|
@ -0,0 +1,13 @@
|
|||
AS=riscv64-unknown-elf-as
|
||||
LD=riscv64-unknown-elf-ld
|
||||
|
||||
all: main.x
|
||||
|
||||
hello.elf: hello.o
|
||||
$(LD) -m elf32lriscv $^ -o $@
|
||||
|
||||
main.x: main.o exit.o
|
||||
$(LD) -m elf32lriscv $^ -o main.x
|
||||
|
||||
%.o : %.s
|
||||
$(AS) -mabi=ilp32e -march=rv32ec $< -o $@
|
22
README.md
Normal file
22
README.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
Calculator
|
||||
==========
|
||||
|
||||
Aims to be a calculator implemented in 32-bit RISC-V assembly, initially targeting the
|
||||
inexpensive [CH32V003 RV32EC microcontroller][CH32V003]: 48Mhz 2KB SRAM, 16KB Flash.
|
||||
|
||||
Notes
|
||||
-----
|
||||
|
||||
### Disassemble
|
||||
|
||||
riscv64-unknown-elf-objdump -D main.o
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
* https://riscv-programming.org/book/riscv-book.html
|
||||
* [CH32V003 Datasheet](https://www.wch-ic.com/downloads/CH32V003RM_PDF.html)
|
||||
* [QingKeV2 Processor Manual](https://www.wch-ic.com/downloads/QingKeV2_Processor_Manual_PDF.html) — core used in the CH32V003
|
||||
|
||||
|
||||
[CH32V003]: https://www.wch-ic.com/products/CH32V003.html
|
5
exit.s
Normal file
5
exit.s
Normal file
|
@ -0,0 +1,5 @@
|
|||
.globl exit
|
||||
exit:
|
||||
li a0, 0
|
||||
li a1, 93
|
||||
ecall
|
40
hello.s
Normal file
40
hello.s
Normal file
|
@ -0,0 +1,40 @@
|
|||
# RISC-V assembly program to print "Hello World!" to stdout.
|
||||
|
||||
.org 0
|
||||
# Provide program starting address to linker
|
||||
.global _start
|
||||
|
||||
/* newlib system calls */
|
||||
.set SYSEXIT, 93
|
||||
.set SYSWRITE, 64
|
||||
|
||||
.section .rodata
|
||||
str: .ascii "Hello World!\n"
|
||||
.set str_size, .-str
|
||||
|
||||
.text
|
||||
_start:
|
||||
li t0, 0
|
||||
li t1, 5
|
||||
|
||||
# dummy test for jal instruction
|
||||
.L1:
|
||||
jal x0, .L2
|
||||
.L2:
|
||||
nop
|
||||
|
||||
loop:
|
||||
beq t0, t1, end
|
||||
|
||||
li t0, SYSWRITE # "write" syscall
|
||||
li a0, 1 # 1 = standard output (stdout)
|
||||
la a1, str # load address of hello string
|
||||
li a2, str_size # length of hello string
|
||||
ecall # invoke syscall to print the string
|
||||
addi t0, t0, 1
|
||||
j loop
|
||||
|
||||
end:
|
||||
li t0, SYSEXIT # "exit" syscall
|
||||
add a0, x0, 0 # Use 0 return code
|
||||
ecall # invoke syscall to terminate the program
|
5
main.s
Normal file
5
main.s
Normal file
|
@ -0,0 +1,5 @@
|
|||
.globl _start
|
||||
_start:
|
||||
li a0, 10
|
||||
li a1, 20
|
||||
jal exit
|
Loading…
Reference in a new issue