Tony Morse Summer 2012 Opus
(cscs 2650)
I am Tony Morse. I am a third year student at SUNY Brockport, studying Math and Computer Science. I am taking cscs 2650 at Corning Community College as an equivalent course for csc 311 at Brockport. The goal of the summer class is to make a working emulator.
- What action or concept of significance, as related to the course, did you experience on this date?
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
Logic Operations: And, Or, Not, and Xor
The logical operators take either one(Not) or multiple(And, Or, Xor) arguments and compare the argument(s) and create a new output depending on the specific operator. And operator will check to see if all of the given arguments have the value that is being checked for, and will return true if they do and false otherwise. Not operator will check the argument and give the opposite corresponding value. Or operator will check to see if any one or more of the given arguments have the value that is being checked for, and will return true if so or else false. Xor operator will check to see if exactly one of the given arguments has the value that is being checked for, and will return true if so or else false. We are using bit-wise versions of these operators to check multiple registers and create a new one based on whether or not the corresponding bits in the given registers adhere to the logical operator that is being implemented. See code for example!
given Register reg1: 00011011 and Register reg2: 00011000 use the And operator to produce reg3.
reg1: 00011011
reg2: 00011000
reg3: 00011000
Instruction Sets
Scripts or programs in an architecture that allow for quick manipulation of key components in said architecture. In this project, our instruction sets are used to perform quick manipulations of key registers.
The following is an instruction for loading a given value into the accumulator:
#!/bin/bash # #A9-Immediate instruction #loads given value into Accumulator # #../../datamanip Load calls the java program Load.java #../reg/a.reg is the register the value will be loaded to #./checkZero a calls the checkZero script with accumulator as the argument #./checkSign a calls the checkSign script with accumulator as the argument java -cp ../../datamanip Load $1 ../reg/a.reg ./checkZero a ./checkSign a
Command-line example:
lab46:~$ cd src/project/sim/ops lab46:~/src/project/sim/ops$ ./0xA9 0
Binary and Hexadecimal Number Representation
Representing numbers in base 2 (binary) and base 16 (hexadecimal) as opposed to decimal (10) which is normally used. It should be noted that for base 16: 10 == A, 11 == B, 12 == C, 13 == D, 14 == E, 15 == F
Demonstration will be through simple examples: It will be in the form (number)base → /*convert to*/ (number)base
(10)10 –> (1010)2 –> (A)16
(73)10 –> (1001001)2 –> (49)16
(115)10 –> (1110011)2 –> (73)16
(159)10 –> (10011111)2 –> (9F)16
(256)10 –> (100000000)2 –> (100)16
Data Representation
The different ways to represent data. Such as base choice, (binary or decimal for example), and whether or not it is signed. For this project, we are using signed binary. For negative values we are using two's complement as opposed to one's.
Demonstration of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Code snippets * Take in a value * convert to binary */ import java.util.Scanner; public class BinaryConverter { public static char [] bin; public static void main (String [] args) { Scanner value = new Scanner (System.in); System.out.println("Input a value."); int val = value.nextInt(); System.out.print(twoComp(val)); } public static char [] oneComp (int val) { val = Math.abs(val); twoComp(val); for (int k = 0; k < bin.length(); k++) { if (bin[k] == '0') bin[k] = '1'; else bin[k] = '0'; } return bin; } //convert to two's comp public static char [] twoComp (int val) { String binary; if (val >= 0) { binary = Integer.toBinaryString(val); for (int k = 0; k < binary.length(); k++) bin[k] = binary.charAt(k); } else { bin = oneComp(val); increment(); } return bin; } //increment the array public static void increment() { boolean check = true; for (int k = 7; k >= 0; k--) { if (check == true) { if (bin[k] == '0') { bin[k] = '1'; check = false; } else { bin[k] = '0'; check = true; } } } } }
von Neumann vs Harvard architecture
Harvard and von Neumann are two prominent computer architectures used in modern computers.
The Harvard and von Neumann architectures are both very popular and both have a cpu based system. The primary difference between these architectures is that von Neumann stores data memory and data instructions in the same space, while the Harvard architecture stores data memory and data instructions in separate spaces. This has a couple consequences:
Both have advantages and disadvantages. For instance the Harvard architecture having separate spaces for instructions and data means that machines that run it need more physical space so as to keep them separate. However, this attribute is also advantageous in that simultaneous manipulation of instructions and data makes for a faster machine than can be achieved with a von Neumann architecture.
Interrupts
Instructions or code that allow for quick changes in the instructions being executed.
An example of an Interrupt is the NOP (No Operation) instruction. The NOP instruction's only purpose is to increment the program counter.
# !/bin/bash # # INSTRUCTION: # 0xEA - NOP instruction # # FUNCTION: # Increments the program counter. # # FLAGS FLIPPED: # None # PROGRAMCOUNTER="pc" # The location of the program counter java -cp ../../lib Increment ${PROGRAMCOUNTER} exit 0
Storage
Computers need to be able to recall previous instructions, and it is convenient for users to be able to frequently access media, or entertainment, or files that they want to put on the computer. To provide this function, computers are able to store information in memory. There are several different types of memory: ram, rom, and cache to name a few.
An example of using memory is saving a file that you are working on. E.G.- You are writing an essay for some reason, and you want to go to bed, so you save it so that you are able to shut off your computer and open it again at a later date.
I/O
Input/Output refers to the process of interacting with a computing device by giving it parameters or instructions (input) and the machine executing the instructions and giving an answer or showing the result of the instructions (output).
My Demonstration will take the form of a simple program.
# Asks the user for his name and age, # and prints out an interesting fact prompt = '-->' print "Hi, what is your name?" name = raw_input(prompt) print "Well, %s, is a nice name. How old are you?" % name age = raw_input(prompt) print """ So, your name is %s and you are %s years old.\nDid you know that Bears eat fish?\nWell they do. """ % (name, age)
python nameandage.py Hi, what is your name? -->Tony Well, Tony, is a nice name. How old are you? -->20 So, your name is Tony and you are 20 years old. Did you know that bears eat fish? Well they do.
Would it have been at all faster to make the register boolean arrays instead of char arrays?
http://www.roseindia.net/java/master-java/java-data-types.shtml
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html=
Based on the resources I have found that say booleans take up less memory and are faster to access, I believe that an array of boolean values would have been a faster alternative to char arrays.
I will write java programs that will be clones except for using boolean arrays in one of the programs and char arrays in the other. The program will load an array and time how long it takes.
* Note that the difference in data types may require some differences in functions and register initializations.
Boolean Results TIME: NanoSeconds
1st | 2nd | 3rd | 4th | 5th | |
---|---|---|---|---|---|
1 | 46660 | 4200 | 3733 | 3267 | 3732 |
2 | 47127 | 4666 | 3733 | 3266 | 3733 |
3 | 44795 | 4666 | 3266 | 3733 | 3733 |
4 | 46194 | 4199 | 3733 | 3733 | 3733 |
5 | 45727 | 4200 | 3733 | 3733 | 4200 |
AVG: | 46100.6 | 4386.2 | 3639.6 | 3546.2 | 3826.2 |
AVERAGE | 12299.76 |
Char Results TIME: NanoSeconds
1st | 2nd | 3rd | 4th | 5th | |
---|---|---|---|---|---|
1 | 45728 | 4200 | 3732 | 3733 | 3733 |
2 | 46195 | 3733 | 3732 | 3733 | 3733 |
3 | 46660 | 4666 | 3267 | 3733 | 3733 |
4 | 49461 | 4199 | 4200 | 4199 | 3733 |
5 | 46195 | 4666 | 3266 | 3266 | 3733 |
AVG: | 46847.8 | 4292.8 | 3639.4 | 3732.8 | 3733 |
AVERAGE | 12449.16 |
/* * Experiment for opus. * First program test. * Using char arrays. * * */ public class ExperimentChar { public static char [] test = new char[8]; public static void load(int val) { String binaryVal = Integer.toBinaryString(val); for(int x = 0; x < binaryVal.length(); x++) test[x] = binaryVal.charAt(x); } public static long getTime(int val) { final long startTime = System.nanoTime(); final long endTime; try { load(val); } finally { endTime = System.nanoTime(); } final long duration = endTime - startTime; return duration; } public static void main(String [] args) { ExperimentChar experiment = new ExperimentChar(); for(int k = 0; k <= 4; k ++) System.out.println("The time for the " + (k + 1) + " experiment was: " + experiment.getTime(k) + " nanoseconds."); } }
/* * Experiment for opus. * Second program test. * Using boolean arrays. * * */ public class ExperimentBool { public static boolean [] test = new boolean[8]; public static void load(int val) { String binaryVal = Integer.toBinaryString(val); for(int x = 0; x < binaryVal.length(); x++) if(binaryVal.charAt(x) == '1') test[x] = true; else test[x] = false; } public static long getTime(int val) { final long startTime = System.nanoTime(); final long endTime; try { load(val); } finally { endTime = System.nanoTime(); } final long duration = endTime - startTime; return duration; } public static void main(String [] args) { ExperimentBool experiment = new ExperimentBool(); for(int k = 0; k <= 4; k ++) System.out.println("The time for the " + (k + 1) + " experiment was: " + experiment.getTime(k) + " nanoseconds."); } }
Based on the data collected:
The boolean array did take less time to run, however it was only around a 100 nanosecond difference, so I do not believe that it would have actually affected the project.
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
Fetch-Execute Cycle
It is the process the computer goes through in order to complete instructions. It grabs the instruction at the memory address in the program counter, then the program counter is incremented to the next instruction to be executed, the control unit then decodes the instruction at the address, and then it executes the program.
Registers (General Purpose, Floating Point, Accumulator, Data)
Registers are used as storage in computers, as an alternate to main memory which can take time to access and is not always most efficient. They are usually used by the CPU. There are several types of registers:
Accumulator: The accumulator is a register that stores results for arithmetic and logical operations. This is a useful register to have, because constantly using main memory to store and access something as commonly done as arithmetic or logical expressions would be very inefficient speed-wise.(Is a data register)
Data Registers: Contain integers, characters, and other primitive data types. They generally contain the information that will be accessed by RAM and that will be manipulated by the CPU.
General Purpose: They are used to store information such as data or memory addresses to data.
Floating Point: As the name would imply, they store floating point values.
Registers can be different sizes, and the choice is dependent on how much information you wish to store, for this project we used 8-bit registers.
Registers (Stack Pointer, Program Counter, Flag)
Registers are used as storage in computers, as an alternate to main memory which can take time to access and is not always most efficient. They are usually used by the CPU. There are several more types of registers:
Stack Pointer: In order to execute instructions in the order that they are supposed to be, the sequence of instructions are put into a stack. The stack pointer register points to the top of the stack, which is the instruction or command that is currently being executed.
Program Counter: The purpose of this register is to store the location of the next instruction to be executed. This is the register that is used in the Fetch-Execute cycle that I have previously explained.
Flag: Flag registers, as the name would imply, are used to store the flag registers and their statues. The flag registers are registers that are used to indicate if an event has occurred. There are several types of flags, in our project we have: Decimal, Interrupt, Overflow, Carry, Parity, Sign, and Zero. The flags are either set at '1' or '0', '1' if the event occurred (e.g. we checked if the register was 0 and it was, so we set the zero flag) and '0' otherwise.
Registers can be different sizes, and the choice is dependent on how much information you wish to store, for this project we used 8-bit registers.
Registers (Index/Pointer)
Registers are used as storage in computers, as an alternate to main memory which can take time to access and is not always most efficient. They are usually used by the CPU. There are several more types of registers:
Index: A register used for keeping track of and modifying operand addresses for memory. It is commonly used in Branch Instructions, though we don't seem to be using them in our project, since we are able to use indirect addressing.
Pointer: I think that this is just the general case of registers that are used to show the next/current/or recent instruction to be used or memory address where data is located. Special cases of pointers would be: A Stack Pointer and a Program Counter.
Registers can be different sizes, and the choice is dependent on how much information you wish to store, for this project we used predominately 8-bit registers, and a couple of 16-bit registers.
Negated Logic Operartions (NOT, NAND, NOR, XNOR)
As the name would imply, you negate the operator that the Not is attached to.
The demonstration will take the form of a logical table.
X | Y | X(AND)Y | X(OR)Y | X(XOR)Y | X(NOT) | Y(NOT) | X (NAND) Y | X(NOR)Y | X(XNOR)Y |
---|---|---|---|---|---|---|---|---|---|
T | T | T | T | F | F | F | F | F | T |
T | F | F | T | T | F | T | T | F | F |
F | T | F | T | T | T | F | T | F | F |
F | F | F | F | F | T | T | T | T | T |
Control flow and Data flow
Data flow is the process of moving and manipulating data between different sources, so that it will ultimately end up in the desired destination.
Control flow is the process of executing different tasks in a specific order in order to retrieve a desired effect, which may involve manipulating data.
The main similarity is that both are processes used to achieve some desired outcome. The main difference being that Data flow acts on, as you would figure, data, while Control flow refers to processing tasks. Also, due to its function, Control flow is implemented in an “assembly line” fashion, where one task is going to be started and finished before moving on to the next, whereas data can be manipulated in different locations simultaneously.
My demonstration will take the form of pseudocode.
Control Flow:
print “Input your age”
user_age = input
if user_age > 0
else
end
Data Flow:
Global variable favorite_color = “green”
print “What is your favorite color”
user_input = “input”
Global variable favorite_color = “input”
end
Machine Word
A word is the number of bits in a group for different processor designs. Most general computers today have either 32 or 64-bit word sizes, though 8 or 16-bits aren't unheard of.
Our standard for this project is 8-bits per data or memory address.
For the demonstration, I will the different registers we have, and the amount of bits they are assigned to take.
a(accumulator):8-bits
x:8-bits
y:8-bits
f(flag):8-bits
s(stack):8-bits
pc(program counter):16-bits
mar(memory address register):16-bit
mbr(memory buffer register):8-bit
iom(input/output memory):8-bit
iob(input/output buffer):8-bit
Subroutines
Subroutines is the name given to programs, scripts, or sections of code that are generally going to be used many times.
Since they are used frequently, programmers will generally have shortcuts to get to these code snippets.
For the 6502, there are two instructions used for code flow control.
The demonstration will be in the form of the unix scripts going to and returning from the subroutine.
# !/bin/bash # # INSTRUCTION: # RTS (0x60) - return from subroutine. # # FUNCTION: # Pull address off of stack and set program counter. # ARGUMENTS: # --------- # Implied functionality - no arguments needed. # # FLAGS: # Does not impact any flags # # Initialize Simulator Environment source ../etc/simvar.sh # Increment S register (Stack Pointer) java -cp ../../lib Increment s # hmm.. need to make sure no flags are adjusted. # Convert top of stack to hexadecimal value (lower order byte) PCLOWER="0x01`reg2hex strip < ${REGDIR}/s.reg`" # Increment S register (Stack Pointer) java -cp ../../lib Increment s # hmm.. need to make sure no flags are adjusted. # Convert top of stack to hexadecimal value (upper order byte) PCUPPER="0x01`reg2hex strip < ${REGDIR}/s.reg`" # Set the program counter with data we just pulled off the stack echo -n "${PCUPPER}${PCLOWER}" > ${REGDIR}/pc.reg # Increment Program Counter register java -cp ../../lib Increment pc # hmm.. need to make sure no flags are adjusted. exit 0
# !/bin/bash # # INSTRUCTION: # JSR (0x20) - jump to subroutine. # # FUNCTION: # Push address onto stack and set program counter. # ARGUMENTS: # ${1} - absolute address of routine we're jumping to # # FLAGS: # Does not impact any flags # # Initialize Simulator Environment source ../etc/simvar.sh # Convert upper order byte of PC to memory byte to put on stack cat ${REGDIR}/pc.reg | cut -c0-7 > ${REGDIR}/tmp.reg reg2bin strip < ${REGDIR}/tmp.reg > ${MEMDIR}/mbr.mem STACKTOP="0x01`reg2hex strip < ${REGDIR}/s.reg`" memput main mbr ${STACKTOP} # Decrement S register (Stack Pointer) java -cp ../../lib Decrement s # hmm.. need to make sure no flags are adjusted. # Convert lower order byte of PC to memory byte to put on stack cat ${REGDIR}/pc.reg | cut -c8-15 > ${REGDIR}/tmp.reg reg2bin strip < ${REGDIR}/tmp.reg > ${MEMDIR}/mbr.mem STACKTOP="0x01`reg2hex strip < ${REGDIR}/s.reg`" memput main mbr ${STACKTOP} # Decrement S register (Stack Pointer) java -cp ../../lib Decrement s # hmm.. need to make sure no flags are adjusted. # Set the program counter with data we just pulled off the stack echo -n "${1}" > ${REGDIR}/tmp.txt hex2reg < ${REGDIR}/tmp.txt > ${REGDIR}/pc.reg ## Need to check and perform any address sanitization ## Need to ensure hex2reg exists ## Need in ensure hex2reg supports and can operate on 8- and 16-bit values (input and output) exit 0
What is the question you'd like to pose for experimentation? State it here.
Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.
Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.
State your rationale.
How are you going to test your hypothesis? What is the structure of your experiment?
Perform your experiment, and collect/document the results here.
Based on the data collected:
What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.
- What action or concept of significance, as related to the course, did you experience on this date?
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
Remember that 4 is just the minimum number of entries. Feel free to have more.
Identification of chosen keyword (unless you update the section heading above).
Definition (in your own words) of the chosen keyword.
Demonstration of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification of chosen keyword (unless you update the section heading above).
Definition (in your own words) of the chosen keyword.
Demonstration of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification of chosen keyword (unless you update the section heading above).
Definition (in your own words) of the chosen keyword.
Demonstration of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification of chosen keyword (unless you update the section heading above).
Definition (in your own words) of the chosen keyword.
Demonstration of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification of chosen keyword (unless you update the section heading above).
Definition (in your own words) of the chosen keyword.
Demonstration of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification of chosen keyword (unless you update the section heading above).
Definition (in your own words) of the chosen keyword.
Demonstration of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification of chosen keyword (unless you update the section heading above).
Definition (in your own words) of the chosen keyword.
Demonstration of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
Identification of chosen keyword (unless you update the section heading above).
Definition (in your own words) of the chosen keyword.
Demonstration of the chosen keyword.
If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:
/* * Sample code block */ #include <stdio.h> int main() { return(0); }
Alternatively (or additionally), if you want to demonstrate something on the command-line, you can do so as follows:
lab46:~$ cd src lab46:~/src$ gcc -o hello hello.c lab46:~/src$ ./hello Hello, World! lab46:~/src$
What is the question you'd like to pose for experimentation? State it here.
Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.
Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.
State your rationale.
How are you going to test your hypothesis? What is the structure of your experiment?
Perform your experiment, and collect/document the results here.
Based on the data collected:
What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.