Presentation is loading. Please wait.

Presentation is loading. Please wait.

What is TINY? 1.Base-10 Machine (emulator currently runs on Windows-based machines.) 2.Only 1,000 ‘bytes’ of memory 3.Only 5 registers 4.~26 machine instructions.

Similar presentations


Presentation on theme: "What is TINY? 1.Base-10 Machine (emulator currently runs on Windows-based machines.) 2.Only 1,000 ‘bytes’ of memory 3.Only 5 registers 4.~26 machine instructions."— Presentation transcript:

1 What is TINY? 1.Base-10 Machine (emulator currently runs on Windows-based machines.) 2.Only 1,000 ‘bytes’ of memory 3.Only 5 registers 4.~26 machine instructions 5.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 1.Fetch next instruction as indicated by the PC and load it into the IR. ( IR  c(PC) ) 2.Increment the PC by 1.( PC  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 Op CodeMnemonicDescription 00STOPSTOP execution of TINY program. 01LD xLoaD accumulator with contents at the address 02LDI xLoaD (Indirect) accumulator 03LDA xLoaD Address specified by 'x' into accumulator. 04ST xSTore contents of accumulator at address 'x'. 05STI xSTore (Indirect) contents of accumulator 06ADD xADD contents at address 'x' to the accumulator. 07SUB xSUBtract contents at address 'x' from the accumulator. 08MUL xMULtiply contents at address 'x' to the accumulator. 09DIV xDIVide contents of accumulator by the contents at 'x'. 10ININput a Character from the keyboard 11OUTOUTput the Character in the accumulator. 12JMP xJuMP (unconditionally) to address 'x'. 13JG xJump to address 'x‘ if accumulator is Greater than 0. 14JL xJump to address 'x‘ if accumulator is Less than 0. 15JE xJump to address 'x‘ if accumulator is Equal to 0. 16CALL xCALL function whose address is specified by 'x'. 17RETRETurn from function. 18PUSHPUSH contents of ACCUM onto stack. 19POPPOP value off of stack and place in ACCUM. 20LDPARAMLoaD accumulator with a copy of the nth PARAMeter. 21JGE xJump to address ‘x’ if accumulator Greater than or Equal to 0 22JLE xJump to address ‘x’ if accumulator Less than of Equal to 0 23JNE xJump to address ‘x’ if accumulator Not Equal to 0 24PUSH xPUSH contents of memory at address ‘x’ onto stack 25POP xPOP value off of stack and place in memory at address ‘x’ TINY Machine Instructions (partial)

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:DB n Define 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:DS n Define 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 900PrintIntegerConverts current integer value in ACC register to ASCII characters and outputs the result. ldintegerValue callprintInteger 925PrintStringOutputs 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! ldastring callprintString 950InputIntegerExecution pauses to accept a numeric value from the user. The input is converted to decimal format and stored in ACC register. callinputInteger stintegerValue 975InputStringExecution 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 callinputString

7 TINY Assembly Language Source Code Lines LABEL:OPCODEOPERAND;COMMENT jmpmain i:ds1; int i; main:; void main () { callinputInteger; cin >> i; sti ldi; cout << i * i; muli callprintInteger stop; } Example:

8 “Hello World” Example ;****************************************************************************** ;Program Name: HELLO* ;Description: Displays the string, “Hello World!” on the screen.* ;****************************************************************************** jmpmain ; Constants str:dc‘Hello World!’ db13 db10 db0 main:; void main () { ldastr; cout << “Hello World!” << endl; callprintString stop; } HELLO.TNY(Source Code) 000 12016009 00114 001 00072010 00108 002 00101011 00100 003 00108012 00033 004 00108013 00013 005 00111014 00010 006 00032015 00000 007 00087016 03001 008 00111017 16925 018 00000 HELLO.TNC(Machine Code)

9 From Source Code to Machine Code (Command Line version) C:> EDIT SAMPLE.TNY Enter TINY assembler source code. C:> TINY SAMPLE.TNY Assembles machine code program SAMPLE.TNC. Also creates listing file: SAMPLE.LIS. C:> RUNTINY SAMPLE.TNC Run 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. * :****************************************************** JMPmain ; CONSTANTS #1:DB1 ; VARIABLES i:DS1; int i; main;; void main () { CALLinputInteger; cin >> i; STi LDi; cout << (i * i + 1); MULj ADD#1 PrintInteger STOP; }

12 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 PrintInteger Total number of TINY errors: 4 C:> First ‘COMPILE’ attempt:

13 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 inputInteger; 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 PrintInteger ERROR: Invalid opcode in line #26 27 008 00000 28 STOP ; } SAMPLE.LIS after 1 st ‘COMPILE’ attempt:

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

15 Tiny Assembler Listing of sample.tny on Tue Aug 19 11:37:14 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 ;****************************************************** 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 () { 19 003 16950 20 CALL InputInteger; cin >> i; 004 04002 21 ST i 22 005 01002 23 LD i ; cout << (i * i + 1); 006 08002 24 MUL i 007 06001 25 ADD #1 008 16900 26 CALL PrintInteger 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;callinputInteger sti cout << i;ldi callprintInteger cin.getline(str,80);ldastr callinputString cout << str;ldastr callprintString j = 2*i*i + 2;ldi muli mul#2 (assumes #2 is defined as below) add#2 stj #2:db2


Download ppt "What is TINY? 1.Base-10 Machine (emulator currently runs on Windows-based machines.) 2.Only 1,000 ‘bytes’ of memory 3.Only 5 registers 4.~26 machine instructions."

Similar presentations


Ads by Google