mirror of
https://github.com/plctlab/riscv-operating-system-mooc.git
synced 2025-11-16 12:34:47 +00:00
fixed some minor issues.
- https://gitee.com/unicornx/riscv-operating-system-mooc/issues/I4QLTP - https://gitee.com/unicornx/riscv-operating-system-mooc/issues/I4PJTQ - https://gitee.com/unicornx/riscv-operating-system-mooc/issues/I49VW5 Signed-off-by: Wang Chen <wangchen20@iscas.ac.cn>
This commit is contained in:
@@ -20,7 +20,7 @@ stop:
|
||||
nop # just for demo effect
|
||||
|
||||
stack_start:
|
||||
.rept 10
|
||||
.rept 12
|
||||
.word 0
|
||||
.endr
|
||||
stack_end:
|
||||
|
||||
@@ -17,7 +17,7 @@ stop:
|
||||
nop # just for demo effect
|
||||
|
||||
stack_start:
|
||||
.rept 10
|
||||
.rept 12
|
||||
.word 0
|
||||
.endr
|
||||
stack_end:
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
# Calling Convention
|
||||
# Demo to create a leaf routine
|
||||
#
|
||||
# void _start()
|
||||
# {
|
||||
# // calling leaf routine
|
||||
# square(3);
|
||||
# }
|
||||
#
|
||||
# int square(int num)
|
||||
# {
|
||||
# return num * num;
|
||||
# }
|
||||
|
||||
.text # Define beginning of text section
|
||||
.global _start # Define entry _start
|
||||
|
||||
_start:
|
||||
la sp, stack_end # prepare stack for calling functions
|
||||
|
||||
li a0, 3
|
||||
call square
|
||||
|
||||
# the time return here, a0 should stores the result
|
||||
stop:
|
||||
j stop # Infinite loop to stop execution
|
||||
|
||||
# int square(int num)
|
||||
square:
|
||||
# prologue
|
||||
addi sp, sp, -8
|
||||
sw s0, 0(sp)
|
||||
sw s1, 4(sp)
|
||||
|
||||
# `mul a0, a0, a0` should be fine,
|
||||
# programing as below just to demo we can contine use the stack
|
||||
mv s0, a0
|
||||
mul s1, s0, s0
|
||||
mv a0, s1
|
||||
|
||||
# epilogue
|
||||
lw s0, 0(sp)
|
||||
lw s1, 4(sp)
|
||||
addi sp, sp, 8
|
||||
|
||||
ret
|
||||
|
||||
# add nop here just for demo in gdb
|
||||
nop
|
||||
|
||||
# allocate stack space
|
||||
stack_start:
|
||||
.rept 10
|
||||
.word 0
|
||||
.endr
|
||||
stack_end:
|
||||
|
||||
.end # End of file
|
||||
|
||||
# Calling Convention
|
||||
# Demo to create a leaf routine
|
||||
#
|
||||
# void _start()
|
||||
# {
|
||||
# // calling leaf routine
|
||||
# square(3);
|
||||
# }
|
||||
#
|
||||
# int square(int num)
|
||||
# {
|
||||
# return num * num;
|
||||
# }
|
||||
|
||||
.text # Define beginning of text section
|
||||
.global _start # Define entry _start
|
||||
|
||||
_start:
|
||||
la sp, stack_end # prepare stack for calling functions
|
||||
|
||||
li a0, 3
|
||||
call square
|
||||
|
||||
# the time return here, a0 should stores the result
|
||||
stop:
|
||||
j stop # Infinite loop to stop execution
|
||||
|
||||
# int square(int num)
|
||||
square:
|
||||
# prologue
|
||||
addi sp, sp, -8
|
||||
sw s0, 0(sp)
|
||||
sw s1, 4(sp)
|
||||
|
||||
# `mul a0, a0, a0` should be fine,
|
||||
# programing as below just to demo we can contine use the stack
|
||||
mv s0, a0
|
||||
mul s1, s0, s0
|
||||
mv a0, s1
|
||||
|
||||
# epilogue
|
||||
lw s0, 0(sp)
|
||||
lw s1, 4(sp)
|
||||
addi sp, sp, 8
|
||||
|
||||
ret
|
||||
|
||||
# add nop here just for demo in gdb
|
||||
nop
|
||||
|
||||
# allocate stack space
|
||||
stack_start:
|
||||
.rept 12
|
||||
.word 0
|
||||
.endr
|
||||
stack_end:
|
||||
|
||||
.end # End of file
|
||||
|
||||
|
||||
@@ -1,99 +1,99 @@
|
||||
# Calling Convention
|
||||
# Demo how to write nested routines
|
||||
#
|
||||
# void _start()
|
||||
# {
|
||||
# // calling nested routine
|
||||
# aa_bb(3, 4);
|
||||
# }
|
||||
#
|
||||
# int aa_bb(int a, int b)
|
||||
# {
|
||||
# return square(a) + square(b);
|
||||
# }
|
||||
#
|
||||
# int square(int num)
|
||||
# {
|
||||
# return num * num;
|
||||
# }
|
||||
|
||||
.text # Define beginning of text section
|
||||
.global _start # Define entry _start
|
||||
|
||||
_start:
|
||||
la sp, stack_end # prepare stack for calling functions
|
||||
|
||||
# aa_bb(3, 4);
|
||||
li a0, 3
|
||||
li a1, 4
|
||||
call aa_bb
|
||||
|
||||
stop:
|
||||
j stop # Infinite loop to stop execution
|
||||
|
||||
# int aa_bb(int a, int b)
|
||||
# return a^2 + b^2
|
||||
aa_bb:
|
||||
# prologue
|
||||
addi sp, sp, -16
|
||||
sw s0, 0(sp)
|
||||
sw s1, 4(sp)
|
||||
sw s2, 8(sp)
|
||||
sw ra, 12(sp)
|
||||
|
||||
# cp and store the input params
|
||||
mv s0, a0
|
||||
mv s1, a1
|
||||
|
||||
# sum will be stored in s2 and is initialized as zero
|
||||
li s2, 0
|
||||
|
||||
mv a0, s0
|
||||
jal square
|
||||
add s2, s2, a0
|
||||
|
||||
mv a0, s1
|
||||
jal square
|
||||
add s2, s2, a0
|
||||
|
||||
mv a0, s2
|
||||
|
||||
# epilogue
|
||||
lw s0, 0(sp)
|
||||
lw s1, 4(sp)
|
||||
lw s2, 8(sp)
|
||||
lw ra, 12(sp)
|
||||
addi sp, sp, 16
|
||||
ret
|
||||
|
||||
# int square(int num)
|
||||
square:
|
||||
# prologue
|
||||
addi sp, sp, -8
|
||||
sw s0, 0(sp)
|
||||
sw s1, 4(sp)
|
||||
|
||||
# `mul a0, a0, a0` should be fine,
|
||||
# programing as below just to demo we can contine use the stack
|
||||
mv s0, a0
|
||||
mul s1, s0, s0
|
||||
mv a0, s1
|
||||
|
||||
# epilogue
|
||||
lw s0, 0(sp)
|
||||
lw s1, 4(sp)
|
||||
addi sp, sp, 8
|
||||
|
||||
ret
|
||||
|
||||
# add nop here just for demo in gdb
|
||||
nop
|
||||
|
||||
# allocate stack space
|
||||
stack_start:
|
||||
.rept 10
|
||||
.word 0
|
||||
.endr
|
||||
stack_end:
|
||||
|
||||
.end # End of file
|
||||
# Calling Convention
|
||||
# Demo how to write nested routines
|
||||
#
|
||||
# void _start()
|
||||
# {
|
||||
# // calling nested routine
|
||||
# aa_bb(3, 4);
|
||||
# }
|
||||
#
|
||||
# int aa_bb(int a, int b)
|
||||
# {
|
||||
# return square(a) + square(b);
|
||||
# }
|
||||
#
|
||||
# int square(int num)
|
||||
# {
|
||||
# return num * num;
|
||||
# }
|
||||
|
||||
.text # Define beginning of text section
|
||||
.global _start # Define entry _start
|
||||
|
||||
_start:
|
||||
la sp, stack_end # prepare stack for calling functions
|
||||
|
||||
# aa_bb(3, 4);
|
||||
li a0, 3
|
||||
li a1, 4
|
||||
call aa_bb
|
||||
|
||||
stop:
|
||||
j stop # Infinite loop to stop execution
|
||||
|
||||
# int aa_bb(int a, int b)
|
||||
# return a^2 + b^2
|
||||
aa_bb:
|
||||
# prologue
|
||||
addi sp, sp, -16
|
||||
sw s0, 0(sp)
|
||||
sw s1, 4(sp)
|
||||
sw s2, 8(sp)
|
||||
sw ra, 12(sp)
|
||||
|
||||
# cp and store the input params
|
||||
mv s0, a0
|
||||
mv s1, a1
|
||||
|
||||
# sum will be stored in s2 and is initialized as zero
|
||||
li s2, 0
|
||||
|
||||
mv a0, s0
|
||||
jal square
|
||||
add s2, s2, a0
|
||||
|
||||
mv a0, s1
|
||||
jal square
|
||||
add s2, s2, a0
|
||||
|
||||
mv a0, s2
|
||||
|
||||
# epilogue
|
||||
lw s0, 0(sp)
|
||||
lw s1, 4(sp)
|
||||
lw s2, 8(sp)
|
||||
lw ra, 12(sp)
|
||||
addi sp, sp, 16
|
||||
ret
|
||||
|
||||
# int square(int num)
|
||||
square:
|
||||
# prologue
|
||||
addi sp, sp, -8
|
||||
sw s0, 0(sp)
|
||||
sw s1, 4(sp)
|
||||
|
||||
# `mul a0, a0, a0` should be fine,
|
||||
# programing as below just to demo we can contine use the stack
|
||||
mv s0, a0
|
||||
mul s1, s0, s0
|
||||
mv a0, s1
|
||||
|
||||
# epilogue
|
||||
lw s0, 0(sp)
|
||||
lw s1, 4(sp)
|
||||
addi sp, sp, 8
|
||||
|
||||
ret
|
||||
|
||||
# add nop here just for demo in gdb
|
||||
nop
|
||||
|
||||
# allocate stack space
|
||||
stack_start:
|
||||
.rept 12
|
||||
.word 0
|
||||
.endr
|
||||
stack_end:
|
||||
|
||||
.end # End of file
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
# Shift Right Arithmetic Immediate
|
||||
# Format:
|
||||
# SLLI RD, RS1, IMM
|
||||
# Description:
|
||||
# The immediate value determines the number of bits to shift. The contents of
|
||||
# RS1 is shifted right that many bits and the result is placed in RD. The shift
|
||||
# is “arithmetic”, i.e., the sign bit is repeatedly shifted in on the
|
||||
# most-significant end.
|
||||
# Comment:
|
||||
# In C, for signed integer, >> is shift right with arithmetic.
|
||||
|
||||
.text # Define beginning of text section
|
||||
.global _start # Define entry _start
|
||||
|
||||
_start:
|
||||
# li x6, 0x80 # x6 = 0b1000-0000
|
||||
li x6, 0x80000000 # x6 = 0b1000-0000-0000-0000-0000-0000-0000-0000
|
||||
srai x5, x6, 4 # x5 = x6 >> 3
|
||||
|
||||
stop:
|
||||
j stop # Infinite loop to stop execution
|
||||
|
||||
.end # End of file
|
||||
# Shift Right Arithmetic Immediate
|
||||
# Format:
|
||||
# SRAI RD, RS1, IMM
|
||||
# Description:
|
||||
# The immediate value determines the number of bits to shift. The contents of
|
||||
# RS1 is shifted right that many bits and the result is placed in RD. The shift
|
||||
# is “arithmetic”, i.e., the sign bit is repeatedly shifted in on the
|
||||
# most-significant end.
|
||||
# Comment:
|
||||
# In C, for signed integer, >> is shift right with arithmetic.
|
||||
|
||||
.text # Define beginning of text section
|
||||
.global _start # Define entry _start
|
||||
|
||||
_start:
|
||||
# li x6, 0x80 # x6 = 0b1000-0000
|
||||
li x6, 0x80000000 # x6 = 0b1000-0000-0000-0000-0000-0000-0000-0000
|
||||
srai x5, x6, 4 # x5 = x6 >> 4
|
||||
|
||||
stop:
|
||||
j stop # Infinite loop to stop execution
|
||||
|
||||
.end # End of file
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/*
|
||||
* POWER UP DEFAULTS
|
||||
* IER = 0: TX/RX holding register interrupts are bith disabled
|
||||
* IER = 0: TX/RX holding register interrupts are both disabled
|
||||
* ISR = 1: no interrupt penting
|
||||
* LCR = 0
|
||||
* MCR = 0
|
||||
|
||||
Reference in New Issue
Block a user