LC-3 Assembly Code Error detection

In summary, the conversation discusses a code fragment with instructions for the LC-3 instruction set. The code initializes register values, adds 7 to R2, enters a subroutine to add 9 to R2, returns and adds the value in ASCII to R2, sets R0 to the same value, and executes trap x21. The purpose of trap x21 is to output to the monitor, and R7 is used as the return address. The conversation also provides links to resources for understanding the LC-3 instruction set and assembly language.
  • #1
elec_is_gross
1
0

Homework Statement



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

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.
 
Physics news on Phys.org
  • #2
elec_is_gross said:
I think Trap x21 does something with the keyboard to monitor, but I'm not sure.
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:

http://classes.soe.ucsc.edu/cmpe012/Summer09/notes/06_LC3_ISA_and_Addressing_Modes.pdf

link to assembly language pdf:

http://classes.soe.ucsc.edu/cmpe012/Winter09/lectures/06_LC3_Assembly.pdf

link to lc-3 trap pdf:

http://classes.soe.ucsc.edu/cmpe012/Summer08/notes/11_LC3_TRAP_markup.pdf

link to another description of the instruction set:

http://www.scribd.com/doc/4596293/LC3-Instruction-Details
 
Last edited:

FAQ: LC-3 Assembly Code Error detection

1. What is LC-3 Assembly Code Error detection?

LC-3 Assembly Code Error detection is a process used in computer programming to identify and correct errors in LC-3 assembly code. The LC-3 is a simplified computer architecture used for educational purposes, so error detection is important for ensuring the accuracy and functionality of programs written in this language.

2. How does LC-3 Assembly Code Error detection work?

LC-3 Assembly Code Error detection involves using a program called a simulator to run the assembly code and identify any errors. The simulator analyzes the code and flags any potential errors, such as syntax errors or logical errors. The programmer can then go back and correct these errors before running the code on an actual LC-3 computer.

3. What are some common errors in LC-3 Assembly Code?

Some common errors in LC-3 Assembly Code include syntax errors, such as misspelled commands or missing punctuation, and logical errors, where the code does not produce the desired output. Memory errors, such as attempting to access a memory address that is out of bounds, are also common in assembly code.

4. How important is error detection in LC-3 Assembly Code?

Error detection is crucial in LC-3 Assembly Code as it ensures the accuracy and functionality of the program. The LC-3 architecture does not have built-in error detection mechanisms, so it is up to the programmer to identify and correct errors before running the code on a physical LC-3 computer.

5. Are there any tools or resources available for LC-3 Assembly Code Error detection?

Yes, there are various tools and resources available to assist with LC-3 Assembly Code Error detection. These include simulators, debuggers, and online forums or communities where programmers can seek help and advice from others experienced in LC-3 programming. It is essential to use these resources to ensure the accuracy and functionality of LC-3 assembly code.

Back
Top