What is TINY? 1.Base-10 Machine (emulator currently runs on Windows-based machines.) 2.Only 1,000...

16
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.

Transcript of What is TINY? 1.Base-10 Machine (emulator currently runs on Windows-based machines.) 2.Only 1,000...

Page 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.

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.

Page 2: 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.

Tiny Machine Architecture

Page 3: 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.

The TINY Instruction Cycle1. 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: 0004. Unless told to STOP, TINY will execute forever.

Page 4: 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.

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.

21 JGE x Jump to address ‘x’ if accumulator Greater than or Equal to 0

22 JLE x Jump to address ‘x’ if accumulator Less than of Equal to 0

23 JNE x Jump to address ‘x’ if accumulator Not Equal to 0

24 PUSH x PUSH contents of memory at address ‘x’ onto stack

25 POP x POP value off of stack and place in memory at address ‘x’

TINY Machine Instructions (partial)

Page 5: 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.

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.)

Page 6: 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.

ROM routines

Address Mnemonic Description900 PrintInteger Converts current integer value in ACC register to

ASCII characters and outputs the result.ld integerValuecall printInteger

 925 PrintString 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 stringcall printString

 950 InputInteger Execution pauses to accept a numeric value from the

user. The input is converted to decimal format and stored in ACC register.call inputIntegerst integerValue

 975 InputString 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.

lda string_buffercall inputString

Page 7: 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.

TINY Assembly Language Source Code Lines

LABEL: OPCODE OPERAND ;COMMENT

jmp main

i: ds 1 ; int i;

main: ; void main () {call inputInteger ; cin >> i;st i

ld i ; cout << i * i;mul icall printInteger

stop ; }

Example:

Page 8: 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.

“Hello World” Example

;******************************************************************************;Program Name: HELLO *;Description: Displays the string, “Hello World!” on the screen. *;******************************************************************************

jmp main

; Constantsstr: dc ‘Hello World!’

db 13db 10db 0

main: ; void main () {

lda str ; cout << “Hello World!” << endl;call printString

stop ; }

HELLO.TNY (Source Code)

000 12016 009 00114001 00072 010 00108002 00101 011 00100003 00108 012 00033004 00108 013 00013005 00111 014 00010006 00032 015 00000007 00087 016 03001008 00111 017 16925

018 00000

HELLO.TNC (Machine Code)

Page 9: 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.

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 programSAMPLE.TNC. Also createslisting file: SAMPLE.LIS.

C:> RUNTINY SAMPLE.TNC Run program on TINY emulator.

OROne could use the Tiny Integrated Development Environment (TIDE).

Page 10: 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.

TIDE – Tiny Integrated Development Environment

Page 11: 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.

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

 ; VARIABLESi: DS 1 ; int i;

main; ; void main () { 

CALL inputInteger ; cin >> i;ST i

 LD i ; cout << (i * i + 1);MUL jADD #1PrintInteger

 STOP ; }

Page 12: 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.

C:> TINY SAMPLEERROR: 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: 4C:>

First ‘COMPILE’ attempt:

Page 13: 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.

 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 #9000 12003 10 JMP main

11 12 ; CONSTANTS

001 00001 13 #1: DB 1 14 15 ; VARIABLES002 ????? 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 #24007 06001 25 ADD #1 26 PrintInteger ERROR: Invalid opcode in line #26 27 008 00000 28 STOP ; }

SAMPLE.LIS after 1st ‘COMPILE’ attempt:

Page 14: 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.

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

Page 15: 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.

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 ; 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 InputInteger ; 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 PrintInteger 27 009 00000 28 STOP ; }

SAMPLE.LIS after syntax errors are corrected:

Page 16: 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.

C++ to TINYC++ TINYint i; i: ds 1int j; j: ds 1

char str[80]; str: ds 80

cin >> i; call inputIntegerst i

cout << i; ld icall printInteger

cin.getline(str,80); lda strcall inputString

cout << str; lda strcall printString

j = 2*i*i + 2; ld imul imul #2 (assumes #2 is defined as below)add #2st j

#2: db 2