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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:52:50+00:00 2026-06-13T12:52:50+00:00

I am writing a program for one of my classes in assembly(pep8). The program

  • 0

I am writing a program for one of my classes in assembly(pep8). The program is supposed to take in an integer between -32,768 and 32,767, and output its binary equivalent. The code below accomplishes the task except it prints the binary number backwards.

Is there an elegant way for me to print the binary number in the correct order (ie I DONT want to store every binary digit in a local variable and then print them in reverse order).

        BR main
int:             .EQUATE 0                ;local variable int
out:             .EQUATE 2                ;local variable out
index:           .EQUATE 4                ;local variable index
stack:           .EQUATE 6                ;local variable for dynamic memory allocation



main:            SUBSP       stack,i      ;allocate memmory
                 LDA         0,i          
                 STA         index,s      ;initialize index
                 DECI        int,s        ;get user input and store it in num 
while:           LDA         index,s      ;while (num <= 16)
                 CPA         16,i         ;
                 BRGE        endWhile     ;
                 ADDA        1,i          ;index++
                 STA         index,s      ;
                 LDA         int,s        ;
                 ANDA        0x0001,i     ;modulus 2 "%2"
                 STA         out,s        ;
                 DECO        out,s        ;output results 
                 LDA         int,s        ;
                 ASRA                     ;devide num by 2
                 STA         int,s        ;

                 BR          while        ;
endWhile:        ADDSP       stack,i      ;deallocate memmory
                 STOP
                 .END
  • 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-13T12:52:51+00:00Added an answer on June 13, 2026 at 12:52 pm

    I am not familiar with this particular kind of assembly, but printing out a binary is relatively easy in all architectures if you shift values left, and check the carry flag C.

    When you shift a register left, its most significant bit ends up in C. Now set another register to zero, and rotate it left immediately after shifting the source value left. The most significant bit of the original value is now in the least significant bit of the register:

    Register   C   Value
    --------   -   --------
    00000000   x   11001010 // Initially
    00000000   1   10010100 // After left-shifting the value
    00000001   0   10010100 // After left-rotating the register
    

    Output the register, set it back to zero, and continue on. This will output the bits in the correct order.

    Note that this trick is available only to assembly programmers. It is inaccessible to C/C++ programmers, because the carry flag C is out of their reach.

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

Sidebar

Related Questions

I'm writing a program that for one part asks for the program to print
i am writing a C program and one of the issues i have is
I am currently writing a program using Weka that builds a model (using one
I am writing a GUI program. In one part of it I show an
I'm writing a simple program to convert text to strings. One quick question, how
I'm writing a ruby program that has 2 threads. One that listens on an
I'm writing a simple program. There is only one class in it. There is
I'm writing a custom text-to-speech program that uses SAPI 5, and one problem I'm
I am on MacOSX. I am writing a multi threaded program. One thread does
For a program i'm writing I need to marshal ActionScript classes to a format

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.