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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:25:26+00:00 2026-06-11T21:25:26+00:00

The edit before the publish: So I kinda pretty much figured it all out

  • 0

The edit before the publish: So I kinda pretty much figured it all out on my own only AFTER I had the whole freakin’ question typed out and neatly arranged. So as not to work for nothing, I’m posting this anyways, asking if this is actually right, and asking for any suggestions/comments. I’m still not sure about one thing.

Alright, so I am a complete noob to computer science. Right now I am learning about assembly-language and machine language programming. This is a homework question so please help me understand, don’t throw answers in my face. I am trying to write a program that gets the sum of the numbers from 1 to 20 (the answer is 210) using branch on condition (a loop).

The Mnemonics used are:

L  for load  
A  for Add  
St for store  
BC for branch on condition  
C  for compare
CH for channel

There are 10 registers to put stuff into.

So basically I have to do 2 things: 1) Figure out a way to add up all numbers from 1 to 20 (1+2+3+4+5+6+7+8+9+…+20) which includes making a loop, AND 2) create a counter so it knows to stop when it gets to twenty. Is this right??

START    L  R1,COUNT
         A  R1,ONE
         ST R1,COUNT
         A  R2,COUNT
         C  R1,TWENTY
         BC  3,???
         ST R2,SUM
         CH SUM
         STOP
COUNT    DC F'0'
ONE      DC F'1'
TWENTY   DC F'20'
         END START

All this is saying: Load Register1 with contents of COUNT (which to begin with is 0). Add to Register1 contents of ONE (which is 1). Store this new number that’s in Register1 into COUNT. Add this new number to Register2. Compare contents of COUNT with contents of TWENTY (which is 20). Branch (/repeat) if the number inside COUNT is less than or equal to 20 (3 is the condition code). Once the counter reaches 20, the condition will be broken and the instruction will go to the next line which is: Store the number which is in Register2 (which should now be 210) into variable SUM. Then call CHannel to display contents of SUM on I/O device. Then STOP.

Now… I don’t know how to specify to branch/return back up to the beginning, so it repeats the process until the counter reaches 20. I’m also not sure if I should specify COUNT as 0 or not.

Thanks for any/all help.

  • 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-11T21:25:27+00:00Added an answer on June 11, 2026 at 9:25 pm

    A couple of things that I see. Since I have not tested this, I suggest that you test it yourself.

    You will need to initialize Register 2 so that as you add the value of Count, Register 2 starts with a known value.

    Typically a branch on condition requires that you specify the condition as well as a label to branch to if the condition is met. Not sure what your assembler requires for this.

    So I would consider the following changes. I have put comments on each line using two slashes similar to C. I assume that the Branch on Condition instruction has two operands, a condition operand that indicates which flags to test and an offset which the assembler calculates to a label. And I assume the AD instruction will set the condition flags which the BC instruction can then test. I put a 3 for the conditional flags to test for the BC instruction however I am not sure what the operand should actually be so I put a comment on that line.

    If your assembler allows adding two registers and has an XOR instruction allowing a register as an operand, you could just do away with the variable COUNT by doing XOR Register2 with itself and Register1 with itself to zero them out and to then do an ADD using the two registers. The XOR works because a one bit XORed with a one bit turns into a zero while a zero XORed with a zero stays a zero.

    The Branch on Condition, BC, instruction may or may not allow a backward branch. If it does not or if there is some kind of a constraint on it, you may have to have to use a jump or JMP instruction to go back to the top of the loop with a BC instruction before the jump to branch over the JMP once the COUNT reaches 20.

    START    L  R2,COUNT    // initialize Register 2 to zero as Count starts with zero
             L  R1,COUNT    // initialize Register 1 to zero as Count starts with zero
    LOOP     A  R1,ONE      // add one as part of incrementing Count for the next sequence
             ST R1,COUNT    // save current Count back.
             A  R2,COUNT    // add the current value of Count into Register 2 for the sum
             C  R1,TWENTY   // compare Register 1, Count, to end of loop condition
             BC 3,LOOP      // branch if less than back to loop.  if 20 we are done.
             ST R2,SUM
             CH SUM
             STOP
    COUNT    DC F'0'
    ONE      DC F'1'
    TWENTY   DC F'20'
    SUM      DC F'0'
             END START
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need edit my Images before they import to the app but after editing
I create an audio buffer and want to edit this before I play this
In Prelude, > :load foo.hs > -- before edit > :edit foo.hs ... Edit
I used to edit Web.config before in order to allow some users to access
Do I need to call edit SharedPreferences everytime before I change the preferences and
i am trying to edit a select list every time the list before it
EDIT: You can see the search box live here . Before I explain, let
So, I have this code in a controller: before_filter :require_login, :only => :new, :edit,
EDIT: I was an idiot. I simply had an image that was vertically long,
EDIT BEFORE YOU READ: Sorry.. I didn't add newline so it appeared jumbled, I

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.