From 5690fb96f07e10ab9897fd424789843db29bb15b Mon Sep 17 00:00:00 2001 From: Erick Date: Sun, 13 Feb 2022 23:02:08 +0100 Subject: [PATCH] minor changes --- README.md | 23 +++++++++++------------ asm/asm_test.asm | 26 +++----------------------- asm/helloworld | 26 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 asm/helloworld diff --git a/README.md b/README.md index d0aab1d..d13116b 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ I created this project for fun during a week, looking at how others implemented ## 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. +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. 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. -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. +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: @@ -16,7 +16,6 @@ TyVM is a very barebone VM that has: - 16 opcodes - 10 registers - 3 condition flags - #### Memory It has 2^16(=65,536) individual memory locations ``` @@ -68,24 +67,24 @@ 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 30; -- [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: -``` +``` #define __UNIX -``` +``` Build using the command: -``` +``` gcc --std=c11 tyvm.c -o tyvm ``` Or simply using makefile (optional: in makefile change binary file name wether building on Unix or Windows): -``` +``` make ``` diff --git a/asm/asm_test.asm b/asm/asm_test.asm index 546e779..6aa640d 100644 --- a/asm/asm_test.asm +++ b/asm/asm_test.asm @@ -1,26 +1,6 @@ .ORIG x3000 - AND R0, R0, #0 - AND R1, R1, #0 - AND R3, R3, #0 - LEA R0, NUM - ADD R1, R1, R0 - LD R2, ASCII - -FOR_LOOP - LDR R4, R1, #0 - BRz END_LOOP - ADD R4, R4, R2 - STR R4, R1, #0 - ADD R1, R1, #1 - BRnzp FOR_LOOP -END_LOOP - - PUTs +LEA R0, HELLO_WORLD +PUTS HALT - -ASCII .fill x30 -NUM .fill x01 - .fill x02 - .fill x03 - .fill x04 +HELLO_STR .STRINGZ "Hello World!" .END \ No newline at end of file diff --git a/asm/helloworld b/asm/helloworld new file mode 100644 index 0000000..4445d3e --- /dev/null +++ b/asm/helloworld @@ -0,0 +1,26 @@ +.ORIG x3000 + AND R0, R0, #0 ; Clear R0 + AND R1, R1, #0 ; Clear R1 + AND R3, R3, #0 ; Clear R3 + LEA R0, NUM ; pointer [mem]NUM + ADD R1, R1, R0 ; Store the pointer address of R0 into R1 + LD R2, ASCII ; load the ascii offset into R2 + +FOR_LOOP + LDR R4, R1, #0 ; load the contents of mem address of R1 into R4 + BRz END_LOOP + ADD R4, R4, R2 ; Add our number to the ASCII offset + STR R4, R1, #0 ; Store the new value in R4 into [mem] address R1 + ADD R1, R1, #1 ; move our memory pointer down one + BRnzp FOR_LOOP ; loop again until we get an x00 char +END_LOOP + + PUTs ; print our string starting from [mem]address in R0 +HALT ; Trap x25 + +ASCII .fill x30 ; Our ASCII offset +NUM .fill x01 ; Our Number to print + .fill x02 + .fill x03 + .fill x04 +.END \ No newline at end of file