Use static and for loop for printing Hello World

This commit is contained in:
Philipp Oppermann
2018-02-08 22:59:00 +01:00
parent cef44163bc
commit 7be59b571d
3 changed files with 32 additions and 29 deletions

View File

@@ -2,22 +2,21 @@
#![no_std] // don't link the Rust standard library
#![no_main] // disable all Rust-level entry points
//extern crate rlibc;
static HELLO: &[u8] = b"Hello World!";
#[no_mangle] // don't mangle the name of this function
pub fn _start() -> ! {
// this function is the entry point, since the linker looks for a function
// named `_start_` by default
let vga_buffer = 0xb8000 as *const u8 as *mut u8;
unsafe {
*vga_buffer.offset(0) = b'H';
*vga_buffer.offset(1) = 0xa; // foreground color green
*vga_buffer.offset(2) = b'e';
*vga_buffer.offset(3) = 0xa; // foreground color green
*vga_buffer.offset(4) = b'l';
*vga_buffer.offset(5) = 0xa;
*vga_buffer.offset(6) = b'l';
*vga_buffer.offset(7) = 0xa;
*vga_buffer.offset(8) = b'o';
*vga_buffer.offset(9) = 0xa;
for (i, &byte) in HELLO.iter().enumerate() {
unsafe {
*vga_buffer.offset(i as isize * 2) = byte;
*vga_buffer.offset(i as isize * 2 + 1) = 0xb;
}
}
loop {}