1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: LC-3 Assembly Code Error detection

  1. Apr 1, 2012 #1
    1. The problem statement, all variables and given/known data

    What is wrong with the code fragment:
    .ORIG x3000
    AND R0,R0, #0
    AND R2,R2, #0
    ADD R2,R2, #7
    ADD R2,R2, ASCII
    ADD R0,R2,#0
    TRAP x21
    SUB ADD R2,R2,#9
    ADD R7,R7,#1
    ASCII .FILL x0030

    3. The attempt at a solution

    Ok, so first we ckear some register values. Then we set R2 to 7. Next we go into a subroutine that adds 9 to R2, so now R2 is 16. Then we add 1 to R7, which has an unknown value at the start. Then we return to the command after JSR. This adds the value in ASCII to R2, making R2 64. Then we set R0 to 64 as well, and finish by executing Trap x21.

    I don't know what the problem here is, nor what the output is. I think Trap x21 does something with the keyboard to monitor, but I'm not sure.
  2. jcsd
  3. Apr 1, 2012 #2


    User Avatar
    Homework Helper

    Trap x21 outputs to the monitor, then returns. R7 is used for the return address. What is going to happen with your program when trap x21 returns?

    link to lc-3 instruction set pdf:


    link to assembly language pdf:


    link to lc-3 trap pdf:


    link to another description of the instruction set:

    Last edited: Apr 1, 2012
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook