Today a minor milestone was reached.
The javascript assembler is working (for most instructions). I didn't work yet on the Javascript simulator .
But I also have a Logisim simulator. The assembler output for 'Hello World' was loaded in the Logisim simulator, and it worked ! It's the first real running program written in Kobold Assembly !
The program is this:
0 ; Kobold K2 assembler test 1 2 screen: equ 0xf000 3 newline: equ 0x0d 4 00000 7C00 5 mov 0,d0 00002 7A20 6 mov text,a2 00004 631E 7 mov screen,a3 00006 7008+ 8 loop: 00008 6540 9 mov (a2),d1 0000A 7242 10 add 2,a2 0000C 9560 11 mov d1,(a3) 0000E 4514 12 add 0xffff,d1 ;test for zero 00010 A092 b13 brc loop ; branch if non zero 00012 700C+ 14 hlt: jmp hlt 00014 6084 15 00016 AAAA 16 data section 00018 0014- 0001A 0008- 0001C FFFF- 0001E F000- 17 18 text: 00020 0048 19 dw 'H' 00022 0065 20 dw 'e' 00024 006C 21 dw 'l' 00026 006C 22 dw 'l' 00028 006F 23 dw 'o' 0002A 0020 24 dw ' ' 0002C 0057 25 dw 'W' 0002E 006F 26 dw 'o' 00030 0072 27 dw 'r' 00032 006C 28 dw 'l' 00034 0064 29 dw 'd' 00036 000D 30 dw newline 00038 0000 31 dw 0
Some remarks:
- In the instructions, source comes before destination: MOV SRC,DST
- The first instruction (mov 0,d0) is non-functional, because execution after reset skips the first instruction
- There is no HLT instruction. A the end of the string, the program just keeps jumping to the same HLT label.
- Note the use of the ADD 0xffff instruction to test for zero. That's because there only is a carry flag, no zero flag.
- Immediates that do not fit in 8 bits are 16 bits and placed at the end of a 16 word chunk, and flagged with a '-' for the human reader. so you find the 0xffff for the 'test for zero' on address 0x0001C. The values 0014 and 0008 are for branches to loop and hlt, to be discussed later.
- The logisim textscreen responds to writing to every address of 0x8000 and higher. The textscreen has the address 0xf000 in this example.
- The Logisim simulator can not read bytes from memory, so the text has been placed in words. The actual CPU wil be able to read bytes.
- Line 13 is marked 'b' and lines 8 and 14 are marked '+', both will be explained later.
- Actually, the page registers of A2 and A3 should have been set to 0 with an instruction, but in the simulator they are already zero by default. However, the reset hardware does set the page of PC to zero.
The Logisim file and the file to be loaded in the Logisim RAM are in the file section.
The assembler can be tried here: Kobold K2 Assembler. Just press 'Assemble' to run the assembler. Feel free to try some code changes. The assembler can load/store files from/to your own PC.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.