TRAP (processor instruction)
Encyclopedia
TRAP is an instruction command in the LC-3
LC-3
Little Computer 3, or LC-3, is a type of computer educational programming language, an assembly language, which is a type of low-level programming language. It features a relatively simple instruction set, but can be used to write moderately complex assembly programs, and is a theoretically viable...

 (Little Computer 3) assembly
Assembly (programming)
An assembly is a runtime unit consisting of types and other resources. All types in an assembly have the same version number.Often, one assembly has only one namespace and is used by one program. But it can span over several namespaces. Also, one namespace can spread over several assemblies...

 language that consists of a set of basic service routines
Interrupt handler
An interrupt handler, also known as an interrupt service routine , is a callback subroutine in microcontroller firmware, operating system or device driver whose execution is triggered by the reception of an interrupt...

 to simplify operations. Each service routine created with a combination of other basic operations in the LC-3 instructions set. Although a user can reconstruct these service routines
Interrupt handler
An interrupt handler, also known as an interrupt service routine , is a callback subroutine in microcontroller firmware, operating system or device driver whose execution is triggered by the reception of an interrupt...

, the TRAP instruction is available for advanced users.

Using TRAP

TRAP is a reference table to different routines; this means that when using the instruction, you must also declare a vector (reference identity) with it. To calling a TRAP function, in the hex file code, type the hex value of 0xF0ZZ (ZZ being the TRAP vector value for the specific sub routine you wish to use).

TRAP service routines (possible values for ZZ)

TRAP Vector: x20

Assembly name: GETC
C file input/output
The C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header...



Description: waits for the keyboard interrupt and reads a single character and converts the key value into an ASCII character. The character is not echoed to the console screen, it is simply read and stored into a register.

TRAP Vector: x21

Assembly name: OUT

Description: writes the character currently in R0 from the GPR (General Purpose Registers) onto the console display.

TRAP Vector: x22

Assembly name: PUTS

Description: prints an array of characters or string onto the console window. The address of the first character is stored in R0 of the GPRs; each register holds two characters and the data is converted into ASCII before printing to the screen. Printing continues following the path of the string until the program finds consecutive data reading 0x0000.

TRAP Vector: x23

Assembly name: IN

Description: this command is similar to the GETC command. This command is more user-friendly, though this command is more time consuming. It tells the user to input a character and that single character is echoed back to the screen and is also stored into R0 as an ASCII value in the GPRs.

TRAP Vector: x24

Assembly Name: PUTSP

Description: this command is used for recording input strings, each register will hold a pair of characters and the address of the first character is stored in R0. The user writes into the console and the program stores the characters into an array. Writing terminates with the occurrence of 0x0000 in the memory location.

TRAP Vector: x25

Assembly Name: HALT
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...



Description: this routine is used for ending programs, instead of terminating the program, it simply stops execution by the use of a forever loop
Infinite loop
An infinite loop is a sequence of instructions in a computer program which loops endlessly, either due to the loop having no terminating condition, having one that can never be met, or one that causes the loop to start over...

.

REFERENCE pages

  • http://ftp.csci.csusb.edu/georgiou/lab/lab.pdf
  • http://www.lc3help.com/tutorials/Getting_User_Input/
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK