Skip to content

Commit

Permalink
examples: simplify write_bytes in hello world example
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Jan 16, 2025
1 parent f0fbd92 commit b9a7dd9
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions examples/no-std/hello-world/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,13 @@ fn write_bytes(bytes: &[u8]) {
return;
}

let mut word = bytes[0] as u64;

for i in 1..bytes.len() {
if i % 8 == 0 {
// XXX(qix-): Hard coding the ID for a moment, bear with.
syscall::set!(
ROOT_DEBUG_OUT_V0,
4294967296,
0,
syscall::key!("write"),
word
)
.unwrap();
word = 0;
for chunk in bytes.chunks(8) {
let mut word = 0u64;
for b in chunk {
word = (word << 8) | *b as u64;
}

word = (word << 8) | bytes[i] as u64;
}

if bytes.len() % 8 != 0 {
// Shift it the remaining bits.
word <<= 8 * (8 - (bytes.len() % 8));
// XXX(qix-): Hard coding the ID for a moment, bear with.
syscall::set!(
ROOT_DEBUG_OUT_V0,
4294967296,
Expand Down

0 comments on commit b9a7dd9

Please sign in to comment.