====================================================================== A SUMMARY OF TTK-91 COMMANDS ====================================================================== +--------------------------------------------------------------------+ ¦ Operation code ¦ Rj ¦ M ¦ Ri ¦ address part ADDR ¦ ¦ 8 bits ¦ 3 ¦ 2 ¦ 3 ¦ 16 bits ¦ +--------------------------------------------------------------------+ 31 24 23 16 15 0 In the symbolic machine language, the commands are of the form LABEL OPER Rj,M ADDR(Ri) where OPER the symbolic name of the command Rj the first operand (register R0..R7) M addressing mode: = immediate operand direct addressing (empty, ie. not marked) @ indirect addressing ADDR address part (memory address or constant value) Ri possible index register (register R0..R7) If some part of a command has no meaning, it can be left out. It is possible to add a label (symbolic address) in front of a command. The label should consist of the letters A-Ö, 0-9 and _, and contain at least one non-numerical character. Only the first 8 characters are considered. Almost all commands have the following forms available: OPER Rj,ADDR direct memory addressing OPER Rj,=ADDR immediate operand OPER Rj,@ADDR indirect memory addressing OPER Rj,ADDR(Ri) indexed addressing OPER Rj,=ADDR(Ri) indexed immediate operand OPER Rj,@ADDR(Ri) indexed indirect memory addressing OPER Rj,Ri direct register addressing There are exceptions: STORE The latter operand is always the target address; it cannot be a register or a constant value. POP The latter operand must always be a register. JUMP COMMANDS The latter operand is always the target address; it cannot be a constant. In the jump commands which look at the state register, the first operand is ignored. NOT First operand always register, 2nd operand ignored NOP The operands are ignored. ====================================================================== The symbolic commands of the TTK-91 machine language ====================================================================== Data transfer commands: LOAD Stores the value of the latter operand to the register Rj. STORE Stores the integer in Rj as the value of the latter operand. IN Reads an integer from the device given as the latter operand into the register Rj (eg. IN R1,=KBD to read from the keyboard). OUT Outputs the integer in the register Rj to the device given as the latter operand (eg. OUT R1,=CRT to print to screen). Arithmetic and logical commands: The result of the calculation is stored in register Rj. ADD Adds the value of the latter operand to the integer in the register Rj. SUB Substracts the value of the latter operand from the integer in the register Rj. MUL Multiplies the integer in the register Rj with the value of the latter operand. DIV Divides the integer in the register Rj with the value of the latter operand, and stores the whole part in Rj. MOD Modulo divides the integer in the register Rj with the value of the latter operand, and stores the remainder in Rj. AND Boolean logic 'and' between Rj and the value of the latter operand. OR Boolean logic 'or' between Rj and the value of the latter operand. XOR Boolean logic 'exclusive or' between Rj and the value of the latter operand. NOT Inverts all bits in register Rj SHL Shifts the bits of the register Rj left, with the number of shifts given by the value of the latter operand. Fills the right end with 0 bits. SHR Shifts the bits on the register Rj right, otherwise like SHL. SHRA Performs an arithmetic right shift; as in SHR, but fills the left end with copies of the leftmost bit, thus keeping negative numbers negative. COMP Compares the first operand with the second operand and stores the result in the status register SR's bits L=less, E=equal, G=greater. See eg. JLES. Forking commands: JUMP An unconditional jump to the target address expressed by the second operand. JNEG Jump if negative. If Rj < 0, jumps to the address given as the second operand, otherwise continues with the next command. JZER Jump if zero, ie. if Rj = 0 JPOS Jump if positive, if Rj > 0 JNNEG Jump if not negative, if Rj >= 0 JNZER Jump if not zero, if Rj <> 0 JNPOS Jump if not positive, if Rj <= 0 JLES Jump if less - if the status register SR has its L bit set, jumps to the address given as the second operand, otherwise continues from the next command. Used together with the COMP command. JEQU Jump if equal, ie. if E bit is set in SR JGRE Jump if greater, if G bit is set in SR JNLES Jump if not less, if E or G bit is set in SR JNEQU Jump if not equal if L or G bit is set in SR JNGRE Jump if not greater if L or E bit is set in SR Stack commands: The first operand of the command, the register Rj, points to the top of the stack, ie. the topmost item in it. Usually, the register SP (which is also R6) is used as the stack pointer. PUSH Increases the stack pointer Rj's value by one and stores the latter operand as the topmost item in the stack. POP Removes the topmost item in the stack and stores it as the register Ri (the latter operand is always a register). Substracts one from the stack pointer Rj. PUSHR Pushes the registers R0, R1, R2, R3, R4, R5 and R6 (SP) to the stack, in this order. Before pushing each register, increases the stack pointer Rj's value by one. POPR Pops values to the registers R6 (SP), R5, R4, R3, R2, R1 and R0, in this order, from the stack. For each pop, first fetches the value from the top of the stack indicated by the register Rj, and then substracts one from Rj. Subroutine commands: CALL Call procedure. Moves the control (by manipulating the program counter) to the address given by the latter operand. Stores the return address to the stack, with its top indicated by Rj. EXIT Returns from a procedure to the command following its call. The return address is found from the stack, the top of which Rj points to. The latter operand indicates the number of parameters passed to the subroutine in the call. System calls: SVC Supervisor call. Calls a service routine in the operating system. The first operand is Rj, indicating the top of the stack, the latter operand gives the number identifying the service. Supervisor calls are special subroutine calls to predefined procedures. Their code is invisible to the user, and is considered to be stored "outside" the memory space. Service identifiers: HALT : Stops the execution of the program. TIME : Gives the time of day. The stack should contain the addresses to store the hour, minute and second values. Note their order! DATE : Gives the date. The stack should contain the addresses to store the year, month and day values. Note their order! READ : Reads an integer from the keyboard. The stack should contain the address to store the integer to. WRITE: Prints an integer to the screen. The stack should contain the value to print. Other: NOP No operation. This command does nothing. ====================================================================== The operation codes of the TTK-91 commands ====================================================================== Command Binary Decimal Hexadecimal NOP 0000 0000 0 00 STORE 0000 0001 1 01 LOAD 0000 0010 2 02 IN 0000 0011 3 03 OUT 0000 0100 4 04 ADD 0001 0001 17 11 SUB 0001 0010 18 12 MUL 0001 0011 19 13 DIV 0001 0100 20 14 MOD 0001 0101 21 15 AND 0001 0110 22 16 OR 0001 0111 23 17 XOR 0001 1000 24 18 SHL 0001 1001 25 19 SHR 0001 1010 26 1A NOT 0001 1011 27 1B [LL-2004-10-06] SHRA 0001 1100 28 1C [LL-2004-10-06] COMP 0001 1111 31 1F JUMP 0010 0000 32 20 JNEG 0010 0001 33 21 JZER 0010 0010 34 22 JPOS 0010 0011 35 23 JNNEG 0010 0100 36 24 JNZER 0010 0101 37 25 JNPOS 0010 0110 38 26 JLES 0010 0111 39 27 JEQU 0010 1000 40 28 JGRE 0010 1001 41 29 JNLES 0010 1010 42 2A JNEQU 0010 1011 43 2B JNGRE 0010 1100 44 2C CALL 0011 0001 49 31 EXIT 0011 0010 50 32 PUSH 0011 0011 51 33 POP 0011 0100 52 34 PUSHR 0011 0101 53 35 POPR 0011 0110 54 36 SVC 0111 0000 112 70 ====================================================================== Predefined symbols of the TTK-91 machine ====================================================================== These symbols can be used without explicitly defining them in a TTK-91 program. Symbol Value --------------------- CRT 0 KBD 1 STDIN 6 STDOUT 7 HALT 11 READ 12 WRITE 13 TIME 14 DATE 15 ====================================================================== Instructions to the compiler (fake commands) ====================================================================== The compiler instructions direct the program translating the symbolic machine language to binary. They are NOT actual symbolic commands. name EQU value The alias command EQU defines a symbolic name for an integer value. The symbol name can be used in the ADDR field of a command, in which case it will be handled as 'value' written in its stead would be. name DC value The memory allocation command DC (data constant) allocates one word of memory for a constant, aliases 'name' with the constant's memory address and stores 'value' in the allocated address in the memory. 'Name' can then be used in a command's ADDR field as a memory address. name DS size The memory allocation command DS (data segment) allocates an area of memory, sized 'size' words. It aliases 'name' with the start address of the memory area. 'Name' can then be used in a command's ADDR field as a memory address. This instruction is used for allocating space for global variables. option DEF string This special instruction changes options for simulating the file system of a TTK-91 machine. 'String' should be an absolute directory path. Examples: STDIN DEF /home/myuser/ttk91/stdin STDOUT DEF C:\mydir\stdout Available options are: STDIN To set which file stdin data is read from. STODUT To set which file stdout data is written to. HOME To set the user's home directory for this application; unused in Titokone as the home directory is requested from the underlying operating system via the Java virtual machine. The default files for the two first options are stdin and stdout in the user's current working directory.