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

  • SEARCH
  • Home
  • 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 8712273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:04:37+00:00 2026-06-13T05:04:37+00:00

I am currently working on a c++ compiler for my Logisim CPU in JS,

  • 0

I am currently working on a c++ compiler for my Logisim CPU in JS, and have now a problem with variables:

I have defined a space in ram to store data/values, and I have defined a space to store addresses to the data space. I have a register nx with a pointer to the last variable, and a register mx with a pointer to the last “data-storage” RAM. But I do not know how to access them, e.g. here:

modified C++ Code:

int *pointer_test;
int test;
test = 123;
pointer_test = &test;
*pointer_test = 25;

Pre-Assembler:

//Allocate new variable       <---  int *pointer_test;
add nx, 1
//Set the pointer pointing to zero
sram nx, 0


//Allocate another variable   <---  int test;
add nx, 1
//Allocate new storage for the variable
add mx, 1

//Let the variable point to the data <--- test = 123;
sram nx, mx
sram mx, 123

How do I implement now:

pointer_test = &test; 

I have only the value of &test, saved in nx because it is the last variable declared, but not the address of the variable/pointer “pointer_test” …

  • 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-06-13T05:04:38+00:00Added an answer on June 13, 2026 at 5:04 am

    You probably want to write stack based assembly, like every other C compiler in the last 20 years. What that means is that there is a data area in RAM called the stack, which is a FIFO queue, that grows down. Stacks also always involve at least one register: the stack pointer. The stack pointer points at the current place in the stack where the next thing will go. So, to add something to the stack, you put it where the stack pointer points, and then subtract the size of that thing from the stack pointer.

    Another register that is used most often in assembly that comes from C is the base pointer. The base pointer points at the beginning of the current frame. A frame can be roughly compared to a scope in C. So, if I have this code:

    int a;
    {
      int b;
    }
    

    And a stack that’s top is at 0x9999, then a will be at 0x9995 (assuming 4 byte int), with the stack pointer now pointing at 0x9991, and the base pointer still at 0x9999. When the new scope is entered, the base pointer is moved to the stack pointer, and then B is put at 0x9991. Then, when the scope is exited, the stack pointer is set to the base pointer, effectively erasing the variables in the lower scope.

    I’ve never heard of the architecture you’re programing for, but just know that any two registers will do, but some architectures, like x86, have specific stak registers (ebp, esp on 32 bit and reb and rsp on 64 bit).

    But to answer the question a little more, it is the compiler’s job to know what offset into the stack each variable is, so it can do things like (pseudocode):

    base_pointer - 5 (Offset for pointer_test) = base_pointer - 4 (offset for test)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a compiler for a language (an external byte-code), and am
I'm currently working with the Diab 4.4 C++ compiler. It's a total POS, non
Currently working with the following package structure: /package __init__.py final.py /write __init__.py write.py /data
I am currently working on a compiler under C and I am abit lost
I'm working in a Linux environment with C++, using the GCC compiler. I'm currently
i am currently working on a C++ project where i have an abstract interface
I'm currently working on the 58 th problem from Project Euler . While my
I'm currently working on a problem that involves System.Reflection.Emit code generation. I'm trying to
Greetings to all the compiler designers here on Stack Overflow. I am currently working
I'm currently working on kind of compiler that was built making use of sablecc

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.