Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:51:34+00:00 2026-05-27T01:51:34+00:00

Creating Your Own Abstract Processor is a quick paper on what I am trying

  • 0

Creating Your Own Abstract Processor is a quick paper on what I am trying to do.

http://malcon.org/ctm.rar is the exact specifications on what the emulator should be.

I am writing a sort of an emulator in Perl. This program will read in a binary file and process the hex of the binary into actions, how a processor works, but software based with different opcodes. Just a challenge thing.

Anyhow, I am not entirely sure how to read the binary file into an array and then assign the hex from the array to the opcodes. This is part of my code:

my $opcode='';
my $file= "path/to/file";
my $IP=0;
my $SP=0;
my $FLAG=0;
my $A=0;
my $B=0;
my $X=0;
my @STACK=(0);

open(F, "<".$file) || die("Could not open file");
binmode(F);
my @ROM = <F>;
close(F);

while($IP >= 0)
{
    $opcode="$ROM[$IP]";
    if ($opcode eq 11) {
        $A = $STACK[$SP];
        $IP++;
    }
    if ($opcode eq 12) {
        $B = $STACK[$SP];
        $IP++;
    }
    if ($opcode eq 13) {
        $A = $B;
        $IP++;
    }
    if ($opcode eq 14) {
        $B = $A;
        $IP++;
    }

This is just the part of the code I need help with. If you need to see more of it for some reason, just let me know.

So I changed my code to reflect an answer above, my code now looks like this:

my $opcode='';
my $file= "CTM-bootrom";
my $IP=0;
my $SP=0;
my $FLAG=0;
my $A=0;
my $B=0;
my $X=0;
my @STACK=(0);

open my $ROM, '<:raw', $file or die "Cannot open '$file': $!";

{
    local $/ = \1; # Read one byte at a time
    while (my $byte = <$ROM>){
        while($IP >= 0)
        {
            $opcode=$ROM[$IP];
            if ($opcode eq 11) {
                $A = $STACK[$SP];
                $IP++;
            }
            if ($opcode eq 12) {
                $B = $STACK[$SP];
                $IP++;
            }
            if ($opcode eq 13) {
                $A = $B;
                $IP++;
            }

But now I get an error:

Use of uninitialized value $opcode in string eq at Aod8.pl line 73,

<$ROM> to me it looks like opcode is initialized… How can I fix this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:51:35+00:00Added an answer on May 27, 2026 at 1:51 am

    I got it now…everything is now working like needed:

    my $IP=0;
    my $FLAG=0;
    my $SP=0;
    my $A=0;
    my $B=0;
    my @STACK=(0);
    my $byte=0;
    $| = 1;
    
    open(BOOTROM, "<bootrom.txt");
    binmode(BOOTROM);
    
    my (@ROM, $instruction);
    while ((read BOOTROM, $instruction, 1) != 0) {
        @ROM[$IP] = $instruction;
        $IP++;
    }
    close(BOOTROM);
    
    $IP = 0;
    while ($IP >= 0 && $byte != 0x3C) {
        $byte = ord(@ROM[$IP]);
    
        if ($byte == 0x11) {
            $A = (@STACK[$SP]);
            $IP++;
        }
        elsif ($byte == 0x12) {
            $B = (@STACK[$SP]);
            $IP++;
        }
        elsif ($byte == 0x13) {
            $A = $B;
            $IP++;
        }
        elsif ($byte == 0x14) {
            $B = $A;
            $IP++;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following a tutorial here http://www.blackweb20.com/2010/01/11/creating-your-own-google-chrome-extension/ I can open fine a tab with
Is there a generic way, without creating and managing your own CLR host, to
With iPhone, creating your own AppFramework is made impossible by the fact that Apple
Are there more extension points available in linq-to-sql than creating your own partial DataContext
Does anyone have any resources about creating your own tab control without using jQuery
I'm trying to follow the custom module tutorial at http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/modules-and-namespaces/creating-your-own-modul I've got a local
The CoreData documentation says You can sometimes benefit from creating your own unique ID
I saw an example of using Expression Builders, and creating your own Custom Expression
I'm just starting with the django creating your own app tutorial (creating a Poll)
This is a followup to another question I asked abou creating your own hooks.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.