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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:40:15+00:00 2026-06-17T16:40:15+00:00

I am trying to understand control flow in 6502 assembly. Say I have the

  • 0

I am trying to understand control flow in 6502 assembly.

Say I have the following code:

    ControlFlow:
      lda mem
      cmp #1
      bne .sub_one

      cmp #2
      bne .sub_two

      .sub_one:
        ; sub routine one goes here
        jmp .done ; <-------------- without this jmp, .sub_two will execute

      .sub_two:
       ; sub routine two goes here

      .done:

      rts

Personally, I would love a switch statement or some other control flow structure.
The JMP above concerns me as well. It seems like there is a better way to handle
multiple cases without this type of spaghetti code.

  • 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-17T16:40:16+00:00Added an answer on June 17, 2026 at 4:40 pm

    There is no better way actually but there might be an improvement like calling the FlowControl as a subroutine and returning with RTS.

    This is the main flow.

      jsr ControlFlow
      ; main routine continues here
    

    Here is the sub routine.

    ControlFlow:
      lda mem
      cmp #1
      bne .sub_one
      cmp #2
      bne .sub_two
      cmp #3
      bne .sub_three
        ; case else here
      rts
    
      .sub_one:
        ; sub routine one goes here
      rts
    
      .sub_two:
       ; sub routine two goes here
      rts
    
      .sub_three:
       ; sub routine three goes here
      rts
    

    if sub routines are too long, you need to use JMPs as mentioned before.

    .jump_to_sub_one
      jmp .sub_one
    .jump_to_sub_two
      jmp .sub_two
    .jump_to_sub_three
      jmp .sub_three
    
    ControlFlow:
      lda mem
      cmp #1
      bne .jump_to_sub_one
      cmp #2
      bne .jump_to_sub_two
      cmp #3
      bne .jump_to_sub_three
        ; case else here
      rts
    
      .sub_one:
        ; sub routine one goes here
      rts
    
      .sub_two:
       ; sub routine two goes here
      rts
    
      .sub_three:
       ; sub routine three goes here
      rts
    

    That’s how it is done and unfortunately, there is no better way. This applies to many assembly languages if not all.

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

Sidebar

Related Questions

I am trying to understand how Parallelism is implemented in .Net. Following code is
I'm trying to control my code flow whit the Node.JS module called asyncblock, it
I'm trying to understand Inversion of Control and how it helps me with my
I am trying understand ViewModels deeper and I have read many articles and blogs
Trying to understand Ruby a bit better, I ran into this code surfing the
Trying to understand the math of this code snippet. A token is provided which
After trying to understand why client code is not rendered in a page (injected
I am trying to understand access control based on RBAC model. I referred to
I have been reading books trying to understand the various aspects of aggregation and
we have svn setup through Assembla with CI Team City. I understand source control,

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.