Add hello world ASM example

This commit is contained in:
Olof Kindgren 2023-01-15 19:49:14 +01:00
parent a92965b359
commit 923b53ce0b
2 changed files with 82 additions and 0 deletions

58
sw/hello_uart.S Normal file
View file

@ -0,0 +1,58 @@
#define GPIO_ADDR 0x40000000
#define HALT_ADDR 0x90000000
/*
a0 = GPIO address
a1 = String address
t0 = Character to write
*/
.globl _start
_start:
/* Load gpio address to a0 */
li a0, GPIO_ADDR
/* Set GPIO high initially */
addi t0, zero, 1
sb t0, 0(a0)
/* Load string address to a1 */
la a1, str
next_char:
/* Read char from string */
lbu t0, 0(a1)
/* If zero, we reached end of string and will exit the simulation */
beqz t0, halt
/* Bitbanged UART loop */
ori t0, t0, 0x100
slli t0, t0, 1
1: sb t0, 0(a0)
srli t0, t0, 1
/*
* Adding delay nops to achieve an approximate
* baud rate of 57600 at 16MHz
*/
nop
nop
bnez t0, 1b
/* Increase address to next char in string */
addi a1, a1, 1
j next_char
/* Writing anything to HALT_ADDR will exit simulation */
halt: li t0, HALT_ADDR
sw zero, 0(t0)
/*
* Loop to prevent PC from keep reading memory in case
* we run on real HW and not in simulation
*/
j halt
str:
.section .data
.string "Hi, I'm Servant!\n"

24
sw/hello_uart.hex Normal file
View file

@ -0,0 +1,24 @@
40000537
00100293
00550023
00000597
04058593
0005C283
02028463
1002E293
00129293
00550023
0012D293
00000013
00000013
FE0298E3
00158593
FD9FF06F
900002B7
0002A023
FF9FF06F
202C6948
206D2749
76726553
21746E61
0000000A