Skip to content

Commit 7f1b77b

Browse files
committed
Finished assembler and documented
1 parent f344179 commit 7f1b77b

11 files changed

Lines changed: 1085 additions & 91 deletions

File tree

README.md

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,94 @@
11
# CPU Assembler
2-
The assembler for the Nibble Knowledge CPU
2+
The assembler for the Nibble Knowledge CPU.
3+
4+
AS4
5+
---
6+
7+
AS4 is the low level assembler on written in C99 for the Nibble Knowledge CPU. It is under 700 lines of executable code, and recognises only 12 contructs:
8+
9+
### 8 instructions ###
10+
The Nibble Knowledge CPU has 8 instructions which are split into two different types:
11+
* Solitary instructions that do not require a memory address (has the format INST)
12+
* NOP: No operation
13+
* HLT: Halt CPU
14+
* CXA: Copy the carry bit (soon to be overflow bit?) and the XOR of that bit and the MSB of the accumulator.
15+
* Binary instructions that require a memory address (has the formal INST ADDR)
16+
* ADD: Add the nibble at the specified memory address to the accumulator.
17+
* NND: NAND the nibble at the specified memory address to the accumulator.
18+
* JMP: Jump to the specified memory address if the accumulator is 0.
19+
* LOD: Load the accumulator with the nibble at the specified address.
20+
* STR: Store the nibble in the accumulator to the specified memory address.
21+
22+
### 2 data types ###
23+
AS4 recognises two inbuilt data types:
24+
* Numberical values. Format: ".data SIZE INITIAL VALUE"
25+
* Strings, both plain and zero terminated. Format: ".ascii "String"" or ".asciiz "String""
26+
* Strings must start and end with double quotes.
27+
* AS4 recognises standard escape characters
28+
29+
### Labels ###
30+
Labels are of the format "NAME:". They are used to refer to memory locations without having to memorise or calculate number.
31+
An example of useage would be "number: .data 1 2", which is using the label "number" to point to a data element of 1 nibble in size with the initial value of 2.
32+
33+
### Comments ###
34+
Comments in AS4 start with a semicolon, ";".
35+
36+
### Example code ###
37+
; This program reads in integers and adds them together
38+
; until a negative number is read in. Then it outputs
39+
; the sum (not including the last number).
40+
41+
;Start: read ; read n -> acc
42+
; jmpn Done ; jump to Done if n < 0.
43+
; add sum ; add sum to the acc
44+
; store sum ; store the new sum
45+
; jump Start ; go back & read in next number
46+
;Done: load sum ; load the final sum
47+
; write ; write the final sum
48+
; stop ; stop
49+
;
50+
;sum: .data 2 0 ; 2-byte location where sum is stored
51+
52+
;; START NIbble-Knowledge code ;;
53+
54+
;; Instruction Section ;;
55+
56+
Start:
57+
LOD n15
58+
ADD n2
59+
NND n15
60+
NOP
61+
CXA
62+
JMP Jump
63+
STR sum
64+
65+
Jump: HLT
66+
67+
68+
;; Data Section ;;
69+
n0: .data 1 0 ; b0000
70+
n1: .data 1 1 ; b0001
71+
n2: .data 1 2 ; b0010
72+
n3: .data 1 3 ; b0011
73+
n4: .data 1 4 ; b0100
74+
n5: .data 1 5 ; b0101
75+
n6: .data 1 6 ; b0110
76+
n7: .data 1 7 ; b0111
77+
n8: .data 1 8 ; b1000
78+
n9: .data 1 9 ; b1001
79+
n10: .data 1 10 ; b1010
80+
n11: .data 1 11 ; b1011
81+
n12: .data 1 12 ; b1100
82+
n13: .data 1 13 ; b1101
83+
n14: .data 1 14 ; b1110
84+
n15: .data 1 15 ; b1111
85+
86+
derp: .data 6 0x454534
87+
88+
derp3: .ascii "hey there"
89+
derp4: .ascii "hey\" there\n"
90+
derp5: .asciiz "hey there"
91+
derp6: .asciiz "hey\" there\n"
92+
93+
sum: .data 1 0
94+

TestCodeNibbleV2.asm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
;; START NIbble-Knowledge code ;;
1717

1818
;; Instruction Section ;;
19+
1920
Start:
2021
LOD n15
2122
ADD n2
@@ -46,6 +47,15 @@ n13: .data 1 13 ; b1101
4647
n14: .data 1 14 ; b1110
4748
n15: .data 1 15 ; b1111
4849

50+
derp: .data 6 0x454534
51+
52+
derp3: .ascii "hey there"
53+
derp4: .ascii "hey\" there\n"
54+
derp5: .asciiz "hey there"
55+
derp6: .asciiz "hey\" there\n"
56+
4957
sum: .data 1 0
5058

5159

60+
61+

0 commit comments

Comments
 (0)