added v2.0
This commit is contained in:
1
07_Operating_System/07_String_Test/Array.jack
Symbolic link
1
07_Operating_System/07_String_Test/Array.jack
Symbolic link
@@ -0,0 +1 @@
|
||||
../Array.jack
|
1
07_Operating_System/07_String_Test/GPIO.jack
Symbolic link
1
07_Operating_System/07_String_Test/GPIO.jack
Symbolic link
@@ -0,0 +1 @@
|
||||
../GPIO.jack
|
83
07_Operating_System/07_String_Test/Main.jack
Normal file
83
07_Operating_System/07_String_Test/Main.jack
Normal file
@@ -0,0 +1,83 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: projects/12/StringTest/Main.jack
|
||||
|
||||
/** Test program for the OS String class. */
|
||||
class Main {
|
||||
|
||||
/** Performs various string manipulations and displays their results. */
|
||||
function void main() {
|
||||
var String s;
|
||||
var String i;
|
||||
|
||||
let s = String.new(0); // a zero-capacity string should be supported
|
||||
do s.dispose();
|
||||
|
||||
let s = String.new(6); // capacity 6, make sure that length 5 is displayed
|
||||
let s = s.appendChar(97);
|
||||
let s = s.appendChar(98);
|
||||
let s = s.appendChar(99);
|
||||
let s = s.appendChar(100);
|
||||
let s = s.appendChar(101);
|
||||
do StdIO.printString("new,appendChar: ");
|
||||
do StdIO.printString(s); // new, appendChar: abcde
|
||||
do StdIO.println();
|
||||
|
||||
let i = String.new(6);
|
||||
do i.setInt(12345);
|
||||
do StdIO.printString("setInt: ");
|
||||
do StdIO.printString(i); // setInt: 12345
|
||||
do StdIO.println();
|
||||
|
||||
let i = String.new(6);
|
||||
do i.setInt(-32767);
|
||||
do StdIO.printString("setInt: ");
|
||||
do StdIO.printString(i); // setInt: -32767
|
||||
do StdIO.println();
|
||||
|
||||
let s="abcde";
|
||||
do StdIO.printString("length: ");
|
||||
do StdIO.printInt(s.length()); // length: 5
|
||||
do StdIO.println();
|
||||
|
||||
do StdIO.printString("charAt[2]: ");
|
||||
do StdIO.printInt(s.charAt(2)); // charAt[2]: 99
|
||||
do StdIO.println();
|
||||
|
||||
do s.setCharAt(2, 45);
|
||||
do StdIO.printString("setCharAt(2,'-'): ");
|
||||
do StdIO.printString(s); // setCharAt(2,'-'): ab-de
|
||||
do StdIO.println();
|
||||
|
||||
let s="abcde";
|
||||
do s.eraseLastChar();
|
||||
do StdIO.printString("eraseLastChar: ");
|
||||
do StdIO.printString(s); // eraseLastChar: ab-d
|
||||
do StdIO.println();
|
||||
|
||||
let s = "456";
|
||||
do StdIO.printString("intValue: ");
|
||||
do StdIO.printInt(s.intValue()); // intValue: 456
|
||||
do StdIO.println();
|
||||
|
||||
let s = "-32123";
|
||||
do StdIO.printString("intValue: ");
|
||||
do StdIO.printInt(s.intValue()); // intValue: -32123
|
||||
do StdIO.println();
|
||||
|
||||
do StdIO.printString("backSpace: ");
|
||||
do StdIO.printInt(String.backSpace()); // backSpace: 129
|
||||
do StdIO.println();
|
||||
|
||||
do StdIO.printString("doubleQuote: ");
|
||||
do StdIO.printInt(String.doubleQuote());// doubleQuote: 34
|
||||
do StdIO.println();
|
||||
|
||||
do StdIO.printString("newLine: ");
|
||||
do StdIO.printInt(String.newLine()); // newLine: 128
|
||||
do StdIO.println();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
18
07_Operating_System/07_String_Test/Makefile
Normal file
18
07_Operating_System/07_String_Test/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
all: jack vm asm bin sim
|
||||
|
||||
jack:
|
||||
../../tools/JackCompiler/JackCompiler.pyc ./
|
||||
vm:
|
||||
../../tools/VMTranslator/VMTranslator.pyc ./
|
||||
asm:
|
||||
../../tools/Assembler/assembler.pyc out.asm
|
||||
bin:
|
||||
../../tools/AsciiToBin.py out.hack
|
||||
sim:
|
||||
cp out.hack ../00_HACK/ROM.hack
|
||||
upload:
|
||||
iceprogduino -o 64k -w out.bin
|
||||
clean:
|
||||
rm -f *.vm *.asm *.hack *.bin *~
|
||||
|
||||
.PHONY: all clean
|
1
07_Operating_System/07_String_Test/Math.jack
Symbolic link
1
07_Operating_System/07_String_Test/Math.jack
Symbolic link
@@ -0,0 +1 @@
|
||||
../Math.jack
|
1
07_Operating_System/07_String_Test/Memory.jack
Symbolic link
1
07_Operating_System/07_String_Test/Memory.jack
Symbolic link
@@ -0,0 +1 @@
|
||||
../Memory.jack
|
38
07_Operating_System/07_String_Test/Readme.md
Normal file
38
07_Operating_System/07_String_Test/Readme.md
Normal file
@@ -0,0 +1,38 @@
|
||||
## String.jack
|
||||
|
||||
Represents character strings. In addition for constructing and disposing strings, the class features methods for getting and setting individual characters of the string, for erasing the string's last character, for appending a character to the string's end, and more typical string-oriented operations.
|
||||
|
||||
***
|
||||
|
||||
### Project
|
||||
|
||||
* Implement `String.jack` and at least the function `StdIO.printString(String s)`
|
||||
|
||||
* Test by running `String_Test`, which performs several String operation and outputs them to StdIO (UART)
|
||||
|
||||
**Hint:** Use the debug register to show which caracters are transmitted over `UartTX`. Add the following code in function UART.writeChar():
|
||||
|
||||
```
|
||||
do Memory.Poke(4107,data)
|
||||
```
|
||||
|
||||

|
||||
|
||||
* Run String_Test in real hardware on iCE40HX1K-EVB using a terminal program connected to UART.
|
||||
|
||||
* Compare your terminal output with:
|
||||
|
||||
```
|
||||
new,appendChar: abcde
|
||||
setInt: 12345
|
||||
setInt: -32767
|
||||
length: 5
|
||||
charAt[2]: 99
|
||||
setCharAt(2,'-'): ab-de
|
||||
eraseLastChar: abcd
|
||||
intValue: 456
|
||||
intValue: -32123
|
||||
backSpace: 129
|
||||
doubleQuote: 34
|
||||
newLine: 128
|
||||
```
|
54
07_Operating_System/07_String_Test/Readme.md.backup
Normal file
54
07_Operating_System/07_String_Test/Readme.md.backup
Normal file
@@ -0,0 +1,54 @@
|
||||
## String.jack
|
||||
Represents character strings. In addition for constructing and disposing strings, the class features methods for getting and setting individual characters of the string, for erasing the string's last character, for appending a character to the string's end, and more typical string-oriented operations.
|
||||
### constructor String new(int maxLength)
|
||||
constructs a new empty string with a maximum length of maxLength and initial length of 0.
|
||||
### method void dispose()
|
||||
Disposes this string.
|
||||
### method int length()
|
||||
Returns the current length of this string.
|
||||
### method char charAt(int j)
|
||||
Returns the character at the j-th location of this string.
|
||||
### method String appendChar(char c)
|
||||
Appends c to this string's end and returns this string.
|
||||
### method void eraseLastChar()
|
||||
Erases the last character from this string.
|
||||
### method int intValue()
|
||||
Returns the integer value of this string until a non-digit character is detected.
|
||||
### method void setInt(int val)
|
||||
Sets this string to hold a representation of the given value.
|
||||
### function char newLine()
|
||||
Returns the new line character.
|
||||
### function char backSpace()
|
||||
Returns the backspace character.
|
||||
### function char doubleQuote()
|
||||
Returns the double quote (`"`) character.
|
||||
|
||||
***
|
||||
## Project
|
||||
* Implement `String.jack` and at least the function `StdIO.printString(String s)`
|
||||
* Test by running String_Test, which performs several String operation and outputs them to StdIO (UART)
|
||||
|
||||
**Hint:** Use the debug register to show which caracters are transmitted over UART_TX. Add the following code in function UART.writeChar():
|
||||
```
|
||||
do Memory.Poke(4107,data)
|
||||
```
|
||||
|
||||

|
||||
|
||||
* Run String_Test in real hardware on iCE40HX1K-EVB using a terminal program connected to UART.
|
||||
|
||||
* Compare your terminal output with:
|
||||
```
|
||||
new,appendChar: abcde
|
||||
setInt: 12345
|
||||
setInt: -32767
|
||||
length: 5
|
||||
charAt[2]: 99
|
||||
setCharAt(2,'-'): ab-de
|
||||
eraseLastChar: abcd
|
||||
intValue: 456
|
||||
intValue: -32123
|
||||
backSpace: 129
|
||||
doubleQuote: 34
|
||||
newLine: 128
|
||||
```
|
1
07_Operating_System/07_String_Test/StdIO.jack
Symbolic link
1
07_Operating_System/07_String_Test/StdIO.jack
Symbolic link
@@ -0,0 +1 @@
|
||||
../StdIO.jack
|
1
07_Operating_System/07_String_Test/String.jack
Symbolic link
1
07_Operating_System/07_String_Test/String.jack
Symbolic link
@@ -0,0 +1 @@
|
||||
../String.jack
|
BIN
07_Operating_System/07_String_Test/StringTestOutput.gif
Normal file
BIN
07_Operating_System/07_String_Test/StringTestOutput.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.9 KiB |
1
07_Operating_System/07_String_Test/Sys.jack
Symbolic link
1
07_Operating_System/07_String_Test/Sys.jack
Symbolic link
@@ -0,0 +1 @@
|
||||
../Sys.jack
|
1
07_Operating_System/07_String_Test/UART.jack
Symbolic link
1
07_Operating_System/07_String_Test/UART.jack
Symbolic link
@@ -0,0 +1 @@
|
||||
../UART.jack
|
BIN
07_Operating_System/07_String_Test/string.png
Normal file
BIN
07_Operating_System/07_String_Test/string.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 80 KiB |
Reference in New Issue
Block a user