i am writing a vm in rust so i just need code review am i going right or not .????
A browser interface to the Rust compiler to experiment with the language
40 messages · Page 1 of 1 (latest)
i am writing a vm in rust so i just need code review am i going right or not .????
A browser interface to the Rust compiler to experiment with the language
i am following the little endian format
#[repr(u8)]
pub enum OPCode{
Nop=0x0001,
LoadImm=0x0002,
}
that is a bit silly
1 byte is 2 hexadecimal digits
not 4
i see
_=>Err(format!("uknown op code 0x{0:X}",ins))
``` this arm is unreachable (without going through undefined behavior)
yeah the whole transmute is just direct ub
like my instruction is load Ro , 15 so 8 bits are taken by op code and rest 4,4 by imm value and reg but i need to store more than 4 bit imm values
you should use the little endian utilities from std
such as .???
i see
The 16-bit unsigned integer type.
any healp for this
like my instruction is load Ro , 15 so 8 bits are taken by op code and rest 4,4 by imm value and reg but i need to store more than 4 bit imm values
also you really should not use as except maybe for enum casts, and even then probably not
you code is a great example of why as is bad
you freely mix truncating and non truncating casting with no sign of which is which
ig reg could be 3 bits ?
if you never add any more values
otherwise you'll just need to use more bytes
umm for what part are you specifically talking about
also what should i do insted
you should remove all ass. maybe keep 1 in a functon specifically for that
let upper_bits = (byte & 0xff00) as u8;
you got this
that's litterally always 0
yeah i fixed that
you should use from where it is available
let upper_bits = ((byte >>8) &0xff) as u8;
and other methods where possible
that's just silly though
let [upper_bits, lower_bits] = byte.to_be_bytes();
also calling byte a u16 is weird, but i shouldn't judge naming
actually i am very confused about writing vm like how to impl these ive already implemeted chip -8 it was easy cause it had its docs and specification specified
so i was able to think clearly
is this a VM for a specific existing system, or are you designing your own ISA and system?