TRAP (processor instruction)

TRAP is an instruction command in the LC-3 (Little Computer 3) educational assembly language that consists of a set of basic service routines to simplify operations. Each service routine is created with a combination of other basic operations in the LC-3 instructions set. Although a user can reconstruct these service routines, 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 call 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

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

Description: this routine is used for ending programs, instead of terminating the program, it simply stops execution by the use of a forever loop.

REFERENCE pages

This article is issued from Wikipedia - version of the Thursday, October 22, 2015. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.