-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguageSpecH.txt
97 lines (73 loc) · 3.19 KB
/
LanguageSpecH.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
==Registers==
Represented by x, y, z, w.
Valid values: $x where x is 0-15 or ram or ramAdd or lit or tty or pc
$0-$11: are normal registers
$12/$ramAdd: is normal and also outputs to the RAMs address port.
$13/$ram: is the RAMs data ports, both load and store.
$14/$lit/$tty: is the literal value when read from, and the tty when written to.
$15/$pc: is the program counter.
==Booleans==
False: 0
True: != 0
==Operations==
lk x
* loads the next keyboard value into x
add x y z
* x + y -> z
minus x y z
* x - y -> z
negate x y
* Negates x (multiplies by -1) -> y
pt x y
* copies the value in x into y
* Pass Through
and x y z
* x (boolean and) y -> z
or x y z
* x (boolean or) y -> z
invert x y
* if x == 0 then 1 -> y
* if x != 0 then 0 -> y
gt x y z
* if x > y then 1 -> z else 0 -> z
e x y z
* if x == y then 1 -> z else 0 -> z
lt x y z
* if x < y then 1 -> z else 0 -> z
==Jump Instructions==
If the function is true, ALU outputs the new value, else ALU outputs the current Program Counter value + 1
In order for a jump to actually occur, the 4th argument should be $pc.
jgt w x y z
* if w > x then y -> z else program counter + 1 -> z
* jgt <arg1> <arg2> <new value> <destination register>
je w x y z
* if w == x then y -> z else program counter + 1 -> z
jlt w x y z
* if w < x then y -> z else program counter + 1 -> z
==Writing to TTY/Reading from the keyboard==
The terminal and keyboard both use ascii values. To convert a single digit number from ascii to decimal, minus 48 from it.
Eg. To write the number 8 to the terminal add 48 to it first.
There's no easy way to write multi digit numbers to the terminal or read them from the keyboard currently. This functionality would need software support.
The tty only looks at the first 7 bits of the number passed to it. The 8th (highest order) bit is discarded.
==Optional Literal==
All of these commands can also optionally set the literal value by appending a base 10 8 bit number onto the end of the command.
The assembler will check if there's an extra token on the end of the line and if so interpret it as a literal.
Ex. add $0 $6 $1 87 --> $0 + 87 -> $1
==Comments==
Since commands can now have an optional literal value on the end of the line, comments must begin with #.
Before a line is processed, if a # is present, it will be removed, along with everything after it.
==Example Commands== (coming soon)
Loading Ram:
pt $lit $ramAdd 24 #load 24 into the ram's address reg
pt $lit $ram 10 #store 10 into ram location 24
Reading from Ram:
pt $lit $ramAdd 24 #load 24 into the ram's address reg
pt $ram $0 #read the value from ram location 24 into register 0
Writing to the screen:
pt $lit $0 8 #load 8 into register 0
add $lit $0 $tty 48 #convert the 8 in register 0 into ascii by adding 48 and write it to the terminal
Read single digit from keyboard and convert from acsii to number:
lk $0 #read the next ascii character from the keyboard into register 0
minus $0 $lit $0 48 #convert the ascii value in register 0 into a decimal digit by subtracting 48
No-Op (command that does nothing):
pt $0 $0 #puts the value in register 0 into register 0