Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Parsing through instructions

by GrandFather (Saint)
on Apr 08, 2012 at 22:14 UTC ( [id://964039]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Parsing through instructions
in thread Parsing through instructions

So the key information you need is that you need to use the bit operators to manipulate the bits in each byte to extract the interesting bit fields. In particular use & (bitwise and) and a bit mask to isolate bit fields, and use the bitwise shift operators >> and << to move fields of bits about. For example, to isolate the op code you'd do something like:

use strict; use warnings; my $byte = 0b00100100; my $opCode = ($byte & 0b11100000) >> 5; printf "Opcode is 0x%02X\n", $opCode;

Prints:

Opcode is 0x01

See perlop for details about the various Perl operators.

True laziness is hard work

Replies are listed 'Best First'.
Re^4: Parsing through instructions
by DaveMonk (Acolyte) on Apr 08, 2012 at 23:57 UTC
    Awesome man, but I still need some help figuring out how to do this for the other 8 instructions, and then run it (the asm code) and dump to a file. But I have been playing around with perlop :)

      There is nothing more I can tell you that wouldn't amount to writing the code for you. If you can't take it from here then you have been set a task that you are not currently equipped to handle. The rest of the problem is really just applying the mask and shift I've already demonstrated to get at the individual op code fields, and then process the data.

      I suggest you play for a while and generate some code of your own. If you are still struggling show us what you have written along with your input data (the sample data you showed already is very unlikely to be real) and the expected output, then describe how it doesn't work for you.

      True laziness is hard work
        Ok thanks man, I will get to work on it :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://964039]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-19 16:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found