0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

wslでrust その9

Last updated at Posted at 2024-11-14

概要

wslでrustやってみた。
練習問題やってみた。

練習問題

インラインアセンブラを実行せよ。

方針

  • cpuidを取得してみる。

サンプルコード

use std::arch::asm;

fn main() {
	let mut name_buf = [0_u8; 12];
	unsafe {
		asm!(
			"push rbx",
			"cpuid",
			"mov [rdi], ebx",
			"mov [rdi + 4], edx",
			"mov [rdi + 8], ecx",
			"pop rbx",
			in("rdi") name_buf.as_mut_ptr(),
			inout("eax") 0 => _,
			out("ecx") _,
			out("edx") _,
		);
	}
	let name = core::str::from_utf8(&name_buf).unwrap();
	println!("CPU Manufacturer ID: {}", name);
}

実行結果

$ rustc asm0.rs
$ ./asm0
CPU Manufacturer ID: GenuineIntel

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?