From 2cd09790c6ff45ea4dc319dbc21b916f1d4b6e85 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:33:36 +0100 Subject: [PATCH 01/16] Update README.md --- README.md | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5324367..47717a0 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,99 @@ # TyVM - [T]in[y] [V]irtual [M]achine -TyVM is a 16bit VM based on the LC-3 architechture +TyVM is a 16bit VM based on the LC-3 architechture that runs Assembly code, and could more generally run even an operating system -### HARDWARE: - - 16-bit on LC-3 architecture - - 128kb memory +## Resources +https://en.wikipedia.org/wiki/Little_Computer_3 + +### Build +On file "preprocessor.c" define the OS where you want to run TYVM: + + #define __UNIX + +Uncomment this line if you want to build for Unix based OS, otherwise comment it out to build for Windows +Build using the command: +``` +gcc tyvm.c -o tyvm +``` +Or simply using makefile (optional: in makefile change binary file name wether building on Unix or Windows): + +``` +make +``` + +### Hardware +TYVM is a very barebone 16-bit system on LC-3 architechture. It has: + - 128kb memory (65,536 memory locations) - 10 registers: - - 8 general purpose - - 1 program counter - - 1 condition register - 3 condition flags + +#### Memory +It has 2^16(=65,536) individual memory locations +``` +uint16_t memory[UINT16_MAX]; +``` +#### Registers +TYVM has n.10 16-bit registers. + - 8 general purpose registers + - 1 program counter (PC) + - 1 conditional register (COND) + +```c +enum { + RG_000 = 0, + RG_001, + RG_010, + RG_011, + RG_100, + RG_101, + RG_110, + RG_111, + RG_PC, + RG_COND, + RG_COUNT +}; +uint16_t registers[R_COUNT]; +``` +#### Instruction set +TYVM has n.16 16-bit opcodes, that instructs the machine to do some simple calculation: +```c +enum { // [name, 8-bit value] + OP_BR = 0, // branch, 0000 + OP_ADD, // add, 0001 + OP_LD, // load, 0010 + OP_ST, // store, 0011 + OP_JSR, // jump register, 0100 + OP_AND, // bitwise and, 0101 + OP_LDR, // load register, 0110 + OP_STR, // store register, 0111 + OP_RTI, // unused opcode + OP_NOT, // bitwise not, 1001 + OP_LDI, // indirect load, 1010 + OP_STI, // indirect store, 1011 + OP_JMP, // jump, 1100 + OP_RES, // reserved opcode, + OP_LEA, // load effective address, 1110 + OP_TRAP, // execute trap, 1111 +}; +``` + +### Logic +10 Load instruction from memory at program counter [RG_PC] address; +20 Increment RG_PC; +30 Read opcode for next instruction; +40 Perform instruction read in 40; +50 Goto 10; + +### Usage +```bash +./tyvm <*.asm> +``` + +- Below is a `hello-word` program for `TYVM`, the assembled program can be found in `asm` directory +```shell +.ORIG x3000 +LEA R0, HENLO_WORLD +PUTS +HALT +HELLO_STR .STRINGZ "Henlo World!" +.END +``` From aa05399c27bcf6cbbffe8f9155188f9961cf01e8 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:34:04 +0100 Subject: [PATCH 02/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 47717a0..15c41cd 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ enum { // [name, 8-bit value] ./tyvm <*.asm> ``` -- Below is a `hello-word` program for `TYVM`, the assembled program can be found in `asm` directory +Below is a `hello-word` program for `TYVM`, the assembled program can be found in `asm` directory ```shell .ORIG x3000 LEA R0, HENLO_WORLD From 2a1f47692cf917c13371613166e6872ea1b89846 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:37:12 +0100 Subject: [PATCH 03/16] Update README.md --- README.md | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 15c41cd..5b3bc34 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,13 @@ # TyVM - [T]in[y] [V]irtual [M]achine TyVM is a 16bit VM based on the LC-3 architechture that runs Assembly code, and could more generally run even an operating system -## Resources -https://en.wikipedia.org/wiki/Little_Computer_3 +## Introduction +LC-3 is a type of computer educational assembly language. +It features a relatively simple instruction set, but can be used to write moderately complex assembly programs, and is a viable target for a C compiler. The language is less complex than x86 assembly but has many features similar to those in more complex languages. These features make it useful for beginning instruction, so it is most often used to teach fundamentals of programming and computer architecture to computer science and computer engineering students. -### Build -On file "preprocessor.c" define the OS where you want to run TYVM: +The LC-3 specifies a word size of 16 bits for its registers and uses a 16-bit addressable memory with a 216-location address space. The register file contains eight registers, referred to by number as R0 through R7. All of the registers are general-purpose in that they may be freely used by any of the instructions that can write to the register file, but in some contexts (such as translating from C code to LC-3 assembly) some of the registers are used for special purposes. - #define __UNIX - -Uncomment this line if you want to build for Unix based OS, otherwise comment it out to build for Windows -Build using the command: -``` -gcc tyvm.c -o tyvm -``` -Or simply using makefile (optional: in makefile change binary file name wether building on Unix or Windows): - -``` -make -``` +Instructions are 16 bits wide and have 4-bit opcodes. The instruction set defines instructions for fifteen of the sixteen possible opcodes, though some instructions have more than one mode of operation. Individual instructions' execution is regulated by a state machine implemented with a control ROM and microsequencing unit. ### Hardware TYVM is a very barebone 16-bit system on LC-3 architechture. It has: @@ -83,6 +72,22 @@ enum { // [name, 8-bit value] 40 Perform instruction read in 40; 50 Goto 10; +### Build +On file "preprocessor.c" define the OS where you want to run TYVM: + + #define __UNIX + +Uncomment this line if you want to build for Unix based OS, otherwise comment it out to build for Windows +Build using the command: +``` +gcc tyvm.c -o tyvm +``` +Or simply using makefile (optional: in makefile change binary file name wether building on Unix or Windows): + +``` +make +``` + ### Usage ```bash ./tyvm <*.asm> From 4ac38c8d6f98edee2718facffa8317e4a0497125 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:39:02 +0100 Subject: [PATCH 04/16] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5b3bc34..75d53d5 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,10 @@ The LC-3 specifies a word size of 16 bits for its registers and uses a 16-bit ad Instructions are 16 bits wide and have 4-bit opcodes. The instruction set defines instructions for fifteen of the sixteen possible opcodes, though some instructions have more than one mode of operation. Individual instructions' execution is regulated by a state machine implemented with a control ROM and microsequencing unit. ### Hardware -TYVM is a very barebone 16-bit system on LC-3 architechture. It has: - - 128kb memory (65,536 memory locations) - - 10 registers: +TYVM is a very barebone VM that has: + - 128kb memory + - 16 opcodes + - 10 registers - 3 condition flags #### Memory From f6b78da17eb52ea1ebfa4e622d1086296c3548de Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:42:03 +0100 Subject: [PATCH 05/16] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 75d53d5..6da36d4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # TyVM - [T]in[y] [V]irtual [M]achine -TyVM is a 16bit VM based on the LC-3 architechture that runs Assembly code, and could more generally run even an operating system +TyVM is a 16bit VM based on LC-3 architechture that runs a barebone version of assembly code. The whole system is geared towards CS students or (like me) people passionate about computer architecture that are just learning about the topic. +I created this project for fun during a week, looking at how others implemented solutions for LC-3 based machines and getting inspiration from their work. ## Introduction LC-3 is a type of computer educational assembly language. From 21a94d1374009d7244bf175e97115fa14b573496 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:42:38 +0100 Subject: [PATCH 06/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6da36d4..b1a74f1 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ enum { RG_COND, RG_COUNT }; -uint16_t registers[R_COUNT]; +uint16_t registers[RG_COUNT]; ``` #### Instruction set TYVM has n.16 16-bit opcodes, that instructs the machine to do some simple calculation: From 4e870f825558faeec58d840511bfd1a888f6aed5 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:43:27 +0100 Subject: [PATCH 07/16] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b1a74f1..6492470 100644 --- a/README.md +++ b/README.md @@ -76,9 +76,9 @@ enum { // [name, 8-bit value] ### Build On file "preprocessor.c" define the OS where you want to run TYVM: - - #define __UNIX - +``` +#define __UNIX +``` Uncomment this line if you want to build for Unix based OS, otherwise comment it out to build for Windows Build using the command: ``` From a70f836051f13eddfa7926c8d08a51b9a7ba45f6 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:44:06 +0100 Subject: [PATCH 08/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6492470..9bd9559 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ make ./tyvm <*.asm> ``` -Below is a `hello-word` program for `TYVM`, the assembled program can be found in `asm` directory +Below is a hello-world program for `TYVM`, the assembled program can be found in `asm/` directory ```shell .ORIG x3000 LEA R0, HENLO_WORLD From 0dd22aae383815dbb47df5b4432514a905951458 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:45:34 +0100 Subject: [PATCH 09/16] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 9bd9559..fb4d860 100644 --- a/README.md +++ b/README.md @@ -75,11 +75,10 @@ enum { // [name, 8-bit value] 50 Goto 10; ### Build -On file "preprocessor.c" define the OS where you want to run TYVM: +On file "preprocessor.c" define the OS where you want to run TYVM. Uncomment the following line if you want to build for Windows, otherwise it will build for Unix: ``` #define __UNIX ``` -Uncomment this line if you want to build for Unix based OS, otherwise comment it out to build for Windows Build using the command: ``` gcc tyvm.c -o tyvm From 430b50b0d5aa5e50a4b9af8d1a20468079b2f6ea Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:46:01 +0100 Subject: [PATCH 10/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb4d860..c983425 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ enum { // [name, 8-bit value] 50 Goto 10; ### Build -On file "preprocessor.c" define the OS where you want to run TYVM. Uncomment the following line if you want to build for Windows, otherwise it will build for Unix: +On file "preprocessor.c" define the OS where you want to run TYVM. Comment out the following line if you want to build for Windows, otherwise it will build for Unix: ``` #define __UNIX ``` From c6a356ee8ff4de447b2265389f820ea0888b2ae2 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:46:33 +0100 Subject: [PATCH 11/16] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c983425..60dd2ca 100644 --- a/README.md +++ b/README.md @@ -68,11 +68,11 @@ enum { // [name, 8-bit value] ``` ### Logic -10 Load instruction from memory at program counter [RG_PC] address; -20 Increment RG_PC; -30 Read opcode for next instruction; -40 Perform instruction read in 40; -50 Goto 10; +- 10 Load instruction from memory at program counter [RG_PC] address; +- 20 Increment RG_PC; +- 30 Read opcode for next instruction; +- 40 Perform instruction read in 40; +- 50 Goto 10; ### Build On file "preprocessor.c" define the OS where you want to run TYVM. Comment out the following line if you want to build for Windows, otherwise it will build for Unix: From eb57e89dafde1495a22ed89456229893e3326937 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:47:24 +0100 Subject: [PATCH 12/16] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 60dd2ca..d11a2c4 100644 --- a/README.md +++ b/README.md @@ -68,11 +68,11 @@ enum { // [name, 8-bit value] ``` ### Logic -- 10 Load instruction from memory at program counter [RG_PC] address; -- 20 Increment RG_PC; -- 30 Read opcode for next instruction; -- 40 Perform instruction read in 40; -- 50 Goto 10; +- [10] Load instruction from memory at program counter [RG_PC] address; +- [20] Increment RG_PC; +- [30] Read opcode for next instruction; +- [40] Perform instruction read in 40; +- [50] Goto 10; ### Build On file "preprocessor.c" define the OS where you want to run TYVM. Comment out the following line if you want to build for Windows, otherwise it will build for Unix: From 392311894268b73db703c01a09565d90c1eeabf1 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:48:29 +0100 Subject: [PATCH 13/16] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d11a2c4..60fc444 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The LC-3 specifies a word size of 16 bits for its registers and uses a 16-bit ad Instructions are 16 bits wide and have 4-bit opcodes. The instruction set defines instructions for fifteen of the sixteen possible opcodes, though some instructions have more than one mode of operation. Individual instructions' execution is regulated by a state machine implemented with a control ROM and microsequencing unit. ### Hardware -TYVM is a very barebone VM that has: +TyVM is a very barebone VM that has: - 128kb memory - 16 opcodes - 10 registers @@ -23,7 +23,7 @@ It has 2^16(=65,536) individual memory locations uint16_t memory[UINT16_MAX]; ``` #### Registers -TYVM has n.10 16-bit registers. +TyVM has n.10 16-bit registers. - 8 general purpose registers - 1 program counter (PC) - 1 conditional register (COND) @@ -45,7 +45,7 @@ enum { uint16_t registers[RG_COUNT]; ``` #### Instruction set -TYVM has n.16 16-bit opcodes, that instructs the machine to do some simple calculation: +TyVM has n.16 16-bit opcodes, that instructs the machine to do some simple calculation: ```c enum { // [name, 8-bit value] OP_BR = 0, // branch, 0000 @@ -75,7 +75,7 @@ enum { // [name, 8-bit value] - [50] Goto 10; ### Build -On file "preprocessor.c" define the OS where you want to run TYVM. Comment out the following line if you want to build for Windows, otherwise it will build for Unix: +On file "preprocessor.c" define the OS where you want to run TyVM. Comment out the following line if you want to build for Windows, otherwise it will build for Unix: ``` #define __UNIX ``` @@ -94,7 +94,7 @@ make ./tyvm <*.asm> ``` -Below is a hello-world program for `TYVM`, the assembled program can be found in `asm/` directory +Below is a hello-world program for `TyVM`, the assembled program can be found in `asm/` directory ```shell .ORIG x3000 LEA R0, HENLO_WORLD From 3ee291606271bc3a70be5e401b11218ed6c62eb4 Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:50:09 +0100 Subject: [PATCH 14/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 60fc444..f932be5 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ On file "preprocessor.c" define the OS where you want to run TyVM. Comment out t ``` Build using the command: ``` -gcc tyvm.c -o tyvm +gcc --std=c11 tyvm.c -o tyvm ``` Or simply using makefile (optional: in makefile change binary file name wether building on Unix or Windows): From 6f59e331a6c4e0e8005dd7fd88fccd4fe132af8d Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:51:21 +0100 Subject: [PATCH 15/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f932be5..e2fed98 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ make ### Usage ```bash -./tyvm <*.asm> +./tyvm ``` Below is a hello-world program for `TyVM`, the assembled program can be found in `asm/` directory From 25d3e07cea4570369ddda359ed4bd879343651bd Mon Sep 17 00:00:00 2001 From: Erick <74315338+erickahmed@users.noreply.github.com> Date: Sun, 13 Feb 2022 18:10:33 +0100 Subject: [PATCH 16/16] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e2fed98..d0aab1d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Instructions are 16 bits wide and have 4-bit opcodes. The instruction set define ### Hardware TyVM is a very barebone VM that has: - - 128kb memory + - 128kb of memory - 16 opcodes - 10 registers - 3 condition flags @@ -47,7 +47,7 @@ uint16_t registers[RG_COUNT]; #### Instruction set TyVM has n.16 16-bit opcodes, that instructs the machine to do some simple calculation: ```c -enum { // [name, 8-bit value] +enum { // [name, 8-bit value] OP_BR = 0, // branch, 0000 OP_ADD, // add, 0001 OP_LD, // load, 0010 @@ -68,11 +68,11 @@ enum { // [name, 8-bit value] ``` ### Logic -- [10] Load instruction from memory at program counter [RG_PC] address; -- [20] Increment RG_PC; -- [30] Read opcode for next instruction; -- [40] Perform instruction read in 40; -- [50] Goto 10; +- [10] Load instruction from memory at program counter [RG_PC] address; +- [20] Increment RG_PC; +- [30] Read opcode for next instruction; +- [40] Perform instruction read in 30; +- [50] Goto 10; ### Build On file "preprocessor.c" define the OS where you want to run TyVM. Comment out the following line if you want to build for Windows, otherwise it will build for Unix: @@ -97,9 +97,9 @@ make Below is a hello-world program for `TyVM`, the assembled program can be found in `asm/` directory ```shell .ORIG x3000 -LEA R0, HENLO_WORLD +LEA R0, HELLO_WORLD PUTS HALT -HELLO_STR .STRINGZ "Henlo World!" +HELLO_STR .STRINGZ "Hello World!" .END ```