-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Description
I write this code:
pub fn clean(x:isize){
unsafe{
let mut buffer=0xb8000 as *mut u8;
let mut y=0;
while y<(80 * 25 * 2){
let mut p=buffer.offset(y);
*buffer.offset(y)=0x00;
y=y+1;
*buffer.offset(y)=0x20;
y=y+1;
}
}
}
and compile: "cargo build --release"
Disassembling views this:
000000e0 <__ZN6memory5clean17h43e2ddeb8148e2edE>:
push %ebp
mov %esp,%ebp
movaps 0x0,%xmm0
xor %eax,%eax
nopl 0x0(%eax)
movups %xmm0,0xb8010(%eax,%eax,1)
movups %xmm0,0xb8000(%eax,%eax,1)
add $0x10,%eax
cmp $0x7d0,%eax
jne f0 <__ZN6memory5clean17h43e2ddeb8148e2edE+0x10>
pop %ebp
ret
It's not correct code.
But when I write
y=y+x; //x is argument equal 1
instead of
y=y+1;
it produce this asm:
000000e0 <__ZN6memory5clean17h43e2ddeb8148e2edE>:
push %ebp
mov %esp,%ebp
push %esi
mov 0x8(%ebp),%eax
mov $0xb8000,%ecx
xor %esi,%esi
lea 0xb8000(%eax),%edx
data16 data16 nopw %cs:0x0(%eax,%eax,1)
movb $0x0,(%ecx,%esi,1)
movb $0x20,(%edx,%esi,1)
add %eax,%esi
add %eax,%esi
cmp $0xfa0,%esi
jl 100 <__ZN6memory5clean17h43e2ddeb8148e2edE+0x20>
pop %esi
pop %ebp
ret
which is really correct.
Rustc version:
$ rustc -vV
rustc 1.22.1 (05e2e1c 2017-11-22)
binary: rustc
commit-hash: 05e2e1c
commit-date: 2017-11-22
host: i686-pc-windows-gnu
release: 1.22.1
LLVM version: 4.0