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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:57:02+00:00 2026-06-10T06:57:02+00:00

I’ve a very precise specification for an assembly subroutine: Specification Name: The subroutine must

  • 0

I’ve a very precise specification for an assembly subroutine:

Specification

Name: The subroutine must be called hexasc. Input parameters: Only
one, in register r4. The 4 least significant bits in register r4
specify a number, from 0 through 15. The values of all other bits in
the input must be ignored. Return value: Only one, returned in
register r2. The 7 least significant bits in register r2 must be an
ASCII code as described below. All other bits in the output must be
zero. Required action: Input values 0 through 9 must be converted to
the ASCII codes for the digits ‘0’ through ‘9’, respectively. Input
values 10 through 15 must be converted to the ASCII codes for the
letters ‘A’ through ‘F’, respectively. Side effects: The values in
registers r2 through r15 may be changed. All other registers must have
unchanged values when the subroutine returns.

I might know how to make a subroutine but I never did that before. I don’t know how to specify the 4 least significant bits from a register. I don’t know how to return values. I’m just getting started with assembly programming and I can run but not really write programs. Could you guide me with some helpful hints? The processor manual is available here.

The best I can propose, all which Ido not understand since I borrowed some of this code from the internet, is

        .global main 

        .text
        .align 2

main:   movi r8, 0x09
        movi r9, 0x0f

        andi r4, r4, 0x0f

        bgt r8, r4, L1  

        movi r2, 0x1e
        add r2, r2, r4  
        andi r2, r2, 0xff

        movia   r2,putchar
        br  L2  

L1:     movi r2, 0x29   
        add r2, r2, r4
        andi r2, r2, 0xff

        movia   r2,putchar

L2:  .end 

I’ve commented the code but I think it is not according to spec since it is not a subroutine and I’m not sure whether the conversion algorithm is implemented correctly:

        .global hexasc 

        .text
        .align 2

hexasc: movi r8, 0x09       #we are going to use the decimal number 9
        movi r9, 0x0f       #we also will use decimal number 15

        andi r4, r4, 0x0f   #keep only last 4 bits of what is in r4

        bgt r8, r4, L1      #go to L1 if 9 > x

        movi r2, 0x1e       #use decimal number 30
        add r2, r2, r4      #add 30 and what is in r4
        andi r2, r2, 0xff

        movia   r2,putchar
        br  L2  

L1:     movi r2, 0x29        #this is reached iff 9 > x
        add r2, r2, r4
        andi r2, r2, 0xff

        movia   r2,putchar

L2:  .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-10T06:57:03+00:00Added an answer on June 10, 2026 at 6:57 am

    Since this is homework it’s your own task to write code, but maybe this can help you:

    If you have a register of arbitrary size, and want only specific bits from it, consider AND-ing with a mask. For example, for the 7 least significant bits

    11111101 AND 01111111 => 01111101
    

    Regarding I don’t know how to return values, the answer is written in your assignment:

    Return value: Only one, returned in register r2

    Simply store whatever you want to return in register r2 before your routine ends.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.