RISC_V_LAB hinzugefügt

This commit is contained in:
muellerlu
2026-06-09 08:33:18 +02:00
commit 3c0ec38544
233 changed files with 90271 additions and 0 deletions
@@ -0,0 +1,43 @@
// *********************************************************************************************
// Description : C Program to store the sentence 'hello world!' in a char array in memory
// Project Version : v1.0
// Project : [BCDC] Microtec Academy Course: Building a RISC-V CPU with SystemVerilog
// -----
// Copyright (c) : 2025 Fraunhofer IIS, Department IDS
// Created : 15.Oct.2025 by Hussein Elzomor
// Last Modified : 15.Oct.2025 by Hussein Elzomor
// -----
// HISTORY : Date By Comments
// ----------- --------- -------------------------------------------------
// *********************************************************************************************
asm(".global _start, halt; .set DataMem 0x1; _start: lui sp 0x2; addi sp sp -4; jal main;");
// DataMem address usage is set manually in the assembly code after its generation.
void storeChar(char c, char *location)
{
*location = c;
}
int main()
{
static char mem[13];
storeChar('h', &mem[0]);
storeChar('e', &mem[1]);
storeChar('l', &mem[2]);
storeChar('l', &mem[3]);
storeChar('o', &mem[4]);
storeChar(' ', &mem[5]);
storeChar('w', &mem[6]);
storeChar('o', &mem[7]);
storeChar('r', &mem[8]);
storeChar('l', &mem[9]);
storeChar('d', &mem[10]);
storeChar('!', &mem[11]);
storeChar('\0', &mem[12]); // Don't forget the null terminator!
return 0; // End the main function and return 0 on success
}
@@ -0,0 +1,92 @@
00002137
FFC10113
03C000EF
0000006F
FE010113
00112E23
00812C23
02010413
FEB42423
FEA407A3
FE842783
FEF44703
00E78023
01C12083
01812403
02010113
00008067
FF010113
00112623
00812423
01010413
000015B7
00058593
06800513
00000317
FB0300E7
000015B7
00158593
06500513
00000317
F9C300E7
000015B7
00258593
06C00513
00000317
F88300E7
000015B7
00358593
06C00513
00000317
F74300E7
000015B7
00458593
06F00513
00000317
F60300E7
000015B7
00558593
02000513
00000317
F4C300E7
000015B7
00658593
07700513
00000317
F38300E7
000015B7
00758593
06F00513
00000317
F24300E7
000015B7
00858593
07200513
00000317
F10300E7
000015B7
00958593
06C00513
00000317
EFC300E7
000015B7
00A58593
06400513
00000317
EE8300E7
000015B7
00B58593
02100513
00000317
ED4300E7
000015B7
00C58593
00000513
00000317
EC0300E7
00000793
00078513
00C12083
00812403
01010113
00008067
@@ -0,0 +1,121 @@
// *********************************************************************************************
// Description : Assembly instructions for hello world program
// Project Version : v1.0
// Project : [BCDC] Microtec Academy Course: Building a RISC-V CPU with SystemVerilog
// -----
// Copyright (c) : 2025 Fraunhofer IIS, Department IDS
// Created : 15.Oct.2025 by Hussein Elzomor
// Last Modified : 21.Oct.2025 by Hussein Elzomor
// -----
// HISTORY : Date By Comments
// ----------- --------- -------------------------------------------------
// *********************************************************************************************
# GNU C++17 (crosstool-NG UNKNOWN) version 15.2.0 (riscv32-unknown-linux-gnu)
# compiled by GNU C version 16.0.0 20250802 (experimental), GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.24-GMP
# GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
# options passed: -mabi=ilp32d -misa-spec=20191213 -mtls-dialect=trad -march=rv32ifd_zicsr -g
.set DataMem,0x1 # Start of Data Memory 0x1000 (translates to 0x400 due to 4 bytes adressing system)
_start:
lui sp, 0x2 # Initialize stack pointer value to size of memory (0x00002000)
addi sp, sp -4 # Subtract stack pointer value by 4 to point to the last memory address (0x00001FFC)
jal main # Jump to main and save return address to ra
halt:
j halt # Get stuck here in a loop forever
storeChar:
addi sp,sp,-32 # Reserve some space on the stack
sw ra,28(sp) # Save the return address on the stack
sw s0,24(sp) # Save the caller frame pointer value on the stack
addi s0,sp,32 # Store the callee frame pointer value in s0 (end address of the stack frame)
sw a1,-24(s0) # arg1, location
sb a0,-17(s0) # arg0, c
# helloWorld.c:8: *location = c;
lw a5,-24(s0) # tmp136, location
lbu a4,-17(s0) # tmp137, c
sb a4,0(a5) # tmp137, *location_2(D)
# helloWorld.c:9: }
lw ra,28(sp) # Load the return address from the stack and store it in ra
lw s0,24(sp) # Load the caller frame pointer value from the stack and store it in s0
addi sp,sp,32 # Free the allocated stack space for the function call
jr ra # Return to address stored in ra
main:
addi sp,sp,-16 # Reserve some space on the stack
sw ra,12(sp) # Save the return address on the stack
sw s0,8(sp) # Save the caller frame pointer value on the stack
addi s0,sp,16 # Store the callee frame pointer value in s0 (end address of the stack frame)
# helloWorld.c:15: storeChar('h', &mem[0]);
lui a1,DataMem # tmp136, DataMem
addi a1,a1,0 # arg1, tmp136 + 0
li a0,104 # arg0, 'h'
call storeChar #
# helloWorld.c:16: storeChar('e', &mem[1]);
lui a1,DataMem # tmp137, DataMem
addi a1,a1,1 # arg1, tmp137 + 1
li a0,101 # arg0, 'e'
call storeChar #
# helloWorld.c:17: storeChar('l', &mem[2]);
lui a1,DataMem # tmp138, DataMem
addi a1,a1,2 # arg1, tmp138 + 2
li a0,108 # arg0, 'l'
call storeChar #
# helloWorld.c:18: storeChar('l', &mem[3]);
lui a1,DataMem # tmp139, DataMem
addi a1,a1,3 # arg1, tmp139 + 3
li a0,108 # arg0, 'l'
call storeChar #
# helloWorld.c:19: storeChar('o', &mem[4]);
lui a1,DataMem # tmp140, DataMem
addi a1,a1,4 # arg1, tmp140 + 4
li a0,111 # arg0, 'o'
call storeChar #
# helloWorld.c:20: storeChar(' ', &mem[5]);
lui a1,DataMem # tmp141, DataMem
addi a1,a1,5 # arg1, tmp141 + 5
li a0,32 # arg0, ' '
call storeChar #
# helloWorld.c:21: storeChar('w', &mem[6]);
lui a1,DataMem # tmp142, DataMem
addi a1,a1,6 # arg1, tmp142 + 6
li a0,119 # arg0, 'w'
call storeChar #
# helloWorld.c:22: storeChar('o', &mem[7]);
lui a1,DataMem # tmp143, DataMem
addi a1,a1,7 # arg1, tmp143 + 7
li a0,111 # arg0, 'o'
call storeChar #
# helloWorld.c:23: storeChar('r', &mem[8]);
lui a1,DataMem # tmp144, DataMem
addi a1,a1,8 # arg1, tmp144 + 8
li a0,114 # arg0, 'r'
call storeChar #
# helloWorld.c:24: storeChar('l', &mem[9]);
lui a1,DataMem # tmp145, DataMem
addi a1,a1,9 # arg1, tmp145 + 9
li a0,108 # arg0, 'l'
call storeChar #
# helloWorld.c:25: storeChar('d', &mem[10]);
lui a1,DataMem # tmp146, DataMem
addi a1,a1,10 # arg1, tmp146 + 10
li a0,100 # arg0, 'd'
call storeChar #
# helloWorld.c:26: storeChar('!', &mem[11]);
lui a1,DataMem # tmp147, DataMem
addi a1,a1,11 # arg1, tmp147 + 11
li a0,33 # arg0, '!'
call storeChar #
# helloWorld.c:27: storeChar('\0', &mem[12]); // Don't forget the null terminator!
lui a1,DataMem # tmp148, DataMem
addi a1,a1,12 # arg1, tmp148 + 12
li a0,0 # arg0, '\0
call storeChar #
# helloWorld.c:29: return 0; // End the main function and return 0 on success
li a5,0 # _16,
# helloWorld.c:30: }
mv a0,a5 #, <retval>
lw ra,12(sp) # Load the return address from the stack and store it in ra
lw s0,8(sp) # Load the caller frame pointer value from the stack and store it in s0
addi sp,sp,16 # Free the allocated stack space for the function call
jr ra # Return to address stored in ra
@@ -0,0 +1,120 @@
// *********************************************************************************************
// Description : Simplified assembly instructions for hello world program
// Project Version : v1.0
// Project : [BCDC] Microtec Academy Course: Building a RISC-V CPU with SystemVerilog
// -----
// Copyright (c) : 2025 Fraunhofer IIS, Department IDS
// Created : 15.Oct.2025 by Hussein Elzomor
// Last Modified : 21.Oct.2025 by Hussein Elzomor
// -----
// HISTORY : Date By Comments
// ----------- --------- -------------------------------------------------
// *********************************************************************************************
# 1 to 1 mapping of the Hex instructions in helloWorld.hex
# Simplified version of helloWorld.s
## Replaced pseudo instructions with the proper rv32i instructions
## Replaced jumps to labels with address offset values
# Use as a cross reference to identify:
## - the instruction being run on your processor
## - which part of the program is being run
## - confirm registers and memory addresses contain the correct data
_start: # Hex # MemAddr(PC)
lui x2 2 # 0x00002137 # 0x00000000
addi x2 x2 -4 # 0xFFC10113 # 0x00000004
jal x1 60 # 0x03C000EF # 0x00000008
halt:
jal x0 0 # 0x0000006F # 0x0000000C
storeChar:
addi x2 x2 -32 # 0xFE010113 # 0x00000010
sw x1 28(x2) # 0x00112E23 # 0x00000014
sw x8 24(x2) # 0x00812C23 # 0x00000018
addi x8 x2 32 # 0x02010413 # 0x0000001C
sw x11 -24(x8) # 0xFEB42423 # 0x00000020
sb x10 -17(x8) # 0xFEA407A3 # 0x00000024
lw x15 -24(x8) # 0xFE842783 # 0x00000028
lbu x14 -17(x8) # 0xFEF44703 # 0x0000002C
sb x14 0(x15) # 0x00E78023 # 0x00000030
lw x1 28(x2) # 0x01C12083 # 0x00000034
lw x8 24(x2) # 0x01812403 # 0x00000038
addi x2 x2 32 # 0x02010113 # 0x0000003C
jalr x0 x1 0 # 0x00008067 # 0x00000040
main:
addi x2 x2 -16 # 0xFF010113 # 0x00000044
sw x1 12(x2) # 0x00112623 # 0x00000048
sw x8 8(x2) # 0x00812423 # 0x0000004C
addi x8 x2 16 # 0x01010413 # 0x00000050
lui x11 1 # 0x000015B7 # 0x00000054
addi x11 x11 0 # 0x00058593 # 0x00000058
addi x10 x0 104 # 0x06800513 # 0x0000005C
auipc x6 0 # 0x00000317 # 0x00000060
jalr x1 x6 -80 # 0xFB0300E7 # 0x00000064
lui x11 1 # 0x000015B7 # 0x00000068
addi x11 x11 1 # 0x00158593 # 0x0000006C
addi x10 x0 101 # 0x06500513 # 0x00000070
auipc x6 0 # 0x00000317 # 0x00000074
jalr x1 x6 -100 # 0xF9C300E7 # 0x00000078
lui x11 1 # 0x000015B7 # 0x0000007C
addi x11 x11 2 # 0x00258593 # 0x00000080
addi x10 x0 108 # 0x06C00513 # 0x00000084
auipc x6 0 # 0x00000317 # 0x00000088
jalr x1 x6 -120 # 0xF88300E7 # 0x0000008C
lui x11 1 # 0x000015B7 # 0x00000090
addi x11 x11 3 # 0x00358593 # 0x00000094
addi x10 x0 108 # 0x06C00513 # 0x00000098
auipc x6 0 # 0x00000317 # 0x0000009C
jalr x1 x6 -140 # 0xF74300E7 # 0x000000A0
lui x11 1 # 0x000015B7 # 0x000000A4
addi x11 x11 4 # 0x00458593 # 0x000000A8
addi x10 x0 111 # 0x06F00513 # 0x000000AC
auipc x6 0 # 0x00000317 # 0x000000B0
jalr x1 x6 -160 # 0xF60300E7 # 0x000000B4
lui x11 1 # 0x000015B7 # 0x000000B8
addi x11 x11 5 # 0x00558593 # 0x000000BC
addi x10 x0 32 # 0x02000513 # 0x000000C0
auipc x6 0 # 0x00000317 # 0x000000C4
jalr x1 x6 -180 # 0xF4C300E7 # 0x000000C8
lui x11 1 # 0x000015B7 # 0x000000CC
addi x11 x11 6 # 0x00658593 # 0x000000D0
addi x10 x0 119 # 0x07700513 # 0x000000D4
auipc x6 0 # 0x00000317 # 0x000000D8
jalr x1 x6 -200 # 0xF38300E7 # 0x000000DC
lui x11 1 # 0x000015B7 # 0x000000E0
addi x11 x11 7 # 0x00758593 # 0x000000E4
addi x10 x0 111 # 0x06F00513 # 0x000000E8
auipc x6 0 # 0x00000317 # 0x000000EC
jalr x1 x6 -220 # 0xF24300E7 # 0x000000F0
lui x11 1 # 0x000015B7 # 0x000000F4
addi x11 x11 8 # 0x00858593 # 0x000000F8
addi x10 x0 114 # 0x07200513 # 0x000000FC
auipc x6 0 # 0x00000317 # 0x00000100
jalr x1 x6 -240 # 0xF10300E7 # 0x00000104
lui x11 1 # 0x000015B7 # 0x00000108
addi x11 x11 9 # 0x00958593 # 0x0000010C
addi x10 x0 108 # 0x06C00513 # 0x00000110
auipc x6 0 # 0x00000317 # 0x00000114
jalr x1 x6 -260 # 0xEFC300E7 # 0x00000118
lui x11 1 # 0x000015B7 # 0x0000011C
addi x11 x11 10 # 0x00A58593 # 0x00000120
addi x10 x0 100 # 0x06400513 # 0x00000124
auipc x6 0 # 0x00000317 # 0x00000128
jalr x1 x6 -280 # 0xEE8300E7 # 0x0000012C
lui x11 1 # 0x000015B7 # 0x00000130
addi x11 x11 11 # 0x00B58593 # 0x00000134
addi x10 x0 33 # 0x02100513 # 0x00000138
auipc x6 0 # 0x00000317 # 0x0000013C
jalr x1 x6 -300 # 0xED4300E7 # 0x00000140
lui x11 1 # 0x000015B7 # 0x00000144
addi x11 x11 12 # 0x00C58593 # 0x00000148
addi x10 x0 0 # 0x00000513 # 0x0000014C
auipc x6 0 # 0x00000317 # 0x00000150
jalr x1 x6 -320 # 0xEC0300E7 # 0x00000154
addi x15 x0 0 # 0x00000793 # 0x00000158
addi x10 x15 0 # 0x00078513 # 0x0000015C
lw x1 12(x2) # 0x00C12083 # 0x00000160
lw x8 8(x2) # 0x00812403 # 0x00000164
addi x2 x2 16 # 0x01010113 # 0x00000168
jalr x0 x1 0 # 0x00008067 # 0x0000016C