Note to instructors

Download the program DOS/Windows
Download the program Linux
Too lazy to wite your own term project? Here's the source

Summing example
Division example

Itsy Bitsy Machine (IBC)

Version 2.0

A simulation of a simple computer

UMAD IFSM 310

User's Manual

IBC

--------------------------------------

Footnotes:

1 for those who are superstitious about that number, don't worry; the instruction after the twelvth instruction is the fourteenth instruction.
2 Expandable to 64KB if there is user demand...


The instruction set is functionally complete: branching and looping can be done, thus any program could be executed on this computer (within its memory constraints, as in any computer). Don't be put off by its smallness; it can do anything any other computer can do. The instructions, addressing modes, and data types that real computers have add convenience (for programmers and compilers) and efficiency but not fundamental abilities that IBC lacks.









Instructions:

			required
	required #	addressing	machine
Opcode	 operands	modes 		cycles		Example		comment on example        


LOAD     	2 	Abs/Im, Reg	4 or 6		Load	100,R1	/R1 = M[100] 

STORE   	2 	Reg/Im, Abs	6  		Store R2,100	/M[100] = R2

IN 	    	1 	Abs		5		In	100	/M[100] = userinput

OUT	    	1 	Abs		5		Out	100	/output M[100]

NEG	    	1 	Reg		3		Neg	R1	/R1 = -R1

ADD	    	2 	Reg,Reg		5		Add	R1,R2	/R2 = R1+R2

MULT    	2 	Reg,Reg		7		Mult	R1,R2	/R2 = R1*R2

CMP	    	2 	Reg,Reg		4		Cmp	R1,R2	/set EQ, LT flags

JMP	    	1 	Abs*		4		Jmp	Label	/unconditional jump

BEQ	    	1 	Abs*		4		Beq	Label	/jump if EQ flag on

BNE	    	1 	Abs*		4		Bne	Label	/jump if EQ flag off

BLT	    	1 	Abs*		4		Blt	Label	/jump if LT flag on

HALT     	0	-		1		Halt		/stop program

Note: Abs* means a program label/symbolic address.

Load will copy the 2-byte integer value at the specified memory location or the 1-byte immediate value into the register. If the first operand is an immediate value, the instruction occupies 3 bytes of program memory and four cycles are needed to execute it; if the first operand is an absolute address, the instruction uses 4 bytes of program memory and executes in six cycles. The opcode byte encodes the addressing mode (bit 7 is 1 for immediate addressing, 0 for absolute addressing).

Store will copy the value in the register or the 1-byte immediate value to memory. Bit 7 of the opcode encodes the addressing mode of the first operand.

In will input the number entered by the user to the memory location. We will assume that the input value is already available from the input device, thus this instruction always executes in five cycles.

Out will display the value in the memory location to the screen.

Neg will negate the value in the register.

Add will add the two values in the two registers and store the result in the second register.

Mult will multiply the two values in the two registers and store the result in the second register.

Cmp will compare the two values in the two registers and set the EQ flag (a one bit register in the CPU) to 1 if the values are the same or set it to 0 if the two values are different. It will set the LT flag to 1 if the first register's value is less than the second register's value or set it to 0 if the first register's value is not less than the second register's value (that is, if the first register's value is greater than or equal to the second register's value).

Beq will cause the CPU to branch to the instruction labeled with the destination label if the EQ flag is 1.

Bne will cause the CPU to branch to the instruction labeled with the destination label if the EQ flag is 0.

Blt will cause the CPU to branch to the instruction labeled with the destination label is the LT flag is 1.

Jmp will cause the CPU to branch to the instruction labeled with the destination label.

Halt ends the program.

When loaded into memory, opcodes in order of the previous table are coded as the decimal numbers 1 thru 13. Immediate operands are 2's complement bytes. Register operands are 0 thru 7. Absolute operands are 2 byte numbers.


The IBC system has a built-in assembler/interpreter that inputs a file
containing a program and executes it.  Various syntactic errors are
detected and reported (see below).  Comments in the program are
indicated by a / (from the / to the end of the line).  It is
case-insensitive (names of instructions, the 'r' of register
addressing, and labels can be any mix of upper and lowercase letters.)
An instruction line can be preceded by a six or fewer characters
symbolic label followed by a colon.  This label can be used as the
destination of a branch or jump instruction (the colon not being
used).


Commands the user can enter before the loaded program starts execution, or when the program pauses upon encountering a breakpoint, or when the program has completed execution. Either the single letter in upper or lower case or the entire word can be entered.

D Display the program.

E Execute the program (or continue from a breakpoint, or re-execute the program).

R Show the values of the Registers (includes R0-R7, PC, EQ, LT).

M Show the value at a Memory location. (the 2 bytes starting at a given address are displayed in decimal and hex)

S Set a breakpoint (the executing program will pause at a line with a breakpoint set). Any number of breakpoints can be set. When the executing program is paused at a breakpoint any of these commands can be issued. The E command will make the program continue its execution.

C Clear a breakpoint.

H Help (display menu of commands).

L Load another program into IBC.

Q Quit the IBC system.


Errors detected and reported:



Example programs.

Assembly language programs are difficult to understand, thus they should be thoroughly documented, often with each line given a comment.

Program file:

/ read input, multiply by 2, output result		#cycles (for illustration purposes)
IN 102      	/ input to mem 102			  5
LOAD 102,R1  	/ thence to reg 1			  6
LOAD #2,R2    	/ 2 to reg 2				  4
MULT R1,R2    	/ reg2 = reg1 * reg2		  	  7
STORE R2,104  	/ mem 104 = reg2			  6
OUT 104       	/ output mem 104			  5			
HALT		/ terminate program execution	     	  1

						total:	 34

When this is loaded, memory will look like:
Address Content of byte(s)
0 IN
1 102

3 LOAD
4 102

6 R1
7 LOAD
8 2
9 R2
10 MULT
11 R1
12 R2
13 STORE
14 R2
15 104

17 OUT
18 104

20 HALT




Program file:

/ program to read number, count down to 0, summing.
/ repeat for positive numbers
Start: In   102           	/ user input
       Load 102,r1        	/ to r1
       Load #0,r0         	/ 0 to r0
       Cmp  r1,r0         	/ compare user's input with 0
       Beq  done          	/ done if user input a 0
       Load #0,r6         	/ the sum
       Load #-1,r2        	/ the decrement value
Next:  Add  r1,r6       	/ r6 += r1
       Add  r2,r1         	/ r1--
       Store r1,106
       Out  106			/ display current value
       Cmp  r0,r1         	/ =0 yet?
       Bne  next		/ if not, loop back to Next
       Store r6,108		/ but if 0, store sum
       Out  108			/ display sum
       Jmp  start		/ do another
Done:  Halt	             	

Exercises: Show the layout of this in program memory. Show the number of cycles for each instruction. How many machine cycles to execute if the user enters just 0, or 1 then 0, or 2 then 0, or n then 0 (a formula).




Other programs to create:

Input 2 numbers, display sum and product.

Input 2 numbers, output the larger one.

Input 2 numbers, output the difference (i.e. subtraction).

Input 2 numbers, output the quotient and remainder (i.e. division).

Input 3 numbers, output sum and product.

Input 3 numbers, output the smallest.

Input a number, output the numbers from 0 to that number.

Sum a sequence of numbers input by the user. 0 marks the end of the sequence.

Sum a sequence of numbers input by the user. User first indicates how many numbers in the sequence.

Self-modifying program.

etc.