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 788511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:22:37+00:00 2026-05-14T21:22:37+00:00

I’m implementing a stack-based VM and I’ve been trying to read up on literature

  • 0

I’m implementing a stack-based VM and I’ve been trying to read up on literature that explains or outlines algorithms for dealing with stacks no no avail. Here’s an example:

int i = 3
int j = 4
int k = 5

Lets assume i, j, and k are local variables so they would be traditionally stored on the stack. The assembly/bytecode translation would look something like:

pushi 3
pushi 4
pushi 5

And the stack would be: 5 4 3

I have an integer stack and a string stack, hence the pushi, however my question is without storing these on the heap (with some ptr* or literal identifier), how would a compiler or interpreter know that if I want to do something like int x = i + j after the definition, I have to pop two and three times, respectively, as well as do my best not to lose k (save it in a register or something, then push it back)?

I hope my question made some sense and there’s probably a much smarter approach 😛 Thank you for any insight!

  • 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-14T21:22:37+00:00Added an answer on May 14, 2026 at 9:22 pm

    This is usually done with something called a stack frame. You allocate space for all local variables at once (modulo variables allocated/optimized into registers), store base address of that block, and operate on offsets from there. Then pop everything off the stack on scope exit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 399k
  • Answers 399k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Solution: lessThanTen(9). lessThanTen(8). lessThanTen(7). lessThanTen(6). lessThanTen(5). lessThanTen(4). lessThanTen(3). lessThanTen(2). lessThanTen(1).… May 15, 2026 at 3:57 am
  • Editorial Team
    Editorial Team added an answer SO uses prettify to syntax highlight the <code> snippets. Source:… May 15, 2026 at 3:57 am
  • Editorial Team
    Editorial Team added an answer Not the tool actually, but you could use Encapsulate Method… May 15, 2026 at 3:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.