From b78f32e47616d2fd86a75e52b0dc60b96ad4be6e Mon Sep 17 00:00:00 2001 From: zhangxinyu <840317537@qq.com> Date: Wed, 24 May 2023 16:15:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0"=E8=85=94=E9=AA=A8=E9=BE=99"?= =?UTF-8?q?=20=E7=94=A8=E6=88=B7=E5=BA=94=E7=94=A8=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch3/user/src/bin/00power_3.rs | 28 ++++++++++++++++++++++++++++ ch3/user/src/bin/00write_a.rs | 20 -------------------- ch3/user/src/bin/01power_5.rs | 28 ++++++++++++++++++++++++++++ ch3/user/src/bin/01write_b.rs | 20 -------------------- ch3/user/src/bin/02power_7.rs | 28 ++++++++++++++++++++++++++++ ch3/user/src/bin/02write_c.rs | 20 -------------------- ch3/user/src/bin/03sleep.rs | 18 ++++++++++++++++++ 7 files changed, 102 insertions(+), 60 deletions(-) create mode 100644 ch3/user/src/bin/00power_3.rs delete mode 100644 ch3/user/src/bin/00write_a.rs create mode 100644 ch3/user/src/bin/01power_5.rs delete mode 100644 ch3/user/src/bin/01write_b.rs create mode 100644 ch3/user/src/bin/02power_7.rs delete mode 100644 ch3/user/src/bin/02write_c.rs create mode 100644 ch3/user/src/bin/03sleep.rs diff --git a/ch3/user/src/bin/00power_3.rs b/ch3/user/src/bin/00power_3.rs new file mode 100644 index 0000000..1a04dc7 --- /dev/null +++ b/ch3/user/src/bin/00power_3.rs @@ -0,0 +1,28 @@ +#![no_std] +#![no_main] + +#[macro_use] +extern crate user_lib; + +const LEN: usize = 100; + +#[no_mangle] +fn main() -> i32 { + let p = 3u64; + let m = 998244353u64; + let iter: usize = 200000; + let mut s = [0u64; LEN]; + let mut cur = 0usize; + s[cur] = 1; + for i in 1..=iter { + let next = if cur + 1 == LEN { 0 } else { cur + 1 }; + s[next] = s[cur] * p % m; + cur = next; + if i % 10000 == 0 { + println!("power_3 [{}/{}]", i, iter); + } + } + println!("{}^{} = {}(MOD {})", p, iter, s[cur], m); + println!("Test power_3 OK!"); + 0 +} diff --git a/ch3/user/src/bin/00write_a.rs b/ch3/user/src/bin/00write_a.rs deleted file mode 100644 index 3303899..0000000 --- a/ch3/user/src/bin/00write_a.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![no_std] -#![no_main] - -use user_lib::{syscall::*, *}; - -const WIDTH: usize = 10; -const HEIGHT: usize = 5; - -#[no_mangle] -fn main() -> i32 { - for i in 0..HEIGHT { - for _ in 0..WIDTH { - print!("A"); - } - println!(" [{}/{}]", i + 1, HEIGHT); - sys_yield(); - } - println!("Test write_a OK!"); - 0 -} diff --git a/ch3/user/src/bin/01power_5.rs b/ch3/user/src/bin/01power_5.rs new file mode 100644 index 0000000..e47761b --- /dev/null +++ b/ch3/user/src/bin/01power_5.rs @@ -0,0 +1,28 @@ +#![no_std] +#![no_main] + +#[macro_use] +extern crate user_lib; + +const LEN: usize = 100; + +#[no_mangle] +fn main() -> i32 { + let p = 5u64; + let m = 998244353u64; + let iter: usize = 140000; + let mut s = [0u64; LEN]; + let mut cur = 0usize; + s[cur] = 1; + for i in 1..=iter { + let next = if cur + 1 == LEN { 0 } else { cur + 1 }; + s[next] = s[cur] * p % m; + cur = next; + if i % 10000 == 0 { + println!("power_5 [{}/{}]", i, iter); + } + } + println!("{}^{} = {}(MOD {})", p, iter, s[cur], m); + println!("Test power_5 OK!"); + 0 +} diff --git a/ch3/user/src/bin/01write_b.rs b/ch3/user/src/bin/01write_b.rs deleted file mode 100644 index 64bd665..0000000 --- a/ch3/user/src/bin/01write_b.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![no_std] -#![no_main] - -use user_lib::{syscall::*, *}; - -const WIDTH: usize = 10; -const HEIGHT: usize = 2; - -#[no_mangle] -fn main() -> i32 { - for i in 0..HEIGHT { - for _ in 0..WIDTH { - print!("B"); - } - println!(" [{}/{}]", i + 1, HEIGHT); - sys_yield(); - } - println!("Test write_b OK!"); - 0 -} diff --git a/ch3/user/src/bin/02power_7.rs b/ch3/user/src/bin/02power_7.rs new file mode 100644 index 0000000..a97d2f5 --- /dev/null +++ b/ch3/user/src/bin/02power_7.rs @@ -0,0 +1,28 @@ +#![no_std] +#![no_main] + +#[macro_use] +extern crate user_lib; + +const LEN: usize = 100; + +#[no_mangle] +fn main() -> i32 { + let p = 7u64; + let m = 998244353u64; + let iter: usize = 160000; + let mut s = [0u64; LEN]; + let mut cur = 0usize; + s[cur] = 1; + for i in 1..=iter { + let next = if cur + 1 == LEN { 0 } else { cur + 1 }; + s[next] = s[cur] * p % m; + cur = next; + if i % 10000 == 0 { + println!("power_7 [{}/{}]", i, iter); + } + } + println!("{}^{} = {}(MOD {})", p, iter, s[cur], m); + println!("Test power_7 OK!"); + 0 +} diff --git a/ch3/user/src/bin/02write_c.rs b/ch3/user/src/bin/02write_c.rs deleted file mode 100644 index 25464bf..0000000 --- a/ch3/user/src/bin/02write_c.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![no_std] -#![no_main] - -use user_lib::{syscall::*, *}; - -const WIDTH: usize = 10; -const HEIGHT: usize = 3; - -#[no_mangle] -fn main() -> i32 { - for i in 0..HEIGHT { - for _ in 0..WIDTH { - print!("C"); - } - println!(" [{}/{}]", i + 1, HEIGHT); - sys_yield(); - } - println!("Test write_c OK!"); - 0 -} diff --git a/ch3/user/src/bin/03sleep.rs b/ch3/user/src/bin/03sleep.rs new file mode 100644 index 0000000..8af47d4 --- /dev/null +++ b/ch3/user/src/bin/03sleep.rs @@ -0,0 +1,18 @@ +#![no_std] +#![no_main] + +#[macro_use] +extern crate user_lib; + +use user_lib::syscall::{sys_get_time, sys_yield}; + +#[no_mangle] +fn main() -> i32 { + let current_timer = sys_get_time(); + let wait_for = current_timer + 3000; + while sys_get_time() < wait_for { + sys_yield(); + } + println!("Test sleep OK!"); + 0 +}