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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:31:11+00:00 2026-05-20T06:31:11+00:00

So, I have finished an assembly program that asks for a character, reads it,

  • 0

So, I have finished an assembly program that asks for a character, reads it, echos it, repeats that four times, then prints out those characters in a consecutive string. I then wanted to experiment with subroutines (which we haven’t learned about in class yet), so I made the following subroutine to print a newline character to the console:

PRINT_NEWLINE                         ;procedure to print a newline
  AND   R0,R0,#0                      ;clear output register
  LD    R0,NEWLINE                    ;load newline into output regiester
  TRAP  x21                           ;print it out
  RET                                 ;jump to address in R7

It gets “called” like this:

JSR PRINT_NEWLINE

After running this, I noticed something weird, the program seemed to stop after the first call to PRINT_NEWLINE. Then I realized that TRAP saves the address of the next instruction, which in this case is RET, in R7, the register used for subroutine linking. This overwrites the address which was saved in R7 by JSR. So the reason it appears to stop is that after the TRAP routine finishes, it loads my RET instruction. Which is actually, because of the TRAP, changing the pc counter to itself. Sort of like an infinite loop.

That’s all great, and I understand what’s going on, but is there a way I can use system TRAP routines inside of my subroutine, while still using the system JSR instruction?

I could, of course, manually store the address of the instruction after the JSR PRINT_NEWLINE call into a different register, and then at the end of my PRINT_NEWLINE subroutine, JMP to the address in that register.

But, that seems wrong to me and, I’m a programmer, therefore I’m lazy, and would rather just enjoy the fruits of other’s labor and use the combination of JSR and RET.

So is it possible to call a TRAP routine in a subroutine and still use RET to “return” from that subroutine? How would one accomplish this?

Thanks!

  • 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-20T06:31:11+00:00Added an answer on May 20, 2026 at 6:31 am

    You will need to save the value of R7 somewhere else before calling TRAP and restore it afterward. You will need to do that for nested subroutine calls as well. Most RISC architectures require some form of return address saving by the user; they do not implement a memory stack in hardware like x86 processors do.

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

Sidebar

Related Questions

So I am just starting out developing PHP web applications and have finished setting
I have a script that needs to run after tomcat has finished starting up
I need to delete my input file securely once I have finished with it,
I have finally finished my web site. I published it, and I was surprised
I have pretty much finished my first working Symbian application, but in my hastened
I'm trying to make a PHP script, I have the script finished but it
I just finished reading this post: https://developer.yahoo.com/performance/rules.html#flush and have already implemented a flush after
Suppose I have two threads A and B that are both incrementing a ~global~
Once you have finished/reintegrated a branch, is it best practice to delete the branch
Have just started using Google Chrome , and noticed in parts of our site,

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.