1 / 16

What is TINY?

What is TINY?. Base-10 Machine (emulator currently runs on Windows-based machines.) Only 1,000 ‘bytes’ of memory Only 5 registers ~20 machine instructions A simple machine that will actually run small programs!. Tiny was originally designed and written by Drs. Baird and Baber in 1983.

scot
Download Presentation

What is TINY?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What is TINY? • Base-10 Machine (emulator currently runs on Windows-based machines.) • Only 1,000 ‘bytes’ of memory • Only 5 registers • ~20 machine instructions • A simple machine that will actually run small programs! Tiny was originally designed and written by Drs. Baird and Baber in 1983. The Tiny Integrated Development Environment (TIDE) was added by Dr. Steil in 2004.

  2. Tiny Machine Architecture

  3. The TINY Instruction Cycle • Fetch next instruction as indicated by the PC and load it into the IR. • ( IR f c(PC) ) • 2. Increment the PC by 1. ( PC f PC + 1 ) • 3. Decode and Execute the instruction. Ramifications: 1. CPU assumes that PC is pointing to an instruction. 2. Program flow assumes sequential order of instructions. 3. TINY programs must have a start address: 000 4. Unless told to STOP, TINY will execute forever.

  4. TINY Machine Instructions Op Code Mnemonic Description 00 STOP STOP execution of TINY program. 01 LD x LoaD accumulator with contents at the address 02 LDI x LoaD (Indirect) accumulator 03 LDA x LoaD Address specified by 'x' into accumulator. 04 ST x STore contents of accumulator at address 'x'. 05 STI x STore (Indirect) contents of accumulator 06 ADD x ADD contents at address 'x' to the accumulator. 07 SUB x SUBtract contents at address 'x' from the accumulator. 08 MUL x MULtiply contents at address 'x' to the accumulator. 09 DIV x DIVide contents of accumulator by the contents at 'x'. 10 IN INput a Character from the keyboard 11 OUT OUTput the Character in the accumulator. 12 JMP x JuMP (unconditionally) to address 'x'. 13 JG x Jump to address 'x‘ if accumulator is Greater than 0. 14 JL x Jump to address 'x‘ if accumulator is Less than 0. 15 JE x Jump to address 'x‘ if accumulator is Equal to 0. 16 CALL x CALL function whose address is specified by 'x'. 17 RET RETurn from function. 18 PUSH PUSH contents of ACCUM onto stack. 19 POP POP value off of stack and place in ACCUM. 20 LDPARAM LoaD accumulator with a copy of the nth PARAMeter.

  5. Assembler Directives (pseudo-ops) label: DC“string”Define Character string. ASCII codes for characters within quotation marks are stored in consecutive addresses beginning with the one associated with a label label: DBnDefine Byte. Places decimal value of n in byte at address associated with a label. (n must be an integer.) Equivalents: DW n and DD n label: DSnDefine Storage. Reserves next n addresses for future use beginning with the address associated with a label. (n must be a positive integer.)

  6. ROM routines AddressMnemonicDescription 900PRINTN Converts current integer value in ACC register to ASCII characters and outputs the result. ldintegerValue call printn 925PRINTC Outputs ASCII characters contained in memory at the location specified by the ACC register.Careful: Output continues until a null-terminator (or zero byte) is detected! lda string call printc 950INPUTN Execution pauses to accept a numeric value from the user. The input is converted to decimal format and stored in ACC register. call inputn stintegerValue 975INPUTC Execution pauses to accept ASCII text from the user. The input is stored in memory beginning with the address specified by ACC register. A trailing null-terminator will be appended to the end of the ASCII string. ldastring_buffer call inputc

  7. TINY Assembly Language Source Code Lines LABEL: OPCODE OPERAND ;COMMENT Examples: main: ; void main () { call inputn ; cin >> i; st i ld i ; cout << i * i; mul i call printn stop ; } i: ds 1 ; int i;

  8. “Hello World” Example HELLO.TNY (Source Code) ;****************************************************************************** ;Program Name: HELLO * ;Description: Displays the string, “Hello World!” on the screen. * ;****************************************************************************** jmp main ; Constants str: dc ‘Hello World!’ db 13 db 10 db 0 main: ; void main () { lda str ; cout << “Hello World!” << endl; call printc stop ; } HELLO.TNC (Machine Code) • 000 12016 009 00114 • 001 00072 010 00108 • 002 00101 011 00100 • 003 00108 012 00033 • 004 00108 013 00013 • 005 00111 014 00010 • 006 00032 015 00000 • 007 00087 016 03001 • 008 00111 017 16925 • 018 00000

  9. From Source Code to Machine Code (Command Line version) C:> EDIT SAMPLE.TNYEnter TINY assembler source code. C:> TINY SAMPLE.TNYAssembles machine code program SAMPLE.TNC. Also creates listing file: SAMPLE.LIS. C:> RUNTINY SAMPLE.TNCRun program on TINY emulator. OR One could use the Tiny Integrated Development Environment (TIDE).

  10. TIDE – Tiny Integrated Development Environment

  11. Sample Source Code(Can you spot the syntax errors?) ;****************************************************** ;*Program Name: SAMPLE * ;*Author: John Doe * ;*Date Due: Sept. 2002 * ;*Assignment: Lab 0 * ;* * ;*Description: This program accepts an integer and * ;* displays its square + 1. * :****************************************************** JMP main ; CONSTANTS #1: DB 1 ; VARIABLES i: DS 1 ; int i; main; ; void main () { CALL INPUTN ; cin >> i; ST i LD i ; cout << (i * i + 1); MUL j ADD #1 PRINTN STOP ; }

  12. First ‘COMPILE’ attempt: C:> TINY SAMPLE ERROR: Invalid opcode in line #9: 9 :****************************************************** ERROR: Invalid opcode in line #18: 18 main; ; void main () { ERROR: Invalid or missing operand in line #24: 24 MUL j ERROR: Invalid opcode in line #26: 26 PRINTN Total number of TINY errors: 4 C:>

  13. SAMPLE.LIS after 1st ‘COMPILE’ attempt: Tiny Assembler Listing of sample.tny on Tue Aug 19 11:31:15 2003 ADR VALUE Ln SOURCE LINE --- ----- --- ----------- 1 ;****************************************************** 2 ;*Program Name: SAMPLE * 3 ;*Author: John Doe * 4 ;*Date Due: Sept. 2002 * 5 ;*Assignment: Lab 0 * 6 ;* * 7 ;*Description: This program accepts an integer and * 8 ;* displays its square + 1. * 9 :****************************************************** ERROR: Invalid opcode in line #9 000 12003 10 JMP main 11 12 ; CONSTANTS 001 00001 13 #1: DB 1 14 15 ; VARIABLES 002 ????? 16 i: DS 1 ; int i; 17 18 main; ; void main () { ERROR: Invalid opcode in line #18 19 003 16950 20 CALL INPUTN ; cin >> i; 004 04002 21 ST i 22 005 01002 23 LD i ; cout << (i * i + 1); 006 08??? 24 MUL j ERROR: Invalid or missing operand in line #24 007 06001 25 ADD #1 26 PRINTN ERROR: Invalid opcode in line #26 27 008 00000 28 STOP ; }

  14. 1. Use a text editor to enter or correct TINY source code (using EDIT, NotePad, TIDE) C:> EDIT SAMPLE.TNY 2. Recompile C:> TINY SAMPLE 3. If syntax errors present, return to step 1 4. Run the program using TIDE or the RUNTINY emulator. C:> RUNTINY SAMPLE 34 1157

  15. Tiny Assembler Listing of sample.tny on Tue Aug 19 11:37:14 2003ADR VALUE Ln SOURCE LINE--- ----- --- ----------- 1 ;****************************************************** 2 ;*Program Name: SAMPLE * 3 ;*Author: John Doe * 4 ;*Date Due: Sept. 2002 * 5 ;*Assignment: Lab 0 * 6 ;* * 7 ;*Description: This program accepts an integer and * 8 ;* displays its square + 1. * 9 ;******************************************************000 12003 10 JMP main 11 12 ; CONSTANTS001 00001 13 #1: DB 1 14 15 ; VARIABLES002 ????? 16 i: DS 1 ; int i; 17 18 main: ; void main () { 19 003 16950 20 CALL INPUTN ; cin >> i;004 04002 21 ST i 22 005 01002 23 LD i ; cout << (i * i + 1);006 08002 24 MUL i007 06001 25 ADD #1008 16900 26 CALL PRINTN 27 009 00000 28 STOP ; } SAMPLE.LIS after syntax errors are corrected:

  16. C++ to TINY C++TINY int i; i: ds 1 int j; j: ds 1 char str[80]; str: ds 80 cin >> i; call inputn st i cout << i; ld i call printn cin.getline(str,80); lda str call inputc cout << str; lda str call printc j = 2*i*i + 2; ld i mul i mul #2 (assumes #2 is defined) add #2 st j #2: db 2

More Related