├── ReadMe.org ├── automated_tests ├── Make.common └── lcc_regression │ ├── 8q.c │ ├── Makefile │ ├── array.c │ ├── fig14.1.c │ ├── fig14.10.c │ ├── fig14.11.c │ ├── fig14.2.c │ ├── fig15.1.c │ ├── fig15.2.c │ ├── fig15.3.c │ ├── fig15.4.c │ ├── fig16.1.c │ ├── fig16.10.c │ ├── fig16.12.c │ ├── fig16.13.c │ ├── fig16.14.c │ ├── fig16.4.c │ ├── fig16.6.c │ ├── fig16.8.c │ ├── fig16.9.c │ ├── fig17.13.c │ ├── fig17.18.c │ ├── fig18.1.c │ ├── incr.c │ ├── sort.c │ ├── spill.c │ ├── stdio.h │ ├── struct.c │ └── switch.c ├── doc └── Extending.org ├── lc3db ├── trunk │ ├── .cproject │ ├── .project │ ├── Makefile.in │ ├── arch │ │ ├── cpu.def │ │ └── lc3.cpu │ ├── configure │ ├── configure.in │ ├── ddd │ │ ├── history │ │ ├── init.in │ │ └── themes │ │ │ ├── lc3regs_2.vsl │ │ │ └── lc3regs_3.vsl │ ├── include │ │ ├── breakpoints.hpp │ │ ├── cpu.hpp │ │ ├── hardware.hpp │ │ ├── lexical_cast.hpp │ │ ├── memory.hpp │ │ ├── source_info.hpp │ │ └── util.hpp │ ├── lc3db.sh │ ├── lib │ │ └── .dummy │ ├── los │ │ └── los.asm │ ├── src │ │ ├── breakpoints.cpp │ │ ├── gdb.cpp │ │ ├── hardware.cpp │ │ ├── lc3.f │ │ ├── main.cpp │ │ ├── memory.cpp │ │ └── source_info.cpp │ └── tests │ │ ├── debug_info.c │ │ └── struct.c └── utexas.edu │ ├── asm_style.txt │ └── lc3db-1.0.tgz ├── lc3tools ├── CHANGE_LOG ├── COPYING ├── Makefile.def ├── NO_WARRANTY ├── README ├── configure ├── lc3.def ├── lc3.f ├── lc3convert.f ├── lc3os.asm ├── lc3sim-tk.def ├── lc3sim.c ├── lc3sim.h ├── symbol.c └── symbol.h ├── lcc-1.3 ├── .cproject ├── .project ├── AUTHORS ├── COPYING ├── CPYRIGHT ├── ChangeLog ├── Makefile.def ├── NEWS ├── NO_WARRANTY ├── README ├── TODO ├── configure ├── cpp │ ├── Makefile.def │ ├── cpp.c │ ├── cpp.h │ ├── eval.c │ ├── getopt.c │ ├── hideset.c │ ├── include.c │ ├── lex.c │ ├── macro.c │ ├── nlist.c │ ├── tokens.c │ └── unix.c ├── doc │ ├── bprint.1 │ ├── lburg.1 │ └── lcc.1 ├── etc │ ├── Makefile.def │ ├── lc3.c │ └── lcc.c ├── include │ ├── assert.h │ ├── float.h │ ├── limits.h │ ├── math.h │ └── stdarg.h ├── lburg │ ├── Makefile.def │ ├── gram.c │ ├── lburg.c │ └── lburg.h ├── lc3lib │ ├── __init.asm │ ├── getchar.asm │ ├── io_read.asm │ ├── io_write.asm │ ├── lc3io.h │ ├── printf.asm │ ├── ps2kbd_wait_read.asm │ ├── putchar.asm │ ├── scanf.asm │ ├── stdin_wait_read.asm │ ├── stdio.asm │ ├── stdio.h │ └── stdout_wait_write.asm ├── lc3pp │ ├── Makefile.def │ ├── SourcePaste.c │ └── lc3pp.c ├── lib │ ├── Makefile.def │ ├── assert.c │ ├── bbexit.c │ └── yynull.c ├── src │ ├── Makefile.def │ ├── alloc.c │ ├── alpha.md │ ├── bind.c │ ├── bytecode.c │ ├── c.h │ ├── config.h │ ├── dag.c │ ├── dagcheck.md │ ├── decl.c │ ├── enode.c │ ├── error.c │ ├── event.c │ ├── expr.c │ ├── gen.c │ ├── init.c │ ├── inits.c │ ├── input.c │ ├── lc3.md │ ├── lc3_stab.c │ ├── lc3_stab.h │ ├── lc3dtu.md │ ├── lex.c │ ├── list.c │ ├── main.c │ ├── mips.md │ ├── null.c │ ├── ops.h │ ├── output.c │ ├── prof.c │ ├── profio.c │ ├── simp.c │ ├── sparc.md │ ├── stab.c │ ├── stab.h │ ├── stmt.c │ ├── string.c │ ├── sym.c │ ├── symbolic.c │ ├── token.h │ ├── trace.c │ ├── tree.c │ ├── types.c │ ├── x86.md │ └── x86linux.md └── test │ ├── known_problems │ ├── arithmetic_expressions │ │ └── lfsr_random_using_xor.c │ └── constant_folding │ │ └── constant_folding.c │ ├── limitations │ ├── fig14.3.c │ ├── getchar.asm │ ├── init.asm │ ├── init.c │ ├── makefile │ ├── printf.asm │ ├── putchar.asm │ ├── scanf.asm │ ├── stdio.h │ └── wf1.c │ └── regression │ ├── 8q.c │ ├── Makefile │ ├── array.c │ ├── fig14.1.c │ ├── fig14.10.c │ ├── fig14.11.c │ ├── fig14.2.c │ ├── fig15.1.c │ ├── fig15.2.c │ ├── fig15.3.c │ ├── fig15.4.c │ ├── fig16.1.c │ ├── fig16.10.c │ ├── fig16.12.c │ ├── fig16.13.c │ ├── fig16.14.c │ ├── fig16.4.c │ ├── fig16.6.c │ ├── fig16.8.c │ ├── fig16.9.c │ ├── fig17.13.c │ ├── fig17.18.c │ ├── fig18.1.c │ ├── incr.c │ ├── sort.c │ ├── spill.c │ ├── stdio.h │ ├── struct.c │ └── switch.c └── serial ├── C_console ├── lc3Terminal.c ├── lc3Terminal.exe ├── lc3Terminal.lnk └── register_lc3_filetypes.cmd └── python ├── ProgramFileLoader.py ├── hexDump.py ├── testing ├── cat.asm ├── cat2.asm ├── cmds.txt └── serial_cat.py ├── wxGlade ├── wxSerialConfigDialog.wxg └── wxTerminal.wxg ├── wxSerialConfigDialog.py └── wxTerminal.py /ReadMe.org: -------------------------------------------------------------------------------- 1 | LC3 toolchain sources adapted for DTU 2 | 3 | + =automated_tests=: Tests programs to check the compliance of in-FPGA CPU with the simulator [no longer maintained]. 4 | + =lc3db=: Alternative LC3 simulator with gdb interface (can be used with DDD front end). 5 | + =lc3tools=: Unix LC3 assembler and simulator from the book accompanying web-site. 6 | + =lcc-1.3=: LCC based C compiler for LC3. 7 | + =serial=: Serial terminal for uploading the lc3 programs onto the FPGA system. 8 | 9 | 10 | * lc3db 11 | *Original authors:* \\ 12 | Anthony Liguori \\ 13 | *Source code:* \\ 14 | http://www.cs.utexas.edu/users/fussell/courses/cs310h/simulator/lc3db/index.html#download. 15 | 16 | ** Chages 17 | Various improvements: 18 | 1. Breakpoints, displays etc... 19 | 2. C-level debugging 20 | 21 | * lc3tools 22 | *Original authors:* \\ 23 | Steven S. Lumetta \\ 24 | *Source code:* \\ 25 | http://highered.mcgraw-hill.com/sites/dl/free/0072467509/104652/lc3tools_v12.zip 26 | 27 | ** Chages 28 | 1. Build script (configure/Makefile.def) modified to enable compilation to pure windows executables (using "--no-cygwin" option of the cygwin toolchain) 29 | 2. Bug fixes: 30 | 1. Object files were opened in "text" mode, causing corruption of generated files on windows (each '0x0D' byte was written as sequence of '0x0D' '0x0A'). 31 | 2. Where were no proper checks for strtol() returning error. 32 | 3. Range checking for immediate values was not done correctly: 33 | =ADD R1, R0, 31= was accepted as valid (though 15 is the highest allowed constant). The code generated would be =ADD R1, R0, -1=. 34 | 3. Input enable simulator. 35 | The simulator was using standard input for both control commands and to read the inputs for the program. It was also flushing input on command read, so it was hard to run a test with input. 36 | Extra command line options was added to use the input for the program from the separate file. 37 | 4. Extra instructions added: 38 | 1. Syntactic sugar: 39 | + NOP: alias to ".FILL x0000" 40 | + .BLKWTO: version of .BLKW which reserves memory until offset instead of reserving count words (used to align code to given address) 41 | 2. Immediate shifts: "SLL/SRA " are implemented in unused bits of ADD/AND. 42 | SLL (=0001.dr.sr1.01.imm4u=), SRA (=0101.dr.sr1.01.imm4u=). 43 | 3. Extra RRR format (3 reg) arithmetics: 44 | SLL,SRA,DIV,MOD and MUL implemented in reserved instruction (=1101.dr.sr1.func.sr2=) where 3bit 'func' field is 0,1,2... for SLL,SRA,DIV,MOD and MUL 45 | 5. Extra files generated: 46 | 1. =*.vconst= file used for memory initialisation from VHDL code 47 | 2. =*.dbg= file with debug information for lc3db 48 | 49 | * lcc-1.3 50 | *Original authors:* \\ 51 | - lcc authors: Christopher W. Fraser and David R. Hanson 52 | - lc3 adaptation: Ajay Ladsaria \\ 53 | *Source code:* \\ 54 | http://highered.mcgraw-hill.com/sites/dl/free/0072467509/104652/lcc.zip 55 | 56 | ** Chages 57 | 58 | 1. Enable compilation to pure windows executables: 59 | 1. Build script (configure/Makefile.def) modified to use "--no-cygwin" option of the cygwin toolchain 60 | 2. Paths in the source code were changed to use either unix or windows directory separators. 61 | 62 | 2. Bug Fixes: 63 | See: "LC3 Evaluation Report" (separate file). 64 | 65 | 3. Target with DTU processor extensions added to allow generation of more compact and efficient code: 66 | lcc-1.3/src/lc3.md was forked to lc3dtu.md. See: "Extending Compiler" 67 | To invoke generation of code with extensions add "-target=lc3dtu" option to the lcc commandline. 68 | 69 | 4. Removed linking of unused backends (sparc/mips/x86...), they wouldn't work anyway, because lc3 backend porters modified front end (mainly changed the limits for the types). 70 | 71 | 5. Implemented debug information. 72 | 73 | -------------------------------------------------------------------------------- /automated_tests/Make.common: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Common part of makefiles for compiling and running LC3 tests 3 | ################################################################################ 4 | # # Usage: 5 | # BASEDIR=../ 6 | # include $(BASEDIR)Make.common 7 | 8 | 9 | ####################### 10 | ## Command definitions 11 | 12 | #On some systems might need to use: ECHO=echo -e 13 | ECHO=echo 14 | 15 | SED=sed 16 | # On SUN use gsed 17 | #SED=gsed 18 | 19 | LCC=lcc 20 | LCAS=lc3as 21 | LCSIM=lc3sim 22 | 23 | PYTHON?=/cygdrive/c/Python26/python 24 | 25 | lcc_stat=$(BASEDIR)sh/lcc_stat 26 | lcc_split=$(BASEDIR)sh/lcc_split 27 | 28 | RUN_FPGA=$(PYTHON) 'c:\lc3\bin\serial_cat.py' -b $(SERIAL_BAUD) 29 | CROP_OUTPUT_FPGA=$(SED) '0,/^--- Starting user code at x3000... ---/ d; /^--- halting the LC-3 ---/,$$ d; /^ *$$/ d' 30 | 31 | RUN_SIM=$(ECHO) "option flush off\ncontinue\nquit" | $(LCSIM) 32 | #CROP_OUTPUT_SIM=$(SED) -n '/^(lc3sim)/,/^--- halting the LC-3 ---/ { /^ *$$/ d; /^(lc3sim) Will not flush the console/ d; s/^(lc3sim) //; /^--- halting the LC-3/ d; p } ' 33 | CROP_OUTPUT_SIM=$(SED) '1,/^(lc3sim) continue/ d ; /^--- halting the LC-3/,$$ d; /^ *$$/ d' 34 | 35 | 36 | ##############**########### 37 | ## Additional pattern rules 38 | 39 | %.lcc : %.c 40 | $(LCC) -c $< 41 | 42 | %.asm : %.c 43 | $(LCC) -L $< -o $@ 44 | 45 | %.obj %.sym %.ser : %.asm 46 | $(LCAS) $< 47 | # don't delete *.asm files after compilation 48 | .PRECIOUS: %.asm 49 | 50 | %.exe: %.c 51 | $(CC) -o $@ $< 52 | 53 | log.%.host: %.exe 54 | @echo 'Running native version of code (output stored in "$@")' 55 | ./$< > $@ 56 | # don't delete compiled host executable after running it 57 | .PRECIOUS: %.exe 58 | 59 | ifdef TEST_FPGA 60 | 61 | log.%.lc3: %.ser 62 | @echo 'Running LC3 version of code (output stored in "$@")' 63 | $(RUN_FPGA) -O $< -s $@ 64 | $(CROP_OUTPUT_FPGA) -i $@ 65 | 66 | else # use simulator 67 | 68 | log.%.lc3: %.obj 69 | $(RUN_SIM) $< >$@ 70 | $(CROP_OUTPUT_SIM) -i $@ 71 | #log.%.lc3: %.obj 72 | # $(RUN_SIM) -fileio /dev/null $@ $< 73 | # $(CROP_OUTPUT_SIM) -i $@ 74 | 75 | endif 76 | # don't delete *.obj files after compilation 77 | .PRECIOUS: %.obj %.ser 78 | 79 | %.test: log.%.host log.%.lc3 80 | diff -uw $^ > $@ 81 | # don't delete log files after compilation 82 | .PRECIOUS: log.%.host log.%.lc3 83 | 84 | 85 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/8q.c: -------------------------------------------------------------------------------- 1 | int up[15], down[15], rows[8], x[8]; 2 | int queens(), print(); 3 | 4 | main() 5 | { 6 | int i; 7 | 8 | for (i = 0; i < 15; i++) 9 | up[i] = down[i] = 1; 10 | for (i = 0; i < 8; i++) 11 | rows[i] = 1; 12 | queens(0); 13 | return 0; 14 | } 15 | 16 | queens(c) 17 | { 18 | int r; 19 | 20 | for (r = 0; r < 8; r++) 21 | if (rows[r] && up[r-c+7] && down[r+c]) { 22 | rows[r] = up[r-c+7] = down[r+c] = 0; 23 | x[c] = r; 24 | if (c == 7) 25 | print(); 26 | else 27 | queens(c + 1); 28 | rows[r] = up[r-c+7] = down[r+c] = 1; 29 | } 30 | } 31 | 32 | print() 33 | { 34 | int k; 35 | 36 | for (k = 0; k < 8; k++) 37 | printf("%c ", x[k]+'1'); 38 | printf("\n"); 39 | } 40 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/Makefile: -------------------------------------------------------------------------------- 1 | # Set your customisations here: 2 | #TEST_FPGA=1 # Run LC3 executable on the FPGA. Comment if simulation based test is prefered 3 | PYTHON=/cygdrive/c/Python26/python 4 | SERIAL_BAUD=115200 5 | #SERIAL_BAUD=19200 6 | 7 | 8 | # Use common file 9 | BASEDIR=../ 10 | include $(BASEDIR)Make.common 11 | 12 | LCC=lcc -g #-target=lc3dtu 13 | 14 | SRC=$(wildcard *.c) 15 | ASM=$(SRC:.c=.asm) 16 | ASM_LCC=$(SRC:.c=.lcc) 17 | OBJ=$(SRC:.c=.obj) 18 | 19 | NO_INPUT_SRC=8q array fig14.1 fig15.1 fig15.2 fig16.1 fig16.4 incr sort spill struct switch 20 | NO_INPUT_TESTS=$(NO_INPUT_SRC:=.test) 21 | # $(patsubst %.c,%.o $(patsubst %.c,%.bar.c) 22 | 23 | 24 | compile_all: $(ASM) $(ASM_LCC) 25 | 26 | 27 | tests: $(NO_INPUT_TESTS) 28 | 29 | 30 | 31 | clean: 32 | $(RM) *.exe *.obj *.sym *.asm *.lcc *.ser *.bin log.*.host log.*.lc3 33 | $(RM) $(NO_INPUT_TESTS) 34 | 35 | 36 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/array.c: -------------------------------------------------------------------------------- 1 | int x[3][4], *y[3]; 2 | 3 | main() { 4 | int z[3][4]; 5 | int i, j, *p; 6 | 7 | for (i = 0; i < 3; i++) { 8 | for (j = 0; j < 4; j++) 9 | x[i][j] = 1000*i + j; 10 | y[i] = x[i]; 11 | } 12 | af(); 13 | for (i = 0; i < 3; i++) { 14 | y[i] = p = &z[i][0]; 15 | for (j = 0; j < 4; j++) 16 | p[j] = x[i][j]; 17 | } 18 | ag(z, y); 19 | return 0; 20 | } 21 | 22 | af() { 23 | int i, j; 24 | 25 | for (i = 0; i < 3; i++) 26 | for (j = 0; j < 4; j++) 27 | printf(" %d", x[i][j]); 28 | printf("\n"); 29 | for (i = 0; i < 3; i++) 30 | for (j = 0; j < 4; j++) 31 | printf(" %d", y[i][j]); 32 | printf("\n"); 33 | } 34 | 35 | ag(x, y) 36 | int x[][4], *y[]; 37 | { 38 | int i, j; 39 | 40 | for (i = 0; i < 3; i++) 41 | for (j = 0; j < 4; j++) 42 | printf(" %d", x[i][j]); 43 | printf("\n"); 44 | for (i = 0; i < 3; i++) 45 | for (j = 0; j < 4; j++) 46 | printf(" %d", y[i][j]); 47 | printf("\n"); 48 | } 49 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig14.1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void PrintBanner(); /* Function declaration */ 4 | 5 | int main() 6 | { 7 | PrintBanner(); /* Function call */ 8 | printf("A simple C program.\n"); 9 | PrintBanner(); 10 | return 0; 11 | } 12 | 13 | void PrintBanner() /* Function definition */ 14 | { 15 | printf("============================\n"); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig14.10.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Function declaration */ 4 | char ToUpper(char inchar); 5 | 6 | /* Function main: */ 7 | /* Prompt for a line of text, Read one character, */ 8 | /* convert to uppercase, print it out, then get another */ 9 | int main() 10 | { 11 | char echo = 'A'; /* Initialize input character */ 12 | char upcase; /* Converted character */ 13 | 14 | while (echo != '\n') { 15 | scanf("%c", &echo); 16 | upcase = ToUpper(echo); 17 | printf("%c", upcase); 18 | } 19 | return 0; 20 | } 21 | 22 | /* Function ToUpper: */ 23 | /* If the parameter is lower case return */ 24 | /* its uppercase ASCII value */ 25 | char ToUpper(char inchar) 26 | { 27 | char outchar; 28 | 29 | if ('a' <= inchar && inchar <= 'z') 30 | outchar = inchar - ('a' - 'A'); 31 | else 32 | outchar = inchar; 33 | 34 | return outchar; 35 | } 36 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig14.11.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int Squared(int x); 4 | 5 | int main() 6 | { 7 | int sideA; 8 | int sideB; 9 | int sideC; 10 | int maxC; 11 | 12 | printf("Enter the maximum length of hypotenuse: "); 13 | scanf("%d", &maxC); 14 | 15 | for (sideC = 1; sideC <= maxC; sideC++) { 16 | for (sideB = 1; sideB <= maxC; sideB++) { 17 | for (sideA = 1; sideA <= maxC; sideA++) { 18 | if (Squared(sideC) == Squared(sideA) + Squared(sideB)) 19 | printf("%d %d %d\n", sideA, sideB, sideC); 20 | } 21 | } 22 | } 23 | return 0; 24 | } 25 | 26 | /* Calculate the square of a number */ 27 | int Squared(int x) 28 | { 29 | return x * x; 30 | } 31 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig14.2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int Factorial(int n); /*! Function Declaration !*/ 4 | 5 | int main() /* Definition for main */ 6 | { 7 | int number; /* Number from user */ 8 | int answer; /* Answer of factorial */ 9 | 10 | printf("Input a number: "); /* Call to printf */ 11 | 12 | scanf("%d", &number); /* Call to scanf */ 13 | 14 | answer = Factorial(number); /*! Call to factorial !*/ 15 | 16 | printf("The factorial of %d is %d\n", number, answer); 17 | return 0; 18 | } 19 | 20 | int Factorial(int n) /*! Function Definition !*/ 21 | { 22 | int i; /* Iteration count */ 23 | int result = 1; /* Initialized result */ 24 | 25 | for (i = 1; i <= n; i++) /* Calculate factorial */ 26 | result = result * i; 27 | 28 | return result; /*! Return to caller !*/ 29 | } 30 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig15.1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i; 6 | int j; 7 | 8 | for (i = 0; i <= 10; i++) { 9 | j = i * 7; 10 | printf("%d x 7 = %d\n", i, j); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig15.2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i; 6 | int j; 7 | 8 | for (i = 0; i <= 10; i++) 9 | j = i * 7; 10 | printf("%d x 7 = %d\n", i, j); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig15.3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int AllSum(int n); 4 | 5 | int main() 6 | { 7 | int in; /* Input value */ 8 | int sum; /* Value of 1+2+3+..+n */ 9 | 10 | printf("Input a number: "); 11 | scanf("%d", &in); 12 | 13 | sum = AllSum(in); 14 | printf("The AllSum of %d is %d\n", in, sum); 15 | return 0; 16 | } 17 | 18 | 19 | int AllSum(int n) 20 | { 21 | int result; /* Result to be returned */ 22 | int i; /* Iteration count */ 23 | 24 | for (i = 1; i <= n; i++) /* This calculates sum */ 25 | result = result + i; 26 | 27 | return result; /* Return to caller */ 28 | } 29 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig15.4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int year; 6 | 7 | printf("Input a year (i.e., 1996): "); 8 | scanf("%d", &year); 9 | 10 | if (year % 4 == 0) 11 | printf("This year is a leap year\n"); 12 | else 13 | printf("This year is not a leap year\n"); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig16.1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Swap(int firstVal, int secondVal); 4 | 5 | int main() 6 | { 7 | int valueA = 3; 8 | int valueB = 4; 9 | 10 | printf("Before Swap "); 11 | printf("valueA = %d and valueB = %d\n", valueA, valueB); 12 | 13 | Swap(valueA, valueB); 14 | 15 | printf("After Swap "); 16 | printf("valueA = %d and valueB = %d\n", valueA, valueB); 17 | return 0; 18 | } 19 | 20 | void Swap(int firstVal, int secondVal) 21 | { 22 | int tempVal; /* Holds firstVal when swapping */ 23 | 24 | tempVal = firstVal; 25 | firstVal = secondVal; 26 | secondVal = tempVal; 27 | } 28 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig16.10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX_NUMS 10 3 | 4 | int Average(int input_values[]); 5 | 6 | int main() 7 | { 8 | int index; /* Loop iteration variable */ 9 | int mean; /* average of numbers */ 10 | int numbers[MAX_NUMS]; /* Original input numbers */ 11 | 12 | 13 | /* Get input */ 14 | printf("Enter %d numbers.\n", MAX_NUMS); 15 | for (index = 0; index < MAX_NUMS; index++) { 16 | printf("Input number %d : ", index); 17 | scanf("%d", &numbers[index]); 18 | } 19 | 20 | mean = Average(numbers); 21 | 22 | printf("The average of these numbers is %d\n", mean); 23 | return 0; 24 | } 25 | 26 | int Average(int inputValues[]) 27 | { 28 | int index; 29 | int sum = 0; 30 | 31 | for (index = 0; index < MAX_NUMS; index++) { 32 | sum = sum + inputValues[index]; 33 | } 34 | 35 | return (sum / MAX_NUMS); 36 | } 37 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig16.12.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX_STRING 20 3 | 4 | int StringLength(char string[]); 5 | 6 | int main() 7 | { 8 | char input[MAX_STRING]; /* Input string */ 9 | int length = 0; 10 | 11 | printf("Input a word (less than 20 characters): "); 12 | scanf("%s", input); 13 | 14 | length = StringLength(input); 15 | printf("The word contains %d characters\n", length); 16 | return 0; 17 | } 18 | 19 | int StringLength(char string[]) 20 | { 21 | int index = 0; 22 | 23 | while (string[index] != '\0') 24 | index = index + 1; 25 | 26 | return index; 27 | } 28 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig16.13.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX_STRING 20 3 | 4 | int StringLength(char string[]); 5 | void CharSwap(char *firstVal, char *secondVal); 6 | void Reverse(char string[]); 7 | 8 | int main() 9 | { 10 | char input[MAX_STRING]; /* Input string */ 11 | 12 | printf("Input a word (less than 20 characters): "); 13 | scanf("%s", input); 14 | 15 | Reverse(input); 16 | printf("The word reversed is %s.\n", input); 17 | return 0; 18 | } 19 | 20 | int StringLength(char string[]) 21 | { 22 | int index = 0; 23 | 24 | while (string[index] != '\0') 25 | index = index + 1; 26 | 27 | return index; 28 | } 29 | 30 | void CharSwap(char *firstVal, char *secondVal) 31 | { 32 | char tempVal; /* Temporary location for swapping */ 33 | 34 | tempVal = *firstVal; 35 | *firstVal = *secondVal; 36 | *secondVal = tempVal; 37 | } 38 | 39 | void Reverse(char string[]) 40 | { 41 | int index; 42 | int length; 43 | 44 | length = StringLength(string); 45 | 46 | for (index = 0; index < (length / 2); index++) 47 | CharSwap(&string[index], &string[length - (index + 1)]); 48 | } 49 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig16.14.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX_NUMS 10 3 | 4 | void InsertionSort(int list[]); 5 | 6 | int main() 7 | { 8 | int index; /* iteration variable */ 9 | int numbers[MAX_NUMS]; /* list of number to be sorted */ 10 | 11 | /* Get input */ 12 | printf("Enter %d numbers.\n", MAX_NUMS); 13 | for (index = 0; index < MAX_NUMS; index++) { 14 | printf("Input number %d : ", index); 15 | scanf("%d", &numbers[index]); 16 | } 17 | 18 | InsertionSort(numbers); /* Call sorting routine */ 19 | 20 | /* Print sorted list */ 21 | printf("\nThe input set, in ascending order:\n"); 22 | for (index = 0; index < MAX_NUMS; index++) 23 | printf("%d\n", numbers[index]); 24 | return 0; 25 | } 26 | 27 | void InsertionSort(int list[]) 28 | { 29 | int unsorted; /* index for unsorted list items */ 30 | int sorted; /* index for sorted items */ 31 | int unsortedItem; /* Current item to be sorted */ 32 | 33 | /* This loop iterates from 1 thru MAX_NUMS */ 34 | for (unsorted = 1; unsorted < MAX_NUMS; unsorted++) { 35 | unsortedItem = list[unsorted]; 36 | 37 | /* This loop iterates from unsorted thru 0, unless 38 | we hit an element smaller than current item */ 39 | for (sorted = unsorted - 1; 40 | (sorted >= 0) && (list[sorted] > unsortedItem); 41 | sorted--) 42 | list[sorted + 1] = list[sorted]; 43 | 44 | list[sorted + 1] = unsortedItem; /* Insert item */ 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig16.4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void NewSwap(int *firstVal, int *secondVal); 4 | 5 | int main() 6 | { 7 | int valueA = 3; 8 | int valueB = 4; 9 | 10 | printf("Before Swap "); 11 | printf("valueA = %d and valueB = %d\n", valueA, valueB); 12 | 13 | NewSwap(&valueA, &valueB); 14 | 15 | printf("After Swap "); 16 | printf("valueA = %d and valueB = %d\n", valueA, valueB); 17 | return 0; 18 | } 19 | 20 | void NewSwap(int *firstVal, int *secondVal) 21 | { 22 | int tempVal; /* Holds firstVal when swapping */ 23 | 24 | tempVal = *firstVal; 25 | *firstVal = *secondVal; 26 | *secondVal = tempVal; 27 | } 28 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig16.6.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int IntDivide(int x, int y, int *quoPtr, int *remPtr); 4 | 5 | int main() 6 | { 7 | int dividend; /* The number to be divided */ 8 | int divisor; /* The number to divide by */ 9 | int quotient; /* Integer result of division */ 10 | int remainder; /* Integer remainder of division */ 11 | int error; /* Did something go wrong? */ 12 | 13 | printf("Input dividend: "); 14 | scanf("%d", ÷nd); 15 | printf("Input divisor: "); 16 | scanf("%d", &divisor); 17 | 18 | error = IntDivide(dividend,divisor,"ient,&remainder); 19 | 20 | if (!error) /* !error indicates no error */ 21 | printf("Answer: %d remainder %d\n", quotient, remainder); 22 | else 23 | printf("IntDivide failed.\n"); 24 | return 0; 25 | } 26 | 27 | int IntDivide(int x, int y, int *quoPtr, int *remPtr) 28 | { 29 | if (y != 0) { 30 | *quoPtr = x / y; /* Modify *quoPtr */ 31 | *remPtr = x % y; /* Modify *remPtr */ 32 | return 0; 33 | } 34 | else 35 | return -1; 36 | } 37 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig16.8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define NUM_STUDENTS 10 3 | 4 | int main() 5 | { 6 | int i; 7 | int Exam1[NUM_STUDENTS]; 8 | int Exam2[NUM_STUDENTS]; 9 | int Total[NUM_STUDENTS]; 10 | 11 | /* Input Exam 1 scores */ 12 | for (i = 0; i < NUM_STUDENTS; i++) { 13 | printf("Input Exam 1 score for student %d : ", i); 14 | scanf("%d", &Exam1[i]); 15 | } 16 | printf("\n"); 17 | 18 | /* Input Exam 2 scores */ 19 | for (i = 0; i < NUM_STUDENTS; i++) { 20 | printf("Input Exam 2 score for student %d : ", i); 21 | scanf("%d", &Exam2[i]); 22 | } 23 | printf("\n"); 24 | 25 | /* Calculate Total Points */ 26 | for (i = 0; i < NUM_STUDENTS; i++) { 27 | Total[i] = Exam1[i] + Exam2[i]; 28 | } 29 | 30 | /* Output the Total Points */ 31 | for (i = 0; i < NUM_STUDENTS; i++) { 32 | printf("Total for Student %d = %d\n", i, Total[i]); 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig16.9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX_NUMS 10 3 | 4 | int main() 5 | { 6 | int index; /* Loop iteration variable */ 7 | int repIndex; /* Loop variable for rep loop */ 8 | int numbers[MAX_NUMS]; /* Original input numbers */ 9 | int repeats[MAX_NUMS]; /* Number of repeats */ 10 | 11 | /* Get input */ 12 | printf("Enter %d numbers.\n", MAX_NUMS); 13 | for (index = 0; index < MAX_NUMS; index++) { 14 | printf("Input number %d : ", index); 15 | scanf("%d", &numbers[index]); 16 | } 17 | 18 | /* Scan through entire array, counting number of */ 19 | /* repeats per element within the original array */ 20 | for (index = 0; index < MAX_NUMS; index++) { 21 | repeats[index] = 0; 22 | for (repIndex = 0; repIndex < MAX_NUMS; repIndex++) { 23 | if (numbers[repIndex] == numbers[index]) 24 | repeats[index]++; 25 | } 26 | } 27 | 28 | /* Print the results */ 29 | for (index = 0; index < MAX_NUMS; index++) 30 | printf("Original number %d. Number of repeats %d\n", 31 | numbers[index], repeats[index]); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig17.13.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int Fibonacci(int n); 4 | 5 | int main() 6 | { 7 | int in; 8 | int number; 9 | 10 | printf("Which Fibonacci number? "); 11 | scanf("%d", &in); 12 | 13 | number = Fibonacci(in); 14 | printf("That Fibonacci number is %d\n", number); 15 | return 0; 16 | } 17 | 18 | int Fibonacci(int n) 19 | { 20 | int sum; 21 | 22 | if (n == 0 || n == 1) 23 | return 1; 24 | else { 25 | sum = (Fibonacci(n-1) + Fibonacci(n-2)); 26 | return sum; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig17.18.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void IntToAscii(int i); 4 | 5 | int main() 6 | { 7 | int in; 8 | 9 | printf("Input number: "); 10 | scanf("%d", &in); 11 | 12 | IntToAscii(in); 13 | printf("\n"); 14 | return 0; 15 | } 16 | 17 | void IntToAscii(int num) 18 | { 19 | int prefix; 20 | int currDigit; 21 | 22 | if (num < 10) /* The terminal case */ 23 | printf("%c", num + '0'); 24 | else { 25 | prefix = num / 10; /* Convert the number */ 26 | IntToAscii(prefix); /* without last digit */ 27 | 28 | currDigit = num % 10; /* Then print last digit */ 29 | printf("%c", currDigit + '0'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/fig18.1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char inChar1; 6 | char inChar2; 7 | 8 | printf("Input character 1:\n"); 9 | inChar1 = getchar(); 10 | 11 | printf("Input character 2:\n"); 12 | inChar2 = getchar(); 13 | 14 | printf("Character 1 is %c\n", inChar1); 15 | printf("Character 2 is %c\n", inChar2); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/incr.c: -------------------------------------------------------------------------------- 1 | char gx = 'd'; 2 | char gy = 'd'; 3 | int a = 60; 4 | int b = 10; 5 | 6 | main() { 7 | memchar(); 8 | memint(); 9 | regchar(); 10 | regint(); 11 | return 0; 12 | } 13 | 14 | memchar() { 15 | char x, *p; 16 | 17 | &x, &p; 18 | x = gx; 19 | p = &gy; 20 | x = *p++; 21 | x = *++p; 22 | x = *p--; 23 | x = *--p; 24 | printf("%c %c\n",x,*p); 25 | } 26 | 27 | memint() { 28 | int x, *p; 29 | 30 | &x, &p; 31 | 32 | x = a; 33 | p = &b; 34 | x = *p++; 35 | x = *++p; 36 | x = *p--; 37 | x = *--p; 38 | printf("%d %x %o %d\n",x, x, x,*p); 39 | printf("%d %d\n", x,*p); 40 | } 41 | 42 | regchar() { 43 | register char x, *p; 44 | x = gx; 45 | p = &gy; 46 | 47 | x = *p++; 48 | x = *++p; 49 | x = *p--; 50 | x = *--p; 51 | printf("%c %c\n",x,*p); 52 | } 53 | 54 | regint() { 55 | register int x, *p; 56 | 57 | x = a; 58 | p = &b; 59 | x = *p++; 60 | x = *++p; 61 | x = *p--; 62 | x = *--p; 63 | printf("%x %d\n",x,*p); 64 | } 65 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/sort.c: -------------------------------------------------------------------------------- 1 | short nn[] = {10, 32, -1, 567, 3, 18, 1, -51, 789, 1}; 2 | short foo[] = { 1, 2, 3, 4, 5 }; 3 | 4 | main() { 5 | int i; 6 | 7 | //sort(nn, (sizeof nn)/(sizeof nn[0])); 8 | for (i = 0; i < (sizeof nn)/(sizeof nn[0]); i++) { 9 | putd(nn[i]); 10 | putchar('\n'); 11 | //printf("%d/10=%d\n;\n %d%%10=%d\n;\n", nn[i], nn[i]/10, nn[i], nn[i]%10); 12 | //printf("%d*%d=%hd\n;\n", nn[i], nn[i+1], nn[i]*nn[i+1]); 13 | //printf("%d*%d=%hd\n;\n", nn[i], nn[i+2], nn[i]*nn[i+2]); 14 | //printf("%d*%d=%hd\n;\n", nn[i], nn[i+3], nn[i]*nn[i+3]); 15 | //printf("%d/%d=%hd\n;\n", nn[i], nn[i+1], nn[i]/nn[i+1]); 16 | //printf("%d/%d=%hd\n;\n", nn[i], nn[i+2], nn[i]/nn[i+2]); 17 | //printf("%d/%d=%hd\n;\n", nn[i], nn[i+3], nn[i]/nn[i+3]); 18 | //printf("%d%%%d=%hd\n;\n", nn[i], nn[i+1], nn[i]%nn[i+1]); 19 | //printf("%d%%%d=%hd\n;\n", nn[i], nn[i+2], nn[i]%nn[i+2]); 20 | //printf("%d%%%d=%hd\n;\n", nn[i], nn[i+3], nn[i]%nn[i+3]); 21 | } 22 | return 0; 23 | } 24 | 25 | /* putd - output decimal number */ 26 | putd(n) { 27 | if (n < 0) { 28 | putchar('-'); 29 | n = -n; 30 | } 31 | if (n/10) 32 | putd(n/10); 33 | putchar(n%10 + '0'); 34 | } 35 | 36 | int *xx; 37 | 38 | /* sort - sort a[0..n-1] into increasing order */ 39 | sort(a, n) int a[]; { 40 | quick(xx = a, 0, --n); 41 | } 42 | 43 | /* quick - quicksort a[lb..ub] */ 44 | quick(a, lb, ub) int a[]; { 45 | int k, partition(); 46 | 47 | if (lb >= ub) 48 | return; 49 | k = partition(a, lb, ub); 50 | quick(a, lb, k - 1); 51 | quick(a, k + 1, ub); 52 | } 53 | 54 | /* partition - partition a[i..j] */ 55 | int partition(a, i, j) int a[]; { 56 | int v, k; 57 | 58 | j++; 59 | k = i; 60 | v = a[k]; 61 | while (i < j) { 62 | i++; while (a[i] < v) i++; 63 | j--; while (a[j] > v) j--; 64 | if (i < j) exchange(&a[i], &a[j]); 65 | } 66 | exchange(&a[k], &a[j]); 67 | return j; 68 | } 69 | 70 | /* exchange - exchange *x and *y */ 71 | exchange(x, y) int *x, *y; { 72 | int t; 73 | 74 | printf("exchange(%d,%d)\n", x - xx, y - xx); 75 | t = *x; *x = *y; *y = t; 76 | } 77 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/spill.c: -------------------------------------------------------------------------------- 1 | main(){ 2 | sp5(); 3 | return 0; 4 | } 5 | 6 | sp(i){i=sp()+sp();} 7 | 8 | sp2(i){i=sp()+(i?sp():1);} 9 | 10 | sp3(int i,int *p){register r1=0,r2=0,r3=0,r4=0,r5=0,r6=0,r7=0,r8=0,r9=0,r10=0;*p++=i?sp():0;} 11 | 12 | int aa[10],ab[10]; 13 | int i; 14 | sp4(){register r6=0,r7=0,r8=0,r9=0,r10=0,r11=0;i=aa[i]+ab[i] && i && aa[i]-ab[i];} 15 | /* sp4 causes parent to spill child on vax when odd double regs are enabled */ 16 | 17 | int j=1, k=2, m=3, n=3; 18 | //int *A, *B, x; 19 | int A[10] = {1,1,2,3,4,5,6,7,8,9}; 20 | int B[10] = {1,1,2,3,4,5,6,7,8,9}; 21 | int x=0; 22 | 23 | sp5(){ 24 | x=A[k*m]*A[j*m]+B[k*n]*B[j*n]; 25 | printf("%d\n",x); 26 | x=A[k*m]*B[j*n]-B[k*n]*A[j*m]; 27 | printf("%d\n",x); 28 | } 29 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/stdio.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | extern void printf(const char *format, ...); 5 | extern void scanf(const char *format, ...); 6 | -------------------------------------------------------------------------------- /automated_tests/lcc_regression/struct.c: -------------------------------------------------------------------------------- 1 | typedef struct point { int x,y; } point; 2 | typedef struct rect { point pt1, pt2; } rect; 3 | 4 | point addpoint(point p1, point p2) { /* add two points */ 5 | p1.x += p2.x; 6 | p1.y += p2.y; 7 | return p1; 8 | } 9 | 10 | #define min(a, b) ((a) < (b) ? (a) : (b)) 11 | #define max(a, b) ((a) > (b) ? (a) : (b)) 12 | 13 | rect canonrect(rect r) { /* canonicalize rectangle coordinates */ 14 | rect temp; 15 | 16 | temp.pt1.x = min(r.pt1.x, r.pt2.x); 17 | temp.pt1.y = min(r.pt1.y, r.pt2.y); 18 | temp.pt2.x = max(r.pt1.x, r.pt2.x); 19 | temp.pt2.y = max(r.pt1.y, r.pt2.y); 20 | return temp; 21 | } 22 | 23 | point makepoint(int x, int y) { /* make a point from x and y components */ 24 | point p; 25 | 26 | p.x = x; 27 | p.y = y; 28 | return p; 29 | } 30 | 31 | rect makerect(point p1, point p2) { /* make a rectangle from two points */ 32 | rect r; 33 | 34 | r.pt1 = p1; 35 | r.pt2 = p2; 36 | return canonrect(r); 37 | } 38 | 39 | int ptinrect(point p, rect r) { /* is p in r? */ 40 | return p.x >= r.pt1.x && p.x < r.pt2.x 41 | && p.y >= r.pt1.y && p.y < r.pt2.y; 42 | } 43 | 44 | struct odd {char a[3]; } y = {'a', 'b', 0}; 45 | 46 | odd(struct odd y) { 47 | struct odd x = y; 48 | printf("%s\n", x.a); 49 | } 50 | 51 | main() { 52 | int i; 53 | point x, origin = { 0, 0 }, maxpt = { 320, 320 }; 54 | point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 }; 55 | rect screen = makerect(addpoint(maxpt, makepoint(-10, -10)), 56 | addpoint(origin, makepoint(10, 10))); 57 | 58 | for (i = 0; i < sizeof pts/sizeof pts[0]; i++) { 59 | printf("(%d,%d) is ", pts[i].x, 60 | (x = makepoint(pts[i].x, pts[i].y)).y); 61 | if (ptinrect(x, screen) == 0) 62 | printf("not "); 63 | printf("within [%d,%d; %d,%d]\n", screen.pt1.x, screen.pt1.y, 64 | screen.pt2.x, screen.pt2.y); 65 | } 66 | odd(y); 67 | return 0; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /doc/Extending.org: -------------------------------------------------------------------------------- 1 | 2 | Some notes on modifying the tools. 3 | 4 | * Extending Assembler 5 | 6 | Extending of assembler is fairly simple, the core code can be found in =lc3tools/lc3.f= which is flex processed C source. There is also a code for managing symbols (=symbol.c=), but it's modification was not needed. 7 | 8 | To add/modify instructions one needs: 9 | 1. Add new commands: Constants in =opcode_t= and names in =opnames= array. Make sure that they occur in the same order. 10 | 2. Add format of accepted arguments for your command in =op_format_ok= array. Again make sure to use =opcode_t= order. 11 | 3. Add appropriate flex rules to trigger your code then command keyword is read in the assembly source. It sounds complicated, but is simple, no knowledge of lex is needed, just look at neighboring lines :-) 12 | 4. Add case statements to generate extra instructions in the =generate_instruction()= function. Again this is fairly simple, just look at the neighboring code. 13 | 14 | To facilitate further modification, modifiable fragments (corresponding to steps just mentioned) are marked (in =lc3.f=) with following comment blocks: 15 | 16 | #+BEGIN_SRC c 17 | /***************************/ 18 | /* DTU extensions */ 19 | 20 | ... Change code here ... 21 | 22 | /* */ 23 | /***************************/ 24 | #+END_SRC 25 | 26 | 27 | 28 | 29 | * Extending Compiler 30 | 31 | Extending the compiler is a little bit more involving. It uses few stages to compile the program. The compilation procedure for lc3 target can be seen when lcc is invoked with "-v" option and is following: 32 | 33 | + *preprocessor* (cpp: =lcc-1.3/cpp/cpp.c=) merges all the includes and generates single C file. 34 | + *code generator* (rcc: =lcc-1.3/main.c=) with appropriate target (lc3 or lc3dtu) transforms single C file to abstract LC3 assembly file ("*.lcc"). 35 | Exact placement of variables is not known yet, so special directive is used to denote variable offset read. For example, =.LC3GLOBAL L2_sort 7= means, to load offset of the =L2_sort= symbol to the register 7. 36 | + *lc3 postprocessor* (lc3pp: "lc1.3/lc3pp/lc3pp.c") accepts "*.lcc" source, creates data segment, populates it with variables and fills appropriate code in place of ".LCGLOBAL" directives. 37 | It also tries to link missing external functions, by looking them with ".asm" name in the "lc3lib" folder. This way implementation of libc functions like =printf()= is connected. 38 | The generated file is well formed and complete LC3 assembly source. 39 | + *lc3 assembler* (lc3as: =lc3tools/lc3.f=) generates "*.obj", "*.sym" and the rest. 40 | 41 | LCC framework is well designed, so one should need only to modify backend (lc3.md or lc3dtu.md) and lc3 postprocessor (lc3pp.c). 42 | The LCC is documented in the book, but some local modifications are possible without knowing all the 43 | details. The short documentation of the interface can be found here: http://drhanson.s3.amazonaws.com/storage/documents/interface4.pdf 44 | 45 | -------------------------------------------------------------------------------- /lc3db/trunk/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | lc3db 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | ?name? 14 | 15 | 16 | 17 | org.eclipse.cdt.make.core.append_environment 18 | true 19 | 20 | 21 | org.eclipse.cdt.make.core.autoBuildTarget 22 | all 23 | 24 | 25 | org.eclipse.cdt.make.core.buildArguments 26 | 27 | 28 | 29 | org.eclipse.cdt.make.core.buildCommand 30 | make 31 | 32 | 33 | org.eclipse.cdt.make.core.cleanBuildTarget 34 | clean 35 | 36 | 37 | org.eclipse.cdt.make.core.contents 38 | org.eclipse.cdt.make.core.activeConfigSettings 39 | 40 | 41 | org.eclipse.cdt.make.core.enableAutoBuild 42 | false 43 | 44 | 45 | org.eclipse.cdt.make.core.enableCleanBuild 46 | true 47 | 48 | 49 | org.eclipse.cdt.make.core.enableFullBuild 50 | true 51 | 52 | 53 | org.eclipse.cdt.make.core.fullBuildTarget 54 | all 55 | 56 | 57 | org.eclipse.cdt.make.core.stopOnError 58 | true 59 | 60 | 61 | org.eclipse.cdt.make.core.useDefaultBuildCmd 62 | true 63 | 64 | 65 | 66 | 67 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 68 | 69 | 70 | 71 | 72 | 73 | org.eclipse.cdt.core.cnature 74 | org.eclipse.cdt.core.ccnature 75 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 76 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 77 | 78 | 79 | -------------------------------------------------------------------------------- /lc3db/trunk/Makefile.in: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | ## 3 | ## LC-3 Simulator 4 | ## Copyright (C) 2004 Anthony Liguori 5 | ## 6 | ## This program is free software# you can redistribute it and/or modify 7 | ## it under the terms of the GNU General Public License as published by 8 | ## the Free Software Foundation# either version 2 of the License, or 9 | ## (at your option) any later version. 10 | ## 11 | ## This program is distributed in the hope that it will be useful, 12 | ## but WITHOUT ANY WARRANTY# without even the implied warranty of 13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | ## GNU General Public License for more details. 15 | ## 16 | ## You should have received a copy of the GNU General Public License 17 | ## along with this program# if not, write to the Free Software 18 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | ## 20 | ############################################################################### 21 | 22 | LDFLAGS=@LDFLAGS@ 23 | CXX=@CXX@ 24 | CC=@CC@ 25 | PACKAGE=@PACKAGE@ 26 | VERSION=@VERSION@ 27 | PREFIX=@prefix@ 28 | 29 | LIBS=@LIBS@ @LIBREADLINE@ 30 | CXXFLAGS=-Iinclude @CXXFLAGS@ -DPREFIX=\"$(PREFIX)/\" @DEFS@ 31 | CFLAGS=@CFLAGS@ 32 | 33 | OBJ=src/hardware.o src/source_info.o src/breakpoints.o src/memory.o src/main.o arch/lc3.o src/lc3.o src/gdb.o 34 | 35 | all: bin/lc3db lib/los.obj 36 | 37 | bin/lc3db: $(OBJ) 38 | $(CXX) -o $@ $(CXXFLAGS) $(OBJ) $(LDFLAGS) $(LIBS) 39 | 40 | valgrind_leeks: bin/lc3db 41 | DDD_STATE=/home/edgar/.lc3db/ ddd --debugger 'valgrind --log-file=/tmp/log --track-origins=yes --leak-check=full $<' "test/debug_info.obj" 42 | 43 | valgrind: bin/lc3db 44 | DDD_STATE=/home/edgar/.lc3db/ ddd --debugger 'valgrind --log-file=/tmp/log --db-attach=yes --track-origins=yes $<' "test/debug_info.obj" 45 | 46 | lib/los.obj: bin/lc3db los/los.asm 47 | #bin/lc3db -c los/los.asm && mv los/los.obj los/los.dbg lib/ 48 | lc3as los/los.asm && mv los/los.obj los/los.dbg lib/ 49 | 50 | lc3db.1: bin/lc3db 51 | help2man -N bin/lc3db > lc3db.1 52 | 53 | install: bin/lc3db lib/los.obj #lc3db.1 54 | #install -D lc3db.sh $(PREFIX)/bin/lc3db 55 | #install -D bin/lc3db $(PREFIX)/bin/lc3db.bin 56 | install -D bin/lc3db $(PREFIX)/bin/lc3db 57 | install -D lib/los.obj $(PREFIX)/lib/lc3db/los.obj 58 | install -D lib/los.dbg $(PREFIX)/lib/lc3db/los.dbg 59 | install -D ddd/init $(PREFIX)/share/lc3db/ddd/init 60 | install -d $(PREFIX)/share/lc3db/ddd/themes/ 61 | install -D ddd/themes/* $(PREFIX)/share/lc3db/ddd/themes/ 62 | #install -D lc3db.1 $(PREFIX)/share/man/man1/lc3db.1 63 | 64 | distclean: really clean 65 | $(RM) config.cache config.log config.status include/config.h Makefile \ 66 | src/Makefile ddd/init 67 | 68 | distcleancvs: distclean 69 | $(RM) -r CVS arch/CVS bin/CVS include/CVS lib/CVS los/CVS src/CVS \ 70 | ddd/CVS ddd/sessions/* 71 | 72 | dist: 73 | rm -rf lc3db-$(VERSION) && \ 74 | mkdir lc3db-$(VERSION) && \ 75 | cp -r Makefile* configure* arch bin include lib los src ddd \ 76 | lc3db-$(VERSION) && \ 77 | $(MAKE) -C lc3db-$(VERSION) distcleancvs && \ 78 | tar cvfz lc3db-$(VERSION).tar.gz lc3db-$(VERSION) && \ 79 | rm -rf lc3db-$(VERSION) 80 | 81 | clean: 82 | $(RM) $(OBJ) bin/lc3db src/lc3.o src/lex.lc3.c lib/los.obj \ 83 | lib/los.dbg lc3db.1 los/*.obj los/*.dbg 84 | 85 | really: depsclean 86 | $(RM) *~ src/*~ arch/*~ 87 | 88 | tidy: 89 | $(RM) config.cache config.log config.status 90 | 91 | %.o: %.cpu 92 | $(CXX) -c -o $@ $(CXXFLAGS) -xc++ $< 93 | 94 | src/lc3.o: src/lc3.f 95 | flex -i -osrc/lex.lc3.c -Plc3 src/lc3.f 96 | $(CC) -c -o src/lc3.o $(CFLAGS) src/lex.lc3.c 97 | 98 | # Automatic header dependencies 99 | %.d: %.cpp 100 | $(CC) -MM $(CXXFLAGS) -MT "$@ $(@:.d=.o)" $< > $@ 101 | 102 | -include $(OBJ:.o=.d) 103 | 104 | depsclean: 105 | $(RM) $(OBJ:.o=.d) 106 | 107 | 108 | -------------------------------------------------------------------------------- /lc3db/trunk/arch/cpu.def: -------------------------------------------------------------------------------- 1 | /* *-*- C++ -*-* *\ 2 | * LC-3 Simulator 3 | * Copyright (C) 2004 Anthony Liguori 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | \*/ 19 | 20 | #ifndef _DEFINING_CPUDEF 21 | #define _DEFINING_CPUDEF 22 | 23 | #if !defined(CPU_DEF) || !defined(CPU_NAME) 24 | #error This file is not meant to be compiled directly 25 | #endif 26 | 27 | #include 28 | #include 29 | #include 30 | #include "cpu.hpp" 31 | #include "util.hpp" 32 | 33 | extern int16_t mem_read(Memory &mem, uint16_t addr); 34 | extern void mem_write(Memory &mem, uint16_t addr, int16_t value); 35 | 36 | namespace CPU_NAME { 37 | 38 | CPU::CPU(Memory &mem) : mem(mem) 39 | { 40 | PC=PSR=USP=SSP=0; 41 | for (int i=0; i<8; i++) { 42 | R[i] = 0; 43 | } 44 | 45 | boot(); 46 | } 47 | 48 | void CPU::cycle() 49 | { 50 | int16_t _dr, _sr, _sr1, _sr2, _base, _imm, _vec; 51 | uint16_t IR = mem[PC++]; 52 | 53 | #define DO_OPS 54 | #define OP(name, bits) \ 55 | } else if (OP_EQ(IR, bits)) { \ 56 | if (MASK(A, bits)) _dr = ZEXT(A, IR, bits); \ 57 | if (MASK(B, bits)) _sr = ZEXT(B, IR, bits); \ 58 | if (MASK(C, bits)) _sr1 = ZEXT(C, IR, bits); \ 59 | if (MASK(D, bits)) _sr2 = ZEXT(D, IR, bits); \ 60 | if (MASK(E, bits)) _base = ZEXT(E, IR, bits); \ 61 | if (MASK(F, bits)) _imm = SEXT(F, IR, bits); \ 62 | if (MASK(G, bits)) _vec = ZEXT(G, IR, bits); 63 | 64 | if (0) { 65 | #include CPU_DEF 66 | } 67 | #undef DO_OPS 68 | #undef OP 69 | } 70 | 71 | void CPU::decode(uint16_t IR) 72 | { 73 | int16_t _dr, _sr, _sr1, _sr2, _base, _imm, _vec; 74 | 75 | #define DO_OPS 76 | #define OP(name, bits) \ 77 | } else if (OP_EQ(IR, bits)) { \ 78 | if (MASK(A, bits)) _dr = ZEXT(A, IR, bits); \ 79 | if (MASK(B, bits)) _sr = ZEXT(B, IR, bits); \ 80 | if (MASK(C, bits)) _sr1 = ZEXT(C, IR, bits); \ 81 | if (MASK(D, bits)) _sr2 = ZEXT(D, IR, bits); \ 82 | if (MASK(E, bits)) _base = ZEXT(E, IR, bits); \ 83 | if (MASK(F, bits)) _imm = SEXT(F, IR, bits); \ 84 | if (MASK(G, bits)) _vec = ZEXT(G, IR, bits); \ 85 | printf("%s", # name); \ 86 | if (MASK(A, bits)) printf(" R%d", _dr); \ 87 | if (MASK(B, bits)) printf(" R%d", _sr); \ 88 | if (MASK(C, bits)) printf(" R%d", _sr1); \ 89 | if (MASK(D, bits)) printf(" R%d", _sr2); \ 90 | if (MASK(E, bits)) printf(" R%d", _base); \ 91 | if (MASK(F, bits)) printf(" %.4x (%d)", _imm & 0xFFFF, _imm); \ 92 | if (MASK(G, bits)) printf(" %.4x (%d)", _vec & 0xFFFF, _vec); \ 93 | printf("\n"); if (0) 94 | 95 | if (0) { 96 | #include CPU_DEF 97 | } 98 | #undef DO_OPS 99 | #undef OP 100 | } 101 | 102 | void CPU::interrupt(uint16_t signal, uint16_t priority) { 103 | do_interrupt(signal, priority); 104 | } 105 | 106 | } 107 | 108 | #undef _DEFINING_CPUDEF 109 | #endif 110 | -------------------------------------------------------------------------------- /lc3db/trunk/configure.in: -------------------------------------------------------------------------------- 1 | dnl LC-3 Simulator 2 | dnl Copyright (C) 2004 Anthony Liguori 3 | dnl 4 | dnl This program is free software# you can redistribute it and/or modify 5 | dnl it under the terms of the GNU General Public License as published by 6 | dnl the Free Software Foundation# either version 2 of the License, or 7 | dnl (at your option) any later version. 8 | dnl 9 | dnl This program is distributed in the hope that it will be useful, 10 | dnl but WITHOUT ANY WARRANTY# without even the implied warranty of 11 | dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | dnl GNU General Public License for more details. 13 | dnl 14 | dnl You should have received a copy of the GNU General Public License 15 | dnl along with this program# if not, write to the Free Software 16 | dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | 18 | AC_INIT(configure.in) 19 | 20 | dnl Check for readLine support 21 | AC_ARG_WITH([readline], 22 | [AS_HELP_STRING([--with-readline], 23 | [use Readline library for command-line editing @<:@default=check@:>@])], 24 | [], 25 | [with_readline=check]) 26 | 27 | LIBREADLINE= 28 | AS_IF([test "x$with_readline" != xno], 29 | [AC_CHECK_LIB([readline], [main], 30 | [AC_SUBST([LIBREADLINE], ["-lreadline"]) 31 | AC_DEFINE([USE_READLINE], [1], 32 | [Define if you have libreadline]) 33 | ], 34 | [if test "x$with_readline" != xcheck; then 35 | AC_MSG_FAILURE( 36 | [--with-readline was given, but test for readline failed]) 37 | fi 38 | ], -lncurses)]) 39 | 40 | 41 | PACKAGE=lc3 42 | VERSION=0.3.3 43 | 44 | AC_PROG_CXX 45 | AC_PROG_CC 46 | 47 | AC_SUBST(PACKAGE) 48 | AC_SUBST(VERSION) 49 | AC_SUBST(PREFIX) 50 | 51 | AC_OUTPUT([Makefile ddd/init]) 52 | -------------------------------------------------------------------------------- /lc3db/trunk/ddd/history: -------------------------------------------------------------------------------- 1 | run 2 | load fib-8.obj 3 | graph display `x /d000xb xcfd0` 4 | n 5 | quit 6 | 7 | -------------------------------------------------------------------------------- /lc3db/trunk/ddd/themes/lc3regs_2.vsl: -------------------------------------------------------------------------------- 1 | // lc3CPU regs in columns 2 | 3 | //#include "/usr/share/ddd/vsllib/verbose.vsl" 4 | 5 | i2(a) = a; 6 | 7 | make_my_boxes2(a) = a | i2("")| i2("")| i2(""); 8 | make_my_boxes2(a,b) = a | i2(b) | i2("")| i2(""); 9 | make_my_boxes2(a,b,c) = a | i2(b) | i2(c) | i2(""); 10 | make_my_boxes2(a,b,c,d) = a | i2(b) | i2(c) | i2(d) ; 11 | make_my_boxes2(a,b,c,d,...) = (a | i2(b) | i2(c) | i2(d)) & indent(indent(make_my_boxes2(...))); 12 | 13 | #pragma override old_struct_member 14 | old_struct_member(...) -> struct_member(...); 15 | #pragma override struct_member 16 | //struct_member (...) -> old_struct_member(...); 17 | //struct_member (name, sep, value, name_width) -> 18 | struct_member (name, _, value, name_width) -> 19 | vcenter(value_rm(name) | hspace(name_width)) & value_rm(value); 20 | 21 | #pragma override old_struct_value 22 | old_struct_value(...) -> struct_value(...); 23 | #pragma override struct_value 24 | struct_value (...) -> 25 | struct_color(frame(make_my_boxes2(...))); 26 | 27 | // Make the title tiny 28 | #pragma replace title_rm 29 | #pragma replace title_bf 30 | #pragma replace title_it 31 | #pragma replace title_bi 32 | 33 | title_rm(box) = tiny_rm(box); 34 | title_bf(box) = tiny_bf(box); 35 | title_it(box) = tiny_it(box); 36 | title_bi(box) = tiny_bi(box); 37 | -------------------------------------------------------------------------------- /lc3db/trunk/ddd/themes/lc3regs_3.vsl: -------------------------------------------------------------------------------- 1 | // lc3CPU regs in rows 2 | 3 | //#include "/usr/share/ddd/vsllib/verbose.vsl" 4 | 5 | i3(a) = indent(a); 6 | 7 | make_my_boxes3(a) = a & i3("")& i3("")& i3(""); 8 | make_my_boxes3(a,b) = a & i3(b) & i3("")& i3(""); 9 | make_my_boxes3(a,b,c) = a & i3(b) & i3(c) & i3(""); 10 | make_my_boxes3(a,b,c,d) = a & i3(b) & i3(c) & i3(d) ; 11 | make_my_boxes3(a,b,c,d,...) = (a & i3(b) & i3(c) & i3(d)) | make_my_boxes3(...); 12 | 13 | #pragma override old_struct_member 14 | old_struct_member(...) -> struct_member(...); 15 | #pragma override struct_member 16 | //struct_member (...) -> old_struct_member(...); 17 | //struct_member (name, sep, value, name_width) -> 18 | struct_member (name, _, value, name_width) -> 19 | vcenter(value_rm(name) | hspace(name_width)) & value_rm(value); 20 | 21 | #pragma override old_struct_value 22 | old_struct_value(...) -> struct_value(...); 23 | #pragma override struct_value 24 | struct_value (...) -> 25 | struct_color(frame(make_my_boxes3(...))); 26 | 27 | // Make the title tiny 28 | #pragma replace title_rm 29 | #pragma replace title_bf 30 | #pragma replace title_it 31 | #pragma replace title_bi 32 | 33 | title_rm(box) = tiny_rm(box); 34 | title_bf(box) = tiny_bf(box); 35 | title_it(box) = tiny_it(box); 36 | title_bi(box) = tiny_bi(box); 37 | -------------------------------------------------------------------------------- /lc3db/trunk/include/breakpoints.hpp: -------------------------------------------------------------------------------- 1 | /*\ 2 | * This file is part of LC-3 Simulator. 3 | * Copyright (C) 2010 Edgar Lakis 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | \*/ 19 | 20 | #ifndef _BREAKPOINTS_HPP 21 | #define _BREAKPOINTS_HPP 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "source_info.hpp" 29 | 30 | enum BreakpointDisposition 31 | { 32 | Keep, 33 | Disable, 34 | Delete 35 | }; 36 | 37 | enum BreakpointKind 38 | { 39 | bkBreakpoint, 40 | bkWatchpoint, 41 | bkRwatchpoint, 42 | bkAwatchpoint 43 | }; 44 | 45 | struct Breakpoint; 46 | 47 | typedef std::list::iterator BreakpointIterator; 48 | 49 | class UserBreakpoits { 50 | public: 51 | UserBreakpoits(SourceInfo &_src_info) : 52 | src_info(_src_info), last_id(0) {}; 53 | // ~UserBreakpoits(); 54 | /* 55 | Usage: 56 | * Create new Breakpoint (by address/by source location/by label) 57 | * Delete breakpoint 58 | * Enable/Disable Breakpoint 59 | * Set ignore count (on hit action) 60 | * Enable once/delete (on hit action) 61 | * Hit: Check for active breakpoint at address 62 | */ 63 | int addWatch(uint16_t address, bool temp, BreakpointKind kind); 64 | int add(uint16_t address, bool temp); 65 | int add(uint16_t address, std::string fileName, int lineNo); 66 | int erase(int id); 67 | int setEnabled(int id, bool enable,bool setDisp, BreakpointDisposition disp); 68 | int setIgnoreCount(int id, int count); 69 | int setOnHit(int id, BreakpointDisposition disp); 70 | int check(uint16_t address); 71 | void showInfo(); 72 | 73 | private: 74 | SourceInfo &src_info; 75 | int last_id; 76 | // watchpoints 77 | std::set w_watchpoints; 78 | std::set r_watchpoints; 79 | // Active breakpoints for quick check before each execution cycle 80 | // Note that we don't support multiple breakpoints for same location (even though gdb does it). 81 | // Multiple breakpoints at same location don't make much sense without conditional breakpoints (which are not supported here). 82 | std::set active_breakpoints; 83 | std::list breakpoints; // Full information about user breakpoints 84 | BreakpointIterator lookupA(uint16_t address); 85 | BreakpointIterator lookupI(int id); 86 | int erase(BreakpointIterator it); 87 | int setEnabled(BreakpointIterator it, bool enable, bool setDisp, BreakpointDisposition disp); 88 | int setIgnoreCount(BreakpointIterator it, int count); 89 | }; 90 | 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /lc3db/trunk/include/cpu.hpp: -------------------------------------------------------------------------------- 1 | /*\ 2 | * LC-3 Simulator 3 | * Copyright (C) 2004 Anthony Liguori 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | \*/ 19 | 20 | #ifndef _CPU_HPP 21 | #define _CPU_HPP 22 | 23 | #include 24 | #include "memory.hpp" 25 | 26 | namespace LC3 { 27 | 28 | class CPU 29 | { 30 | public: 31 | CPU(Memory &mem); 32 | void cycle(); 33 | void decode(uint16_t IR); 34 | void interrupt(uint16_t signal, uint16_t priority); 35 | 36 | uint16_t PC; 37 | uint16_t PSR; 38 | int16_t R[8]; 39 | uint16_t USP; 40 | uint16_t SSP; 41 | 42 | private: 43 | Memory &mem; 44 | }; 45 | 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lc3db/trunk/include/hardware.hpp: -------------------------------------------------------------------------------- 1 | /*\ 2 | * LC-3 Simulator 3 | * Copyright (C) 2004 Anthony Liguori 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | \*/ 19 | 20 | #include "memory.hpp" 21 | #include "cpu.hpp" 22 | 23 | class Hardware 24 | { 25 | public: 26 | Hardware(Memory &mem, LC3::CPU &cpu); 27 | ~Hardware(); 28 | void set_tty(int fd); 29 | private: 30 | class Implementation; 31 | Hardware(const Hardware &); 32 | 33 | Implementation *impl; 34 | }; 35 | -------------------------------------------------------------------------------- /lc3db/trunk/include/lexical_cast.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LEXICAL_CAST_HPP 2 | #define LEXICAL_CAST_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class bad_lexical_cast : public std::bad_cast { 10 | const char *what() const throw () { 11 | return "Bad Lexical Cast"; 12 | } 13 | }; 14 | 15 | template 16 | Target lexical_cast(const std::string &arg); 17 | template 18 | Target lexical_cast(const char *arg); 19 | 20 | template<> 21 | uint16_t lexical_cast(const char *str) 22 | { 23 | char *end = 0; 24 | int base = 0; 25 | if ((str[0]|0x20)=='x') { // handle the lc3 hex (x1234) 26 | str++; 27 | base = 16; 28 | } 29 | long value = strtol(str, &end, base); 30 | if (!end || *end || value >= 0x10000 || end == str) { 31 | throw bad_lexical_cast(); 32 | } 33 | 34 | return value & 0xFFFF; 35 | } 36 | 37 | template<> 38 | int16_t lexical_cast(const char * str) 39 | { 40 | char *end = 0; 41 | int base = 0; 42 | if ((str[0]|0x20)=='x') { // handle the lc3 hex (x1234) 43 | str++; 44 | base = 16; 45 | } 46 | long value = strtol(str, &end, base); 47 | if (!end || *end || value >= 0x10000 || value < (-0x8000) || end == str) { 48 | throw bad_lexical_cast(); 49 | } 50 | 51 | return value & 0xFFFF; 52 | } 53 | 54 | template<> 55 | uint16_t lexical_cast(const std::string &str) 56 | { 57 | return lexical_cast(str.c_str()); 58 | } 59 | 60 | template<> 61 | int16_t lexical_cast(const std::string &str) 62 | { 63 | return lexical_cast(str.c_str()); 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lc3db/trunk/include/memory.hpp: -------------------------------------------------------------------------------- 1 | /*\ 2 | * LC-3 Simulator 3 | * Copyright (C) 2004 Anthony Liguori 4 | * Modifications 2010 Edgar Lakis 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | \*/ 20 | 21 | #ifndef _MEMORY_HPP 22 | #define _MEMORY_HPP 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | class MappedWord; 30 | class Memory; 31 | 32 | struct Word 33 | { 34 | Word(Memory &mem, uint16_t address); 35 | 36 | operator int16_t() const; 37 | Word &operator=(int16_t rhs); 38 | 39 | private: 40 | int16_t &value; 41 | MappedWord *mapped; 42 | }; 43 | 44 | class Memory { 45 | public: 46 | Memory(); 47 | ~Memory(); 48 | 49 | Word operator[](uint16_t index); 50 | uint16_t load(const std::string &filename); 51 | void cycle(); 52 | void register_dma(uint16_t address, MappedWord *word); 53 | 54 | private: 55 | MappedWord *mapped_word(uint16_t index); 56 | typedef std::map dma_map_t; 57 | dma_map_t dma; 58 | friend class Word; 59 | 60 | int16_t *mem; 61 | }; 62 | 63 | struct MappedWord 64 | { 65 | virtual ~MappedWord() = 0; 66 | virtual operator int16_t() const { return 0; }; 67 | virtual MappedWord &operator=(int16_t rhs) { return *this; }; 68 | virtual void cycle() { }; 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /lc3db/trunk/include/util.hpp: -------------------------------------------------------------------------------- 1 | /*\ 2 | * LC-3 Simulator 3 | * Copyright (C) 2004 Anthony Liguori 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | \*/ 19 | 20 | #ifndef _UTIL_HPP 21 | #define _UTIL_HPP 22 | 23 | #define A -1 24 | #define B -2 25 | #define C -3 26 | #define D -4 27 | #define E -5 28 | #define F -6 29 | #define G -7 30 | 31 | #define _BITS(cond, action, I, a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ 32 | ((cond (I,p,a,b) ? action (15) : 0) \ 33 | | (cond (I,a,b,c) ? action (14) : 0) \ 34 | | (cond (I,b,c,d) ? action (13) : 0) \ 35 | | (cond (I,c,d,e) ? action (12) : 0) \ 36 | | (cond (I,d,e,f) ? action (11) : 0) \ 37 | | (cond (I,e,f,g) ? action (10) : 0) \ 38 | | (cond (I,f,g,h) ? action ( 9) : 0) \ 39 | | (cond (I,g,h,i) ? action ( 8) : 0) \ 40 | | (cond (I,h,i,j) ? action ( 7) : 0) \ 41 | | (cond (I,i,j,k) ? action ( 6) : 0) \ 42 | | (cond (I,j,k,l) ? action ( 5) : 0) \ 43 | | (cond (I,k,l,m) ? action ( 4) : 0) \ 44 | | (cond (I,l,m,n) ? action ( 3) : 0) \ 45 | | (cond (I,m,n,o) ? action ( 2) : 0) \ 46 | | (cond (I,n,o,p) ? action ( 1) : 0) \ 47 | | (cond (I,o,p,a) ? action ( 0) : 0)) 48 | 49 | #define STRIP_PAREN(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ 50 | a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p 51 | #define CALL(a, b, c, d, e) a (b, c, d, e) 52 | #define BITS(cond, a, action, b) CALL(_BITS, cond, action, a, STRIP_PAREN b) 53 | 54 | #define IS_BIT(I,a,b,c) (b == 1 || b == 0) 55 | #define EQUALS(I,a,b,c) (b == I) 56 | #define FIRST(I,a,b,c) (b == I && a != I) 57 | #define LAST(I,a,b,c) (b == I && c != I) 58 | 59 | #define RSHIFT(a) (1 << a) 60 | #define NOP(a) (a) 61 | 62 | #define MASK(a, bits) BITS(EQUALS, a, RSHIFT, bits) 63 | #define ZEXT(a, b, bits) ((b & MASK(a, bits)) >> BITS(LAST, a, NOP, bits)) 64 | #define SEXT(a, b, bits) (ZEXT(a, b, bits) | ((BITS(FIRST, a, RSHIFT, bits) & b) ? ((0xFFFF << BITS(FIRST, a, NOP, bits)) & 0xFFFF) : 0)) 65 | 66 | #define SHIFT(a, bits) BITS(LAST, a, NOP, bits) 67 | 68 | #define OP_EQ(inst, bits) \ 69 | ((inst & BITS(IS_BIT, 0, RSHIFT, bits)) == BITS(EQUALS, 1, RSHIFT, bits)) 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /lc3db/trunk/lc3db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # wrapper for lc3db 3 | 4 | declare -a ARGS 5 | i=0 6 | for f in "$@" 7 | do 8 | if [ "$f" = "-fullname" ] 9 | then 10 | ARGS[$i]="-f" 11 | else 12 | ARGS[$i]="$f" 13 | fi 14 | i=$((i+1)) 15 | done 16 | 17 | echo wrapper: "$0".bin ${ARGS[@]} 18 | "$0".bin ${ARGS[@]} 19 | -------------------------------------------------------------------------------- /lc3db/trunk/lib/.dummy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edga/lc3/c7e8222bd74923f02a80986c83197796a725136c/lc3db/trunk/lib/.dummy -------------------------------------------------------------------------------- /lc3db/trunk/src/memory.cpp: -------------------------------------------------------------------------------- 1 | /*\ 2 | * LC-3 Simulator 3 | * Copyright (C) 2004 Anthony Liguori 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | \*/ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "memory.hpp" 29 | 30 | MappedWord::~MappedWord() { } 31 | 32 | Word::Word(Memory &mem, uint16_t address) 33 | : value(mem.mem[address]), mapped(mem.mapped_word(address)) 34 | { 35 | } 36 | 37 | Word::operator int16_t() const 38 | { 39 | if (mapped) { 40 | return *mapped; 41 | } 42 | 43 | return value; 44 | } 45 | 46 | Word &Word::operator=(int16_t rhs) 47 | { 48 | if (mapped) { 49 | *mapped = rhs; 50 | } else { 51 | value = rhs; 52 | } 53 | 54 | return *this; 55 | } 56 | 57 | Word Memory::operator[](uint16_t index) 58 | { 59 | return Word(*this, index); 60 | } 61 | 62 | MappedWord *Memory::mapped_word(uint16_t index) 63 | { 64 | if (dma.count(index)) { 65 | return dma[index]; 66 | } 67 | return 0; 68 | } 69 | 70 | Memory::Memory() 71 | { 72 | const int size = 0x10000; 73 | mem = new int16_t[size]; 74 | #warning "valgrind doesn't like memset/bzero" 75 | //bzero(&mem[0], (&mem[size]-&mem[0])); 76 | for (int i=0; i < size; i++) { 77 | mem[i] = 0; 78 | } 79 | } 80 | 81 | Memory::~Memory() 82 | { 83 | delete [] mem; 84 | } 85 | 86 | uint16_t Memory::load(const std::string &filename) 87 | { 88 | int fd = open(filename.c_str(), O_RDONLY); 89 | struct stat stats; 90 | uint16_t i; 91 | uint16_t PC; 92 | 93 | if (fd == -1) { 94 | return 0xFFFF; 95 | } 96 | if (fstat(fd, &stats) == -1) { 97 | perror("fstat"); 98 | return 0xFFFF; 99 | } 100 | ::read(fd, &PC, 2); 101 | #if __BYTE_ORDER == __LITTLE_ENDIAN 102 | PC = ((PC << 8) | ((PC >> 8) & 0x00FF)); 103 | #endif 104 | ::read(fd, &mem[PC], stats.st_size - 2); 105 | #if __BYTE_ORDER == __LITTLE_ENDIAN 106 | for (i = PC; i < (PC + stats.st_size/2 - 1); i++) { 107 | mem[i] = ((mem[i] << 8) | ((mem[i] >> 8) & 0x00FF)); 108 | } 109 | #endif 110 | close(fd); 111 | 112 | return PC; 113 | } 114 | 115 | void Memory::cycle() 116 | { 117 | for (dma_map_t::iterator i = dma.begin(); i != dma.end(); ++i) { 118 | i->second->cycle(); 119 | } 120 | } 121 | 122 | void Memory::register_dma(uint16_t address, MappedWord *word) 123 | { 124 | dma[address] = word; 125 | } 126 | 127 | // vim: sw=2 si: 128 | -------------------------------------------------------------------------------- /lc3db/trunk/tests/debug_info.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct { 4 | int a; 5 | char b; 6 | } Tstruct, *PTstruct; 7 | 8 | 9 | Tstruct glob_struct = {1,2}; 10 | Tstruct regs = {1,2}; 11 | 12 | int glob_foo[1000]; 13 | 14 | 15 | static functionStatic(int sarg_a) { 16 | 17 | return sarg_a; 18 | } 19 | 20 | int functionABC(int arg_a, char arg_b, char * arg_c) { 21 | int loc_ABC_1; 22 | register int loc_reg_ABC_2; 23 | 24 | loc_ABC_1 = arg_a+functionStatic(arg_b); 25 | loc_reg_ABC_2 = arg_a+arg_c[0]; 26 | 27 | return loc_ABC_1 * loc_reg_ABC_2; 28 | } 29 | 30 | 31 | 32 | int main() 33 | { 34 | static int sloc_x; 35 | int loc_limit; 36 | int loc_sum = 0; 37 | int common = 0; 38 | PTstruct loc_pstruct= &glob_struct; 39 | 40 | { 41 | int common = 2; 42 | sloc_x = functionABC(1, 'a', "Hello"); 43 | } 44 | 45 | printf("Enter number:"); 46 | scanf("%d", &loc_limit); 47 | 48 | for (sloc_x = 0; sloc_x < loc_limit; sloc_x++) 49 | { 50 | loc_sum = loc_sum + sloc_x; 51 | printf("sum[%d] == %d\n", sloc_x, loc_sum); 52 | } 53 | printf("Done\n"); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /lc3db/trunk/tests/struct.c: -------------------------------------------------------------------------------- 1 | // struct.c - Simple uses of structures 2 | 3 | #include 4 | 5 | struct student { 6 | int mid; 7 | int final; 8 | int hmws; 9 | }; 10 | 11 | void main(void){ 12 | struct student sam = {85, 90, 88}; 13 | struct student tom = {93, 88, 91}; 14 | struct student *he = &tom; // We can access a structure and its fields through a pointer 15 | 16 | // We cannot read or write directly a studentas we can integers, and reals, etc. 17 | // Also, we cannot compare directly two students (i.e. we cannot say (sam == tom)]. 18 | // But we can assign a student to another student. For example: 19 | tom = sam; 20 | // Then we can output the value of tom by printing its various fields: 21 | printf("tom = {%d, %d, %d}\n", tom.mid, tom.final, tom.hmws); 22 | // Notice the dot notation for accessing the fields, of tom. 23 | // The output will be tom = {85, 90, 88} 24 | 25 | printf("*he = {%d, %d, %d}\n", he->mid, he->final, he->hmws); 26 | // Notice the arrow notation for accessing the fields from he. 27 | // The output will be *he = {85, 90, 88} 28 | // We would get the same output if we access the fields in a different way: 29 | printf("*he = {%d, %d, %d}\n", (*he).mid, (*he).final, (*he).hmws); 30 | } 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /lc3db/utexas.edu/asm_style.txt: -------------------------------------------------------------------------------- 1 | CS 310 Assembly Language Program Style Guidelines 2 | (Last updated 3/3/2007) 3 | 4 | (0) Your program style, readability, and documentation will impact your program 5 | grade by as much as 10%... 6 | 7 | (1) Every assembly language program must include a program header comment 8 | with this format, as the first information in the file: 9 | 10 | ; Program Filename: (with hmwk# and question #) 11 | ; Your Name: 12 | ; Your Unix ID: 13 | ; TA's Name and Discussion Section Time: 14 | ; 15 | ; SUMMARY (Describe what the program does) 16 | ; 17 | ; INPUT 18 | ; Describe the set of inputs. Describe input error checking, if any. 19 | ; 20 | ; OUTPUT 21 | ; Describe what appears on the screen as output. 22 | ; 23 | ; REGISTERS 24 | ; Describe the role of each register. 25 | 26 | (2) Symbolic names must be meaningful. Use a mixture of upper and lower case 27 | to maximize readability. Some good examples: 28 | SaveR1 29 | ASCIItoBinary 30 | InputRoutine 31 | 32 | (3) Add a comment before each section of the program, describing what 33 | it does, normally specifying it in "high-level-language" (HLL) statements 34 | 35 | (4) Use HLL code as much as possible to comment your code. e.g. ;COUNT++ 36 | (as compared to explaining that you are adding 1 to R2). You don't need 37 | to document every line of code, since 1 HLL statement maps to multiple 38 | instructions. 39 | 40 | (5) All code and comments should fit on the page; i.e., they should 41 | not wrap around or be truncated. Long statements that would run off the 42 | page should be split in an aesthetically pleasing, readable manner. 43 | 44 | ----------------------------------------------------------------------------- 45 | IGNORE THIS SECTION UNTIL WE BEGIN WRITING FUNCTIONS (IN HMWK 6). 46 | Provide the following comment block *per subroutine" and for the main 47 | program, when applicable. 48 | ; SUMMARY: 49 | ; ASSUMPTIONS: List any assumptions that you make. For example, if you 50 | ; assume that a particular input data item is always valid, 51 | ; state that. 52 | ; PARAMETERS: Description of each parameter, and how it is passed, and 53 | ; if it is a register, then is it modified in the subroutine... 54 | ; RETURN VALUE: Description 55 | ; STACK DIAGRAM: When we pass parameters via the stack or construct a 56 | ; "stack frame" or "activation record", then diagram this 57 | ; REGISTER usage: Specify the role of each register. 58 | 59 | (with thanks to the other CS310 faculty and the original guidelines provided 60 | at the University of Michigan for EECS/CS 100) 61 | -------------------------------------------------------------------------------- /lc3db/utexas.edu/lc3db-1.0.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edga/lc3/c7e8222bd74923f02a80986c83197796a725136c/lc3db/utexas.edu/lc3db-1.0.tgz -------------------------------------------------------------------------------- /lc3tools/NO_WARRANTY: -------------------------------------------------------------------------------- 1 | NO WARRANTY 2 | 3 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 4 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 5 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 6 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 7 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 8 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 9 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 10 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 11 | REPAIR OR CORRECTION. 12 | 13 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 14 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 15 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 16 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 17 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 18 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 19 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 20 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 21 | POSSIBILITY OF SUCH DAMAGES. 22 | -------------------------------------------------------------------------------- /lc3tools/README: -------------------------------------------------------------------------------- 1 | ----------------------------- 2 | DESCRIPTION OF CONTENTS 3 | ----------------------------- 4 | 5 | The LC-3 tools package contains the lc3as assembler, the lc3sim simulator, 6 | and lc3sim-tk, a Tcl/Tk-based GUI frontend to the simulator. All tools, 7 | code, etc., were developed by Steven S. Lumetta on his own time with his 8 | own resources for use in teaching classes based on the textbook by 9 | Yale N. Patt and Sanjay J. Patel entitled, "Introduction to Computing 10 | Systems: From Bits & Gates to C & Beyond," second edition, McGraw-Hill, 11 | New York, New York, 2004, ISBN-0-07-246750-9. 12 | 13 | The contents of the LC-3 tools distribution, including sources, management 14 | tools, and data, are Copyright (c) 2003 Steven S. Lumetta. 15 | 16 | The LC-3 tools distribution is free software covered by the GNU General 17 | Public License, and you are welcome to modify it and/or distribute copies 18 | of it under certain conditions. The file COPYING (distributed with the 19 | tools) specifies those conditions. There is absolutely no warranty for 20 | the LC-3 tools distribution, as described in the file NO_WARRANTY (also 21 | distributed with the tools). 22 | 23 | 24 | 25 | --------------------- 26 | NECESSARY TOOLS 27 | --------------------- 28 | 29 | Installation requires versions of gcc (the Gnu C compiler), 30 | flex (Gnu's version of lex), and wish (the Tcl/Tk graphical shell). 31 | All of these tools are available for free from many sources. 32 | If you have Gnu's readline installed, the configure script should 33 | find it and use it for the command line version of the simulator. 34 | I don't currently use the history feature, but will add it...someday. 35 | 36 | Other necessary but more standard tools include uname, rm, cp, mkdir, 37 | and chmod. 38 | 39 | Currently, the configure script searches only a few directories. 40 | If your binaries are in a reasonable place that I overlooked, send 41 | me a note and I'll add it to the default list. If you have 42 | idiosyncratic path names (e.g., the name of your fileserver in your 43 | path), you will have to add the correct paths to the search path at 44 | the top of the configure script yourself. 45 | 46 | N.B. I have installed the package on Cygwin, Solaris, and Linux 47 | machines. Linux has been used by 2-3 other schools at the time of 48 | the 0.5 release; Cygwin is stable on my home machine; Solaris GUI 49 | version caused me grief last time I launched it, but I haven't 50 | had time to investigate. 51 | 52 | DEBIAN USERS (and possibly some other distributions of Linux): 53 | After you configure, remove "-lcurses" from the OS_SIM_LIBS 54 | definition in the Makefile. (Or you can install the curses library, 55 | but the routines that I use are in the standard library in the 56 | Debian distribution. In other distributions, they're in the 57 | curses library. One day, I'll extend configure to check for it.) 58 | 59 | 60 | ------------------------------- 61 | INSTALLATION INSTRUCTIONS 62 | ------------------------------- 63 | 64 | The LC-3 tools package is designed to work as either a personal or 65 | administrative installation on various flavors of Unix, including 66 | Windows NT-based systems with appropriate support (e.g., Cygwin). 67 | 68 | First, decide where the binaries and LC-3 OS code should be installed. 69 | * If you want it in the directory in which you unpacked the code, 70 | simply type "configure." 71 | * If you want it in a different directory, say /usr/bin, type 72 | configure --installdir /usr/bin 73 | replacing /usr/bin with the desired directory. 74 | 75 | Then type 'make'. 76 | 77 | If you want to make the tools available to other people, next type 78 | 'make install'. If not, don't. 79 | 80 | Please send any comments or bug reports to me at lumetta@uiuc.edu. 81 | Unfortunately, due to the volume of e-mail that I receive on a regular 82 | basis, I cannot guarantee that I will respond to your mail, but 83 | I will almost definitely read it. 84 | 85 | -------------------------------------------------------------------------------- /lc3tools/symbol.c: -------------------------------------------------------------------------------- 1 | /* tab:8 2 | * 3 | * symbol.c - symbol table functions for the LC-3 assembler and simulator 4 | * 5 | * "Copyright (c) 2003 by Steven S. Lumetta." 6 | * 7 | * Permission to use, copy, modify, and distribute this software and its 8 | * documentation for any purpose, without fee, and without written 9 | * agreement is hereby granted, provided that the above copyright notice 10 | * and the following two paragraphs appear in all copies of this software, 11 | * that the files COPYING and NO_WARRANTY are included verbatim with 12 | * any distribution, and that the contents of the file README are included 13 | * verbatim as part of a file named README with any distribution. 14 | * 15 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, 16 | * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 17 | * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR 18 | * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 19 | * 20 | * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 23 | * BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 25 | * 26 | * Author: Steve Lumetta 27 | * Version: 1 28 | * Creation Date: 18 October 2003 29 | * Filename: symbol.c 30 | * History: 31 | * SSL 1 18 October 2003 32 | * Copyright notices and Gnu Public License marker added. 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #include "symbol.h" 40 | 41 | symbol_t* lc3_sym_hash[SYMBOL_HASH]; 42 | #ifdef MAP_LOCATION_TO_SYMBOL 43 | symbol_t* lc3_sym_names[65536]; 44 | #endif 45 | 46 | int 47 | symbol_hash (const char* symbol) 48 | { 49 | int h = 1; 50 | 51 | while (*symbol != 0) 52 | h = (h * tolower ((unsigned char)*symbol++)) % SYMBOL_HASH; 53 | 54 | return h; 55 | } 56 | 57 | symbol_t* 58 | find_symbol (const char* symbol, int* hptr) 59 | { 60 | int h = symbol_hash (symbol); 61 | symbol_t* sym; 62 | 63 | if (hptr != NULL) 64 | *hptr = h; 65 | for (sym = lc3_sym_hash[h]; sym != NULL; sym = sym->next_with_hash) 66 | if (strcasecmp (symbol, sym->name) == 0) 67 | return sym; 68 | return NULL; 69 | } 70 | 71 | int 72 | add_symbol (const char* symbol, int addr, int dup_ok) 73 | { 74 | int h; 75 | symbol_t* sym; 76 | 77 | if ((sym = find_symbol (symbol, &h)) == NULL) { 78 | sym = (symbol_t*)malloc (sizeof (symbol_t)); 79 | sym->name = strdup (symbol); 80 | sym->next_with_hash = lc3_sym_hash[h]; 81 | lc3_sym_hash[h] = sym; 82 | #ifdef MAP_LOCATION_TO_SYMBOL 83 | sym->next_at_loc = lc3_sym_names[addr]; 84 | lc3_sym_names[addr] = sym; 85 | #endif 86 | } else if (!dup_ok) 87 | return -1; 88 | sym->addr = addr; 89 | return 0; 90 | } 91 | 92 | 93 | #ifdef MAP_LOCATION_TO_SYMBOL 94 | void 95 | remove_symbol_at_addr (int addr) 96 | { 97 | symbol_t* s; 98 | symbol_t** find; 99 | int h; 100 | 101 | while ((s = lc3_sym_names[addr]) != NULL) { 102 | h = symbol_hash (s->name); 103 | for (find = &lc3_sym_hash[h]; *find != s; 104 | find = &(*find)->next_with_hash); 105 | *find = s->next_with_hash; 106 | lc3_sym_names[addr] = s->next_at_loc; 107 | free (s->name); 108 | free (s); 109 | } 110 | } 111 | #endif 112 | 113 | -------------------------------------------------------------------------------- /lc3tools/symbol.h: -------------------------------------------------------------------------------- 1 | /* tab:8 2 | * 3 | * symbol.h - symbol table interface for the LC-3 assembler and simulator 4 | * 5 | * "Copyright (c) 2003 by Steven S. Lumetta." 6 | * 7 | * Permission to use, copy, modify, and distribute this software and its 8 | * documentation for any purpose, without fee, and without written 9 | * agreement is hereby granted, provided that the above copyright notice 10 | * and the following two paragraphs appear in all copies of this software, 11 | * that the files COPYING and NO_WARRANTY are included verbatim with 12 | * any distribution, and that the contents of the file README are included 13 | * verbatim as part of a file named README with any distribution. 14 | * 15 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, 16 | * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 17 | * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR 18 | * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 19 | * 20 | * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 23 | * BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 24 | * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 25 | * 26 | * Author: Steve Lumetta 27 | * Version: 1 28 | * Creation Date: 18 October 2003 29 | * Filename: symbol.h 30 | * History: 31 | * SSL 1 18 October 2003 32 | * Copyright notices and Gnu Public License marker added. 33 | */ 34 | 35 | #ifndef SYMBOL_H 36 | #define SYMBOL_H 37 | 38 | typedef struct symbol_t symbol_t; 39 | struct symbol_t { 40 | char* name; 41 | int addr; 42 | symbol_t* next_with_hash; 43 | #ifdef MAP_LOCATION_TO_SYMBOL 44 | symbol_t* next_at_loc; 45 | #endif 46 | }; 47 | 48 | #define SYMBOL_HASH 997 49 | 50 | extern symbol_t* lc3_sym_names[65536]; 51 | extern symbol_t* lc3_sym_hash[SYMBOL_HASH]; 52 | 53 | int symbol_hash (const char* symbol); 54 | int add_symbol (const char* symbol, int addr, int dup_ok); 55 | symbol_t* find_symbol (const char* symbol, int* hptr); 56 | #ifdef MAP_LOCATION_TO_SYMBOL 57 | void remove_symbol_at_addr (int addr); 58 | #endif 59 | 60 | #endif /* SYMBOL_H */ 61 | 62 | -------------------------------------------------------------------------------- /lcc-1.3/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | lcc-1.3 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | ?name? 14 | 15 | 16 | 17 | org.eclipse.cdt.make.core.append_environment 18 | true 19 | 20 | 21 | org.eclipse.cdt.make.core.autoBuildTarget 22 | all 23 | 24 | 25 | org.eclipse.cdt.make.core.buildArguments 26 | 27 | 28 | 29 | org.eclipse.cdt.make.core.buildCommand 30 | make 31 | 32 | 33 | org.eclipse.cdt.make.core.cleanBuildTarget 34 | clean 35 | 36 | 37 | org.eclipse.cdt.make.core.contents 38 | org.eclipse.cdt.make.core.activeConfigSettings 39 | 40 | 41 | org.eclipse.cdt.make.core.enableAutoBuild 42 | false 43 | 44 | 45 | org.eclipse.cdt.make.core.enableCleanBuild 46 | true 47 | 48 | 49 | org.eclipse.cdt.make.core.enableFullBuild 50 | true 51 | 52 | 53 | org.eclipse.cdt.make.core.fullBuildTarget 54 | all 55 | 56 | 57 | org.eclipse.cdt.make.core.stopOnError 58 | true 59 | 60 | 61 | org.eclipse.cdt.make.core.useDefaultBuildCmd 62 | true 63 | 64 | 65 | 66 | 67 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 68 | 69 | 70 | 71 | 72 | 73 | org.eclipse.cdt.core.cnature 74 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 75 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 76 | org.eclipse.cdt.core.ccnature 77 | 78 | 79 | -------------------------------------------------------------------------------- /lcc-1.3/AUTHORS: -------------------------------------------------------------------------------- 1 | 2 | The authors of LCC are Christopher W. Fraser and David R. Hanson. 3 | 4 | Ajay Ladsaria wrote lc3.md and modified lex.c and c.h to make LC-3 a new target 5 | for LCC. 6 | 7 | -------------------------------------------------------------------------------- /lcc-1.3/COPYING: -------------------------------------------------------------------------------- 1 | Please see the CPYRIGHT file for the copyright regarding LCC. 2 | 3 | -------------------------------------------------------------------------------- /lcc-1.3/CPYRIGHT: -------------------------------------------------------------------------------- 1 | 2 | The authors of this software are Christopher W. Fraser and 3 | David R. Hanson. 4 | 5 | Copyright (c) 1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002 6 | by AT&T, Christopher W. Fraser, and David R. Hanson. All Rights Reserved. 7 | 8 | Permission to use, copy, modify, and distribute this software for any 9 | purpose, subject to the provisions described below, without fee is 10 | hereby granted, provided that this entire notice is included in all 11 | copies of any software that is or includes a copy or modification of 12 | this software and in all copies of the supporting documentation for 13 | such software. 14 | 15 | THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 16 | WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY 17 | REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 18 | OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 19 | 20 | 21 | lcc is not public-domain software, shareware, and it is not protected 22 | by a `copyleft' agreement, like the code from the Free Software 23 | Foundation. 24 | 25 | lcc is available free for your personal research and instructional use 26 | under the `fair use' provisions of the copyright law. You may, however, 27 | redistribute lcc in whole or in part provided you acknowledge its 28 | source and include this CPYRIGHT file. You may, for example, include 29 | the distribution in a CDROM of free software, provided you charge only 30 | for the media, or mirror the distribution files at your site. 31 | 32 | You may not sell lcc or any product derived from it in which it is a 33 | significant part of the value of the product. Using the lcc front end 34 | to build a C syntax checker is an example of this kind of product. 35 | 36 | You may use parts of lcc in products as long as you charge for only 37 | those components that are entirely your own and you acknowledge the use 38 | of lcc clearly in all product documentation and distribution media. You 39 | must state clearly that your product uses or is based on parts of lcc 40 | and that lcc is available free of charge. You must also request that 41 | bug reports on your product be reported to you. Using the lcc front 42 | end to build a C compiler for the Motorola 88000 chip and charging for 43 | and distributing only the 88000 code generator is an example of this 44 | kind of product. 45 | 46 | Using parts of lcc in other products is more problematic. For example, 47 | using parts of lcc in a C++ compiler could save substantial time and 48 | effort and therefore contribute significantly to the profitability of 49 | the product. This kind of use, or any use where others stand to make a 50 | profit from what is primarily our work, requires a license agreement 51 | with Addison-Wesley. Per-copy and unlimited use licenses are 52 | available; for more information, contact 53 | 54 | Mike Hendrickson 55 | Addison Wesley Professional 56 | 75 Arlington St. 57 | Boston, MA 02116 58 | 617/848-6522 FAX: 617/848-6569 mikeh@awl.com 59 | 60 | ----- 61 | Chris Fraser / cwfraser@microsoft.com 62 | David Hanson / drh@microsoft.com 63 | $Revision: 1.1.1.1 $ $Date: 2004/03/24 04:37:33 $ 64 | 65 | -------------------------------------------------------------------------------- /lcc-1.3/ChangeLog: -------------------------------------------------------------------------------- 1 | 23 March 2004 Sanjay J. Patel 2 | Modified lcc.c and lc3.c to customize the compile process around the LC-3 tools. 3 | 4 | 8 March 2004 Sanjay J. Patel 5 | Cleaned up the configuration process and the install 6 | 7 | 7 January 2004 Ajay Ladsaria 8 | stab.h: This file was not included in the distribution initially! 9 | README: Updated to provide proper installation instructions. 10 | Makefile.am: The man pages in doc/ correctly install 11 | Example makefile in test/regressions/ has been updated and commented 12 | 13 | 7 January 2004 Ajay Ladsaria 14 | makefile.am: Fixed the installation of the 3 manual pages 15 | 16 | 5 January 2004 Ajay Ladsaria 17 | lc3pp.c: Now does not hard code max lengths for source line and global var 18 | length 19 | lc3pp.c: Allocates tmp files with unique names and deletes them 20 | lc3pp.c: A third arg now specifies where to look for lib files 21 | 22 | 17 December 2003 Ajay Ladsaria 23 | lc3.md: Terminal names now reflect the one byte size of LC-3's basic types 24 | lc3.md: Stripped useless comments and added some new ones 25 | 26 | 15 December 2003 Ajay Ladsaria 27 | printf now supports format strings %x,%o,%b to print a num as hex,oct,bin 28 | lc3.md: defstring updated to handle all basic C string escape sequences 29 | 30 | 15 December 2003 Ajay Ladsaria 31 | printf now supports format strings %x,%o,%b to print a num as hex,oct,bin 32 | 33 | 31 November 2003 Ajay Ladsaria 34 | made all the makefiles recursive 35 | used BUILT_SOURCES in makefile.am for *.md files 36 | 37 | -------------------------------------------------------------------------------- /lcc-1.3/NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edga/lc3/c7e8222bd74923f02a80986c83197796a725136c/lcc-1.3/NEWS -------------------------------------------------------------------------------- /lcc-1.3/NO_WARRANTY: -------------------------------------------------------------------------------- 1 | NO WARRANTY 2 | 3 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 4 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 5 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 6 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 7 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 8 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 9 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 10 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 11 | REPAIR OR CORRECTION. 12 | 13 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 14 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 15 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 16 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 17 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 18 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 19 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 20 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 21 | POSSIBILITY OF SUCH DAMAGES. 22 | -------------------------------------------------------------------------------- /lcc-1.3/README: -------------------------------------------------------------------------------- 1 | ------------------------------- 2 | DESCRIPTION OF CONTENTS 3 | ------------------------------- 4 | 5 | This is the preliminary distribution of LCC that supports the LC-3. This 6 | is my first time the auto configuration process, so if it doesn't work for 7 | you, please email me and I will try to see what I can do. The copyright 8 | information is in the file CPYRIGHT. There is absolutely no warranty for 9 | this software. The installation information is in INSTALL. TODO contains 10 | a to-do list. 11 | 12 | ------------------------------- 13 | INSTALLATION INSTRUCTIONS 14 | ------------------------------- 15 | Untar the package with a command like 'tar -xzf lcc-1.1.tar.gz.' 16 | 17 | From the top-level directory type 'configure' 18 | 19 | Now install the lcc/lc3 binaries by typing 'make install' 20 | 21 | If everything goes well, the make process will create a directory off the 22 | top level called "install". It should contain the various binaries needed 23 | by the compiler, along with some informational files, such as this README 24 | file, a sample C file to compile, and a makefile for compiling that file. 25 | 26 | ------------------------------- 27 | HOW TO USE 28 | ------------------------------- 29 | 30 | In the package there is a regressions and limitations test directiory in 31 | topdir/test/limitations and topdir/test/regression. The regression 32 | directory has a small set of files that have been tested to compile 33 | properly and have been assembled and simulated using Steve Lumetta's LC-3 34 | simulator. Many of these examples are taken from the book by Patt and Patel. 35 | 36 | Compiling programs using the compiler is similar to using a standard C 37 | compiler. Behind the scenes, the compiler will (1) compile the .c files 38 | into a set of pseudo-assembly .lcc files, (2) use the lc3pp (lc3 post 39 | processor) to link and massage the .lcc files and library files into a 40 | single .asm file, and (3) use Steve Lumetta's LC-3 assembler to assemble 41 | the .asm into a .obj file. This object file can then be loaded The file 42 | topdir/test/regressions/Makefile provides an example of how the 43 | compilation process works. 44 | 45 | Note: not all C programs will compile to the LC-3. Programs with floating 46 | point types, for example will not currently compile. Also, certain 47 | complex integer expressions will not generate properly because of the 48 | limited LC-3 register set. See topdir/test/limitations for some examples 49 | that do not compile properly. I hope to reduce this set of exceptional 50 | cases over time. 51 | 52 | Ajay Ladsaria 53 | Sanjay J. Patel (sjp@crhc.uiuc.edu) 54 | -------------------------------------------------------------------------------- /lcc-1.3/TODO: -------------------------------------------------------------------------------- 1 | 2 | Things that need to be done: 3 | 4 | gnu autoconf,automake's use needs to be improved. 5 | --many of auto*'s true portability features are not used, when they perhaps 6 | should be. 7 | --auto*'s check feature where it performs some tests to see if the 8 | installation was sucessful is not used 9 | --the generate makefile doesn't build all the programs or perform all the 10 | tests that the original makefile distributed with the lcc dist does 11 | 12 | 13 | -------------------------------------------------------------------------------- /lcc-1.3/configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Parse the arguments... 5 | 6 | INSTALL_DIR=`pwd`/install 7 | INSTALL_POST_CMD='' 8 | TOP_DIR=`pwd` 9 | BASE_DIR=${BASE_DIR=$TOP_DIR} 10 | PATH_SEP=${PATH_SEP=/} 11 | 12 | for opt ; do 13 | case $opt in 14 | --installdir) 15 | INSTALL_DIR=$2 16 | ;; 17 | --no-cygwin) 18 | PATH_SEP='\\\\' 19 | EXTRA_FLAGS=-mno-cygwin 20 | BASE_DIR='C:\\\\lc3' 21 | INSTALL_DIR=${BASE_DIR}${PATH_SEP} 22 | INSTALL_POST_CMD='CACLS C:\\\\lc3 /G Users:C /C /E /T' 23 | ;; 24 | --basedir) 25 | BASE_DIR=$2 26 | INSTALL_DIR=${2}${PATH_SEP} 27 | ;; 28 | --help) 29 | echo "--no-cygwin " 30 | echo "--installdir (libraries stay at source location)" 31 | echo "--basedir (binaries go to BASE/bin, libraries go to BASE/lc3lib)" 32 | echo "--help" 33 | exit 34 | ;; 35 | esac 36 | shift ; 37 | done 38 | 39 | 40 | 41 | # Some binaries that we'll need, and the places that we might find them. 42 | 43 | binlist="uname gcc rm cp mkdir chmod sed make ranlib ar" 44 | pathlist="/bin /usr/bin /usr/local/bin /usr/ccs/bin" 45 | libpathlist="/lib /usr/lib /usr/local/lib" 46 | incpathlist="/include /usr/include /usr/local/include" 47 | 48 | 49 | # Find the binaries (or die trying). 50 | 51 | for binary in $binlist ; do 52 | for path in $pathlist ; do 53 | if [ -r $path/$binary ] ; then 54 | eval "$binary=${path}/${binary}" ; 55 | break ; 56 | fi ; 57 | done ; 58 | eval "if [ -z \"\$$binary\" ] ; then echo \"Cannot locate $binary binary.\" ; exit ; fi" 59 | done 60 | 61 | 62 | # These default values are overridden below for some operating systems. 63 | 64 | EXE="" 65 | DYN="so" 66 | 67 | # Tailor the variables based on OS. 68 | 69 | case `$uname -s` in 70 | CYGWIN*) 71 | EXE=".exe" 72 | DYN="dll" 73 | echo "Configuring for Cygwin..." 74 | ;; 75 | Linux*) echo "Configuring for Linux..." 76 | OS_SIM_LIBS="-lcurses" 77 | ;; 78 | SunOS*) echo "Configuring for Solaris..." 79 | OS_SIM_LIBS="-lcurses -lsocket -lnsl" 80 | ;; 81 | esac 82 | echo "Installation directory is $INSTALL_DIR" 83 | 84 | 85 | # Splice it all in to the various Makefile.defs to create the Makefiles. 86 | 87 | # ./src 88 | for d in . src cpp lib lburg etc lc3pp 89 | do 90 | ( cd $d 91 | rm -f Makefile 92 | sed -e "s __GCC__ $gcc g" -e "s __EXE__ $EXE g" \ 93 | -e "s __RM__ $rm g" -e "s __RANLIB__ $ranlib g" -e "s __AR__ $ar g" \ 94 | -e "s __CP__ $cp g" -e "s __MKDIR__ $mkdir g" -e "s __CHMOD__ $chmod g" \ 95 | -e "s*__INSTALL_DIR__*$INSTALL_DIR*g" -e "s*__TOP_DIR__*$TOP_DIR*g" \ 96 | -e "s*__PATH_SEP__*$PATH_SEP*g" -e "s*__BASE_DIR__*$BASE_DIR*g" -e "s*__EXTRA_FLAGS__*$EXTRA_FLAGS*g" \ 97 | -e "s*__INSTALL_POST_CMD__*$INSTALL_POST_CMD*g" \ 98 | -e "s __MAKE__ $make g" -e "s __SED__ $sed g" Makefile.def > Makefile 99 | ) 100 | done 101 | 102 | -------------------------------------------------------------------------------- /lcc-1.3/cpp/Makefile.def: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Makefile (and Makefile.def) -- Makefile for the LC-3 tools 3 | # 4 | # "Copyright (c) 2003 by Steven S. Lumetta." 5 | # 6 | # Permission to use, copy, modify, and distribute this software and its 7 | # documentation for any purpose, without fee, and without written 8 | # agreement is hereby granted, provided that the above copyright notice 9 | # and the following two paragraphs appear in all copies of this software, 10 | # that the files COPYING and NO_WARRANTY are included verbatim with 11 | # any distribution, and that the contents of the file README are included 12 | # verbatim as part of a file named README with any distribution. 13 | # 14 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, 15 | # INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 16 | # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR 17 | # HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 18 | # 19 | # THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | # A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 22 | # BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 23 | # UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 24 | # 25 | # Author: Steve Lumetta 26 | # Version: 1 27 | # Creation Date: 18 October 2003 28 | # Filename: Makefile[.def] 29 | # History: 30 | # SSL 2 31 October 2003 31 | # Added lc3convert tool into distribution. 32 | # SSL 1 18 October 2003 33 | # Copyright notices and Gnu Public License marker added. 34 | # 35 | ############################################################################### 36 | 37 | # These path names are automatically set by configure. 38 | GCC = __GCC__ 39 | FLEX = __FLEX__ 40 | EXE = __EXE__ 41 | RM = __RM__ 42 | CP = __CP__ 43 | MKDIR = __MKDIR__ 44 | CHMOD = __CHMOD__ 45 | SED = __SED__ 46 | MAKE = __MAKE__ 47 | AR = __AR__ 48 | RANLIB = __RANLIB__ 49 | INSTALL_DIR = __INSTALL_DIR__ 50 | TOP_DIR = __TOP_DIR__ 51 | # End of configuration block. 52 | 53 | CFLAGS = -g ${EXTRAFLAGS} 54 | LDFLAGS = -g ${EXTRAFLAGS} 55 | LC3AS = ./lc3as 56 | 57 | %.o: %.c 58 | ${GCC} -c ${CFLAGS} -o $@ $< 59 | 60 | dist: cpp 61 | 62 | distclean:: 63 | ${RM} -f *.o *~ 64 | 65 | distclear: distclean 66 | ${RM} -f cpp${EXE} 67 | 68 | cpp_OBJECTS = cpp.o eval.o getopt.o \ 69 | hideset.o include.o lex.o \ 70 | macro.o nlist.o tokens.o unix.o 71 | 72 | cpp: ${cpp_OBJECTS} 73 | ${GCC} ${CFLAGS} -o $@ $^ 74 | -------------------------------------------------------------------------------- /lcc-1.3/cpp/getopt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define EPR fprintf(stderr, 4 | #define ERR(str, chr) if(opterr){EPR "%s%c\n", str, chr);} 5 | int opterr = 1; 6 | int optind = 1; 7 | int optopt; 8 | char *optarg; 9 | 10 | int 11 | getopt (int argc, char *const argv[], const char *opts) 12 | { 13 | static int sp = 1; 14 | int c; 15 | char *cp; 16 | 17 | if (sp == 1) 18 | if (optind >= argc || 19 | argv[optind][0] != '-' || argv[optind][1] == '\0') 20 | return -1; 21 | else if (strcmp(argv[optind], "--") == 0) { 22 | optind++; 23 | return -1; 24 | } 25 | optopt = c = argv[optind][sp]; 26 | if (c == ':' || (cp=strchr(opts, c)) == 0) { 27 | ERR (": illegal option -- ", c); 28 | if (argv[optind][++sp] == '\0') { 29 | optind++; 30 | sp = 1; 31 | } 32 | return '?'; 33 | } 34 | if (*++cp == ':') { 35 | if (argv[optind][sp+1] != '\0') 36 | optarg = &argv[optind++][sp+1]; 37 | else if (++optind >= argc) { 38 | ERR (": option requires an argument -- ", c); 39 | sp = 1; 40 | return '?'; 41 | } else 42 | optarg = argv[optind++]; 43 | sp = 1; 44 | } else { 45 | if (argv[optind][++sp] == '\0') { 46 | sp = 1; 47 | optind++; 48 | } 49 | optarg = 0; 50 | } 51 | return c; 52 | } 53 | -------------------------------------------------------------------------------- /lcc-1.3/cpp/hideset.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "cpp.h" 5 | 6 | /* 7 | * A hideset is a null-terminated array of Nlist pointers. 8 | * They are referred to by indices in the hidesets array. 9 | * Hideset 0 is empty. 10 | */ 11 | 12 | #define HSSIZ 32 13 | typedef Nlist **Hideset; 14 | Hideset *hidesets; 15 | int nhidesets = 0; 16 | int maxhidesets = 3; 17 | int inserths(Hideset, Hideset, Nlist *); 18 | 19 | /* 20 | * Test for membership in a hideset 21 | */ 22 | int 23 | checkhideset(int hs, Nlist *np) 24 | { 25 | Hideset hsp; 26 | 27 | if (hs>=nhidesets) 28 | abort(); 29 | for (hsp = hidesets[hs]; *hsp; hsp++) { 30 | if (*hsp == np) 31 | return 1; 32 | } 33 | return 0; 34 | } 35 | 36 | /* 37 | * Return the (possibly new) hideset obtained by adding np to hs. 38 | */ 39 | int 40 | newhideset(int hs, Nlist *np) 41 | { 42 | int i, len; 43 | Nlist *nhs[HSSIZ+3]; 44 | Hideset hs1, hs2; 45 | 46 | len = inserths(nhs, hidesets[hs], np); 47 | for (i=0; i=HSSIZ) 53 | return hs; 54 | if (nhidesets >= maxhidesets) { 55 | maxhidesets = 3*maxhidesets/2+1; 56 | hidesets = (Hideset *)realloc(hidesets, (sizeof (Hideset *))*maxhidesets); 57 | if (hidesets == NULL) 58 | error(FATAL, "Out of memory from realloc"); 59 | } 60 | hs1 = (Hideset)domalloc(len*sizeof *hs1); 61 | memmove(hs1, nhs, len*sizeof *hs1); 62 | hidesets[nhidesets] = hs1; 63 | return nhidesets++; 64 | } 65 | 66 | int 67 | inserths(Hideset dhs, Hideset shs, Nlist *np) 68 | { 69 | Hideset odhs = dhs; 70 | 71 | while (*shs && *shs < np) 72 | *dhs++ = *shs++; 73 | if (*shs != np) 74 | *dhs++ = np; 75 | do { 76 | *dhs++ = *shs; 77 | } while (*shs++); 78 | return dhs - odhs; 79 | } 80 | 81 | /* 82 | * Hideset union 83 | */ 84 | int 85 | unionhideset(int hs1, int hs2) 86 | { 87 | Hideset hp; 88 | 89 | for (hp = hidesets[hs2]; *hp; hp++) 90 | hs1 = newhideset(hs1, *hp); 91 | return hs1; 92 | } 93 | 94 | void 95 | iniths(void) 96 | { 97 | hidesets = (Hideset *)domalloc(maxhidesets*sizeof(Hideset *)); 98 | hidesets[0] = (Hideset)domalloc(sizeof *hidesets[0]); 99 | *hidesets[0] = NULL; 100 | nhidesets++; 101 | } 102 | 103 | void 104 | prhideset(int hs) 105 | { 106 | Hideset np; 107 | 108 | for (np = hidesets[hs]; *np; np++) { 109 | fprintf(stderr, (char*)(*np)->name, (*np)->len); 110 | fprintf(stderr, " "); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /lcc-1.3/cpp/include.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "cpp.h" 5 | 6 | Includelist includelist[NINCLUDE]; 7 | 8 | extern char *objname; 9 | 10 | void 11 | doinclude(Tokenrow *trp) 12 | { 13 | char fname[256], iname[256]; 14 | Includelist *ip; 15 | int angled, len, i; 16 | FILE *fd; 17 | 18 | trp->tp += 1; 19 | if (trp->tp>=trp->lp) 20 | goto syntax; 21 | if (trp->tp->type!=STRING && trp->tp->type!=LT) { 22 | len = trp->tp - trp->bp; 23 | expandrow(trp, ""); 24 | trp->tp = trp->bp+len; 25 | } 26 | if (trp->tp->type==STRING) { 27 | len = trp->tp->len-2; 28 | if (len > sizeof(fname) - 1) 29 | len = sizeof(fname) - 1; 30 | strncpy(fname, (char*)trp->tp->t+1, len); 31 | angled = 0; 32 | } else if (trp->tp->type==LT) { 33 | len = 0; 34 | trp->tp++; 35 | while (trp->tp->type!=GT) { 36 | if (trp->tp>trp->lp || len+trp->tp->len+2 >= sizeof(fname)) 37 | goto syntax; 38 | strncpy(fname+len, (char*)trp->tp->t, trp->tp->len); 39 | len += trp->tp->len; 40 | trp->tp++; 41 | } 42 | angled = 1; 43 | } else 44 | goto syntax; 45 | trp->tp += 2; 46 | if (trp->tp < trp->lp || len==0) 47 | goto syntax; 48 | fname[len] = '\0'; 49 | if (fname[0]=='/') { 50 | fd = fopen(fname, "r"); 51 | strcpy(iname, fname); 52 | } else for (fd = NULL,i=NINCLUDE-1; i>=0; i--) { 53 | ip = &includelist[i]; 54 | if (ip->file==NULL || ip->deleted || (angled && ip->always==0)) 55 | continue; 56 | if (strlen(fname)+strlen(ip->file)+2 > sizeof(iname)) 57 | continue; 58 | strcpy(iname, ip->file); 59 | strcat(iname, "/"); 60 | strcat(iname, fname); 61 | if ((fd = fopen(iname, "r")) != NULL) 62 | break; 63 | } 64 | if ( Mflag>1 || !angled&&Mflag==1 ) { 65 | fwrite(objname,1,strlen(objname),stdout); 66 | fwrite(iname,1,strlen(iname),stdout); 67 | fwrite("\n",1,1,stdout); 68 | } 69 | if (fd != NULL) { 70 | if (++incdepth > 10) 71 | error(FATAL, "#include too deeply nested"); 72 | setsource((char*)newstring((uchar*)iname, strlen(iname), 0), fd, NULL); 73 | genline(); 74 | } else { 75 | trp->tp = trp->bp+2; 76 | error(ERROR, "Could not find include file %r", trp); 77 | } 78 | return; 79 | syntax: 80 | error(ERROR, "Syntax error in #include"); 81 | return; 82 | } 83 | 84 | /* 85 | * Generate a line directive for cursource 86 | */ 87 | void 88 | genline(void) 89 | { 90 | static Token ta = { UNCLASS }; 91 | static Tokenrow tr = { &ta, &ta, &ta+1, 1 }; 92 | uchar *p; 93 | 94 | ta.t = p = (uchar*)outp; 95 | strcpy((char*)p, "#line "); 96 | p += sizeof("#line ")-1; 97 | p = (uchar*)outnum((char*)p, cursource->line); 98 | *p++ = ' '; *p++ = '"'; 99 | strcpy((char*)p, cursource->filename); 100 | p += strlen((char*)p); 101 | *p++ = '"'; *p++ = '\n'; 102 | ta.len = (char*)p-outp; 103 | outp = (char*)p; 104 | tr.tp = tr.bp; 105 | puttokens(&tr); 106 | } 107 | 108 | void 109 | setobjname(char *f) 110 | { 111 | int n = strlen(f); 112 | objname = (char*)domalloc(n+5); 113 | strcpy(objname,f); 114 | if(objname[n-2]=='.'){ 115 | strcpy(objname+n-1,"$O: "); 116 | }else{ 117 | strcpy(objname+n,"$O: "); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /lcc-1.3/cpp/nlist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "cpp.h" 5 | 6 | extern int getopt(int, char *const *, const char *); 7 | extern char *optarg; 8 | extern int optind; 9 | extern int verbose; 10 | extern int Cplusplus; 11 | Nlist *kwdefined; 12 | 13 | #define NLSIZE 128 14 | 15 | static Nlist *nlist[NLSIZE]; 16 | 17 | struct kwtab { 18 | char *kw; 19 | int val; 20 | int flag; 21 | } kwtab[] = { 22 | "if", KIF, ISKW, 23 | "ifdef", KIFDEF, ISKW, 24 | "ifndef", KIFNDEF, ISKW, 25 | "elif", KELIF, ISKW, 26 | "else", KELSE, ISKW, 27 | "endif", KENDIF, ISKW, 28 | "include", KINCLUDE, ISKW, 29 | "define", KDEFINE, ISKW, 30 | "undef", KUNDEF, ISKW, 31 | "line", KLINE, ISKW, 32 | "error", KERROR, ISKW, 33 | "pragma", KPRAGMA, ISKW, 34 | "eval", KEVAL, ISKW, 35 | "defined", KDEFINED, ISDEFINED+ISUNCHANGE, 36 | "ident", KPRAGMA, ISKW, /* treat like pragma (ignored) */ 37 | "__LINE__", KLINENO, ISMAC+ISUNCHANGE, 38 | "__FILE__", KFILE, ISMAC+ISUNCHANGE, 39 | "__DATE__", KDATE, ISMAC+ISUNCHANGE, 40 | "__TIME__", KTIME, ISMAC+ISUNCHANGE, 41 | "__STDC__", KSTDC, ISUNCHANGE, 42 | NULL 43 | }; 44 | 45 | unsigned long namebit[077+1]; 46 | Nlist *np; 47 | 48 | void 49 | setup_kwtab(void) 50 | { 51 | struct kwtab *kp; 52 | Nlist *np; 53 | Token t; 54 | static Token deftoken[1] = {{ NAME, 0, 0, 0, 7, (uchar*)"defined" }}; 55 | static Tokenrow deftr = { deftoken, deftoken, deftoken+1, 1 }; 56 | 57 | for (kp=kwtab; kp->kw; kp++) { 58 | t.t = (uchar*)kp->kw; 59 | t.len = strlen(kp->kw); 60 | np = lookup(&t, 1); 61 | np->flag = kp->flag; 62 | np->val = kp->val; 63 | if (np->val == KDEFINED) { 64 | kwdefined = np; 65 | np->val = NAME; 66 | np->vp = &deftr; 67 | np->ap = 0; 68 | } 69 | } 70 | } 71 | 72 | Nlist * 73 | lookup(Token *tp, int install) 74 | { 75 | unsigned int h; 76 | Nlist *np; 77 | uchar *cp, *cpe; 78 | 79 | h = 0; 80 | for (cp=tp->t, cpe=cp+tp->len; cpt==*np->name && tp->len==np->len 86 | && strncmp((char*)tp->t, (char*)np->name, tp->len)==0) 87 | return np; 88 | np = np->next; 89 | } 90 | if (install) { 91 | np = new(Nlist); 92 | np->vp = NULL; 93 | np->ap = NULL; 94 | np->flag = 0; 95 | np->val = 0; 96 | np->len = tp->len; 97 | np->name = newstring(tp->t, tp->len, 0); 98 | np->next = nlist[h]; 99 | nlist[h] = np; 100 | quickset(tp->t[0], tp->len>1? tp->t[1]:0); 101 | return np; 102 | } 103 | return NULL; 104 | } 105 | -------------------------------------------------------------------------------- /lcc-1.3/cpp/unix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "cpp.h" 6 | 7 | extern int getopt(int, char *const *, const char *); 8 | extern char *optarg, rcsid[]; 9 | extern int optind; 10 | int verbose; 11 | int Mflag; /* only print active include files */ 12 | char *objname; /* "src.$O: " */ 13 | int Cplusplus = 1; 14 | 15 | void 16 | setup(int argc, char **argv) 17 | { 18 | int c, i; 19 | FILE *fd; 20 | char *fp, *dp; 21 | Tokenrow tr; 22 | extern void setup_kwtab(void); 23 | 24 | setup_kwtab(); 25 | while ((c = getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1) 26 | switch (c) { 27 | case 'N': 28 | for (i=0; i=0; i--) { 34 | if (includelist[i].file==NULL) { 35 | includelist[i].always = 1; 36 | includelist[i].file = optarg; 37 | break; 38 | } 39 | } 40 | if (i<0) 41 | error(FATAL, "Too many -I directives"); 42 | break; 43 | case 'D': 44 | case 'U': 45 | setsource("", NULL, optarg); 46 | maketokenrow(3, &tr); 47 | gettokens(&tr, 1); 48 | doadefine(&tr, c); 49 | unsetsource(); 50 | break; 51 | case 'M': 52 | Mflag++; 53 | break; 54 | case 'v': 55 | fprintf(stderr, "%s %s\n", argv[0], rcsid); 56 | break; 57 | case 'V': 58 | verbose++; 59 | break; 60 | case '+': 61 | Cplusplus++; 62 | break; 63 | default: 64 | break; 65 | } 66 | dp = "."; 67 | fp = ""; 68 | fd = stdin; 69 | if (optind 4 | 5 | static char rcsid[] = "$Id: lc3.c,v 1.1.1.1 2004/03/24 04:37:35 sjp Exp $"; 6 | 7 | #ifndef PATHSEP 8 | #define PATHSEP "/" 9 | #endif 10 | 11 | 12 | #ifndef LCCDIR 13 | #define LCCDIR "." PATHSEP 14 | #endif 15 | 16 | #ifndef BASEDIR 17 | #define BASEDIR "." PATHSEP 18 | #endif 19 | 20 | /* char *suffixes[] = { ".c", ".i", ".s", ".o", ".out", 0 }; */ 21 | char *suffixes[] = { ".c", ".i", ".lcc", ".asm", ".obj", ".out", 0 }; 22 | char inputs[256] = ""; 23 | char *cpp[] = { LCCDIR "cpp", 24 | "-U__GNUC__", "-D__STDC__=1", "-D__STRICT_ANSI__", "-D__signed__=signed", 25 | "$1", "$2", "$3", 0 }; 26 | char *include[] = {"-I" LCCDIR "include", "-I" BASEDIR "lc3lib", 0 }; 27 | char *com[] = { LCCDIR "rcc", "-target=lc3", "$1", "$2", "$3", 0 }; 28 | char *as[] = { LCCDIR "lc3as", "$1", "$2", 0 }; 29 | char *ld[] = { LCCDIR "lc3pp", BASEDIR "lc3lib", "$1", "$2", "$3", 0 }; 30 | char *SourcePaste[] = { LCCDIR "SourcePaste", "$1", "$2", "$3", 0 }; 31 | 32 | extern char *concat(char *, char *); 33 | 34 | int option(char *arg) { 35 | if (strncmp(arg, "-lccdir=", 8) == 0) { 36 | include[0] = concat("-I", concat(&arg[8], PATHSEP "include")); 37 | cpp[0] = concat(&arg[8], PATHSEP "install" PATHSEP "cpp"); 38 | com[0] = concat(&arg[8], PATHSEP "install" PATHSEP "rcc"); 39 | ld[0] = concat(&arg[8], PATHSEP "install" PATHSEP "lc3lib"); 40 | ld[1] = concat(&arg[8], PATHSEP "lc3lib"); 41 | } else if (strncmp(arg, "-ld=", 4) == 0) { 42 | ld[0] = &arg[4]; 43 | } else if (strncmp(arg, "-g", 2) == 0) 44 | return 1; 45 | else return 0; 46 | return 1; 47 | } 48 | -------------------------------------------------------------------------------- /lcc-1.3/include/assert.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASSERT 2 | #define __ASSERT 3 | 4 | void assert(int); 5 | 6 | #endif /* __ASSERT */ 7 | 8 | #undef assert 9 | #ifdef NDEBUG 10 | #define assert(ignore) ((void)0) 11 | #else 12 | extern int _assert(char *, char *, unsigned); 13 | #define assert(e) ((void)((e)||_assert(#e, __FILE__, __LINE__))) 14 | #endif /* NDEBUG */ 15 | -------------------------------------------------------------------------------- /lcc-1.3/include/float.h: -------------------------------------------------------------------------------- 1 | #ifndef __FLOAT 2 | #define __FLOAT 3 | 4 | #define FLT_ROUNDS (__flt_rounds()) 5 | #define FLT_RADIX 2 6 | 7 | #define FLT_DIG 6 8 | #define FLT_EPSILON 1.19209289550781250000e-07 9 | #define FLT_MANT_DIG 24 10 | #define FLT_MAX 3.40282346638528860000e+38 11 | #define FLT_MAX_10_EXP 38 12 | #define FLT_MAX_EXP 128 13 | #define FLT_MIN 1.17549435082228750000e-38 14 | #define FLT_MIN_10_EXP -37 15 | #define FLT_MIN_EXP -125 16 | 17 | #define DBL_DIG 15 18 | #define DBL_EPSILON 2.22044604925031310000e-16 19 | #define DBL_MANT_DIG 53 20 | #define DBL_MAX 1.79769313486231570000e+308 21 | #define DBL_MAX_10_EXP 308 22 | #define DBL_MAX_EXP 1024 23 | #define DBL_MIN 2.22507385850720140000e-308 24 | #define DBL_MIN_10_EXP -307 25 | #define DBL_MIN_EXP -1021 26 | 27 | #define LDBL_MANT_DIG DBL_MANT_DIG 28 | #define LDBL_EPSILON DBL_EPSILON 29 | #define LDBL_DIG DBL_DIG 30 | #define LDBL_MIN_EXP DBL_MIN_EXP 31 | #define LDBL_MIN DBL_MIN 32 | #define LDBL_MIN_10_EXP DBL_MIN_10_EXP 33 | #define LDBL_MAX_EXP DBL_MAX_EXP 34 | #define LDBL_MAX DBL_MAX 35 | #define LDBL_MAX_10_EXP DBL_MAX_10_EXP 36 | 37 | #endif /* __FLOAT */ 38 | -------------------------------------------------------------------------------- /lcc-1.3/include/limits.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIMITS 2 | #define __LIMITS 3 | 4 | #define CHAR_BIT 8 5 | #define MB_LEN_MAX 1 6 | 7 | #define UCHAR_MAX 0xff 8 | #define USHRT_MAX 0xffff 9 | #define UINT_MAX (~0U) 10 | #define ULONG_MAX (~0UL) 11 | 12 | #define SCHAR_MAX 0x7f 13 | #define SHRT_MAX 0x7fff 14 | #define INT_MAX 0x7fffffff 15 | #define LONG_MAX 0x7fffffffL 16 | 17 | #define SCHAR_MIN (-SCHAR_MAX-1) 18 | #define SHRT_MIN (-SHRT_MAX-1) 19 | #define INT_MIN (-INT_MAX-1) 20 | #define LONG_MIN (-LONG_MAX-1) 21 | 22 | #ifdef __CHAR_UNSIGNED__ 23 | #define CHAR_MAX UCHAR_MAX 24 | #define CHAR_MIN 0 25 | #else 26 | #define CHAR_MAX SCHAR_MAX 27 | #define CHAR_MIN SCHAR_MIN 28 | #endif 29 | 30 | #endif /* __LIMITS */ 31 | -------------------------------------------------------------------------------- /lcc-1.3/include/math.h: -------------------------------------------------------------------------------- 1 | #ifndef __MATH 2 | #define __MATH 3 | 4 | #define HUGE_VAL 1.79769313486231570000e+308 5 | 6 | extern double acos(double); 7 | extern double asin(double); 8 | extern double atan(double); 9 | extern double atan2(double, double); 10 | extern double cos(double); 11 | extern double sin(double); 12 | extern double tan(double); 13 | extern double cosh(double); 14 | extern double sinh(double); 15 | extern double tanh(double); 16 | extern double exp(double); 17 | extern double frexp(double, int *); 18 | extern double ldexp(double, int); 19 | extern double log(double); 20 | extern double log10(double); 21 | extern double modf(double, double *); 22 | extern double pow(double, double); 23 | extern double sqrt(double); 24 | extern double ceil(double); 25 | extern double fabs(double); 26 | extern double floor(double); 27 | extern double fmod(double, double); 28 | 29 | #endif /* __MATH */ 30 | -------------------------------------------------------------------------------- /lcc-1.3/include/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef __STDARG 2 | #define __STDARG 3 | 4 | #if !defined(_VA_LIST) && !defined(__VA_LIST_DEFINED) 5 | #define _VA_LIST 6 | #define _VA_LIST_DEFINED 7 | typedef char *__va_list; 8 | #endif 9 | static float __va_arg_tmp; 10 | typedef __va_list va_list; 11 | 12 | #define va_start(list, start) ((void)((list) = (sizeof(start)<4 ? \ 13 | (char *)((int *)&(start)+1) : (char *)(&(start)+1)))) 14 | #define __va_arg(list, mode, n) (\ 15 | __typecode(mode)==1 && sizeof(mode)==4 ? \ 16 | (__va_arg_tmp = *(double *)(&(list += ((sizeof(double)+n)&~n))[-(int)((sizeof(double)+n)&~n)]), \ 17 | *(mode *)&__va_arg_tmp) : \ 18 | *(mode *)(&(list += ((sizeof(mode)+n)&~n))[-(int)((sizeof(mode)+n)&~n)])) 19 | #define _bigendian_va_arg(list, mode, n) (\ 20 | sizeof(mode)==1 ? *(mode *)(&(list += 4)[-1]) : \ 21 | sizeof(mode)==2 ? *(mode *)(&(list += 4)[-2]) : __va_arg(list, mode, n)) 22 | #define _littleendian_va_arg(list, mode, n) __va_arg(list, mode, n) 23 | #define va_end(list) ((void)0) 24 | #define va_arg(list, mode) _littleendian_va_arg(list, mode, 3U) 25 | typedef void *__gnuc_va_list; 26 | #endif 27 | -------------------------------------------------------------------------------- /lcc-1.3/lburg/Makefile.def: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Makefile (and Makefile.def) -- Makefile for the LC-3 tools 3 | # 4 | # "Copyright (c) 2003 by Steven S. Lumetta." 5 | # 6 | # Permission to use, copy, modify, and distribute this software and its 7 | # documentation for any purpose, without fee, and without written 8 | # agreement is hereby granted, provided that the above copyright notice 9 | # and the following two paragraphs appear in all copies of this software, 10 | # that the files COPYING and NO_WARRANTY are included verbatim with 11 | # any distribution, and that the contents of the file README are included 12 | # verbatim as part of a file named README with any distribution. 13 | # 14 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, 15 | # INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 16 | # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR 17 | # HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 18 | # 19 | # THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | # A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 22 | # BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 23 | # UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 24 | # 25 | # Author: Steve Lumetta 26 | # Version: 1 27 | # Creation Date: 18 October 2003 28 | # Filename: Makefile[.def] 29 | # History: 30 | # SSL 2 31 October 2003 31 | # Added lc3convert tool into distribution. 32 | # SSL 1 18 October 2003 33 | # Copyright notices and Gnu Public License marker added. 34 | # 35 | ############################################################################### 36 | 37 | # These path names are automatically set by configure. 38 | GCC = __GCC__ 39 | FLEX = __FLEX__ 40 | EXE = __EXE__ 41 | RM = __RM__ 42 | CP = __CP__ 43 | MKDIR = __MKDIR__ 44 | CHMOD = __CHMOD__ 45 | SED = __SED__ 46 | MAKE = __MAKE__ 47 | AR = __AR__ 48 | RANLIB = __RANLIB__ 49 | INSTALL_DIR = __INSTALL_DIR__ 50 | TOP_DIR = __TOP_DIR__ 51 | # End of configuration block. 52 | 53 | CFLAGS = -g -I. ${EXTRAFLAGS} 54 | LDFLAGS = -g ${EXTRAFLAGS} 55 | LC3AS = ./lc3as 56 | 57 | %.o: %.c 58 | ${GCC} -c ${CFLAGS} -o $@ $< 59 | 60 | dist: lburg 61 | 62 | distclean: 63 | ${RM} -f *.o *~ 64 | 65 | distclear: distclean 66 | ${RM} -f lburg${EXE} 67 | 68 | lburg: gram.o lburg.o 69 | ${GCC} ${CFLAGS} -o $@ $^ 70 | -------------------------------------------------------------------------------- /lcc-1.3/lburg/lburg.h: -------------------------------------------------------------------------------- 1 | #ifndef BURG_INCLUDED 2 | #define BURG_INCLUDED 3 | 4 | /* $Id: lburg.h,v 1.1.1.1 2004/03/24 04:37:35 sjp Exp $ */ 5 | /* iburg.c: */ 6 | extern void *alloc(int nbytes); 7 | 8 | typedef enum { TERM=1, NONTERM } Kind; 9 | typedef struct rule *Rule; 10 | typedef struct term *Term; 11 | struct term { /* terminals: */ 12 | char *name; /* terminal name */ 13 | Kind kind; /* TERM */ 14 | int esn; /* external symbol number */ 15 | int arity; /* operator arity */ 16 | Term link; /* next terminal in esn order */ 17 | Rule rules; /* rules whose pattern starts with term */ 18 | }; 19 | 20 | typedef struct nonterm *Nonterm; 21 | struct nonterm { /* nonterminals: */ 22 | char *name; /* nonterminal name */ 23 | Kind kind; /* NONTERM */ 24 | int number; /* identifying number */ 25 | int lhscount; /* # times nt appears in a rule lhs */ 26 | int reached; /* 1 iff reached from start nonterminal */ 27 | Rule rules; /* rules w/nonterminal on lhs */ 28 | Rule chain; /* chain rules w/nonterminal on rhs */ 29 | Nonterm link; /* next terminal in number order */ 30 | }; 31 | extern Nonterm nonterm(char *id); 32 | extern Term term(char *id, int esn); 33 | 34 | typedef struct tree *Tree; 35 | struct tree { /* tree patterns: */ 36 | void *op; /* a terminal or nonterminal */ 37 | Tree left, right; /* operands */ 38 | int nterms; /* number of terminal nodes in this tree */ 39 | }; 40 | extern Tree tree(char *op, Tree left, Tree right); 41 | 42 | struct rule { /* rules: */ 43 | Nonterm lhs; /* lefthand side nonterminal */ 44 | Tree pattern; /* rule pattern */ 45 | int ern; /* external rule number */ 46 | int packed; /* packed external rule number */ 47 | int cost; /* cost, if a constant */ 48 | char *code; /* cost, if an expression */ 49 | char *template; /* assembler template */ 50 | Rule link; /* next rule in ern order */ 51 | Rule next; /* next rule with same pattern root */ 52 | Rule chain; /* next chain rule with same rhs */ 53 | Rule decode; /* next rule with same lhs */ 54 | Rule kids; /* next rule with same _kids pattern */ 55 | }; 56 | extern Rule rule(char *id, Tree pattern, char *template, char *code); 57 | 58 | /* gram.y: */ 59 | void yyerror(char *fmt, ...); 60 | int yyparse(void); 61 | void yywarn(char *fmt, ...); 62 | extern int errcnt; 63 | extern FILE *infp; 64 | extern FILE *outfp; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lcc-1.3/lc3lib/__init.asm: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;;;; START of the header ;;;;; 3 | 4 | .Orig x0500 5 | INIT_CODE 6 | LD R5, STACK_ADDR 7 | ADD R6, R5, #0 8 | LD R4, GLOBAL_DATA_POINTER 9 | LD R7, GLOBAL_MAIN_POINTER 10 | jsrr R7 11 | 12 | ; The main function has finished, so we do nothing 13 | BUSY_LOOP: BR BUSY_LOOP 14 | 15 | 16 | GLOBAL_DATA_POINTER .FILL GLOBAL_DATA_START 17 | GLOBAL_MAIN_POINTER .FILL main 18 | STACK_ADDR .FILL xdfff 19 | 20 | ;;;; END of the header ;;;;; 21 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; 22 | -------------------------------------------------------------------------------- /lcc-1.3/lc3lib/getchar.asm: -------------------------------------------------------------------------------- 1 | 2 | ; char getchar(void) 3 | LC3_GFLAG lc3_getchar LC3_GFLAG .FILL getchar 4 | 5 | getchar 6 | 7 | STR R7, R6, #-3 8 | STR R0, R6, #-2 9 | GETC 10 | OUT 11 | STR R0, R6, #-1 12 | LDR R0, R6, #-2 13 | LDR R7, R6, #-3 14 | ADD R6, R6, #-1 15 | RET 16 | -------------------------------------------------------------------------------- /lcc-1.3/lc3lib/io_read.asm: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;io_read;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;;; short io_read(unsigned short io_addr); 3 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 | LC3_GFLAG lc3_io_read LC3_GFLAG .FILL io_read 5 | io_read 6 | ADD R6, R6, #-1 ; reserve place for return val 7 | 8 | STR R7, R6, #-1 ; push R7 9 | 10 | LDR R7, R6, #1 ; get io_addr 11 | LDR R7, R7, #0 ; read IO 12 | 13 | STR R7, R6, #0 ; put return val 14 | 15 | LDR R7, R6, #-1 ; pop R7 16 | RET 17 | -------------------------------------------------------------------------------- /lcc-1.3/lc3lib/io_write.asm: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;io_write;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;;; void io_write(unsigned short io_addr, short val); 3 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 | LC3_GFLAG lc3_io_write LC3_GFLAG .FILL io_write 5 | io_write 6 | ; I know that it is void function, but compiler is a bit stupid, 7 | ; and the caller will try to pop return value anyway 8 | ADD R6, R6, #-1 ; reserve place for return value 9 | 10 | STR R7, R6, #-1 ; push R7 11 | STR R0, R6, #-2 ; push R0 12 | 13 | LDR R7, R6, #1 ; get io_addr 14 | LDR R0, R6, #2 ; get val 15 | STR R0, R7, #0 ; write IO 16 | 17 | LDR R0, R6, #-2 ; pop R0 18 | LDR R7, R6, #-1 ; pop R7 19 | RET 20 | -------------------------------------------------------------------------------- /lcc-1.3/lc3lib/lc3io.h: -------------------------------------------------------------------------------- 1 | #ifndef __LC3_IO_H__ 2 | #define __LC3_IO_H__ 3 | 4 | #define STDIN_S 0xfe00u 5 | #define STDIN_D 0xfe02u 6 | #define STDOUT_S 0xfe04u 7 | #define STDOUT_D 0xfe06u 8 | #define SW_S 0xfe08u 9 | #define SW_D 0xfe0Au 10 | #define BTN_S 0xfe0cu 11 | #define BTN_D 0xfe0eu 12 | #define SSEG_S 0xfe10u 13 | #define SSEG_D 0xfe12u 14 | #define LED_S 0xfe14u 15 | #define LED_D 0xfe16u 16 | #define PS2KBD_S 0xfe18u 17 | #define PS2KBD_D 0xfe1au 18 | 19 | /* Interrupt control registers */ 20 | #define INT0_CR 0xfff0u 21 | #define INT1_CR 0xfff1u 22 | #define INT2_CR 0xfff2u 23 | #define INT3_CR 0xfff3u 24 | #define INT4_CR 0xfff4u 25 | #define INT5_CR 0xfff5u 26 | #define INT6_CR 0xfff6u 27 | #define INT7_CR 0xfff7u 28 | /* Machine control register */ 29 | #define LC3_MCR 0xfffeu 30 | 31 | 32 | #define IO_READY -0x8000 33 | 34 | /* Primitive I/O routines */ 35 | short io_read(unsigned short io_addr); 36 | void io_write(unsigned short io_addr, short val); 37 | 38 | /* Optimized blocking routines */ 39 | short stdin_wait_read(); 40 | void stdout_wait_write(short val); 41 | short ps2kbd_wait_read(); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /lcc-1.3/lc3lib/ps2kbd_wait_read.asm: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;kb_wait_read;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;;; short kb_wait_read(); 3 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 | LC3_GFLAG lc3_ps2kbd_wait_read LC3_GFLAG .FILL ps2kbd_wait_read 5 | kwr_KB_S .FILL xfe18 6 | 7 | ps2kbd_wait_read 8 | ADD R6, R6, #-1 ; reserve place for return val 9 | 10 | STR R7, R6, #-1 ; push R7 11 | STR R0, R6, #-2 ; push R0 12 | 13 | LD R7, kwr_KB_S 14 | LDR R0, R7, #0 ; read status 15 | BRzp #-2 16 | 17 | LDR R7, R7, #2 ; read IO 18 | 19 | STR R7, R6, #0 ; put return val 20 | 21 | LDR R0, R6, #-2 ; pop R0 22 | LDR R7, R6, #-1 ; pop R7 23 | RET 24 | -------------------------------------------------------------------------------- /lcc-1.3/lc3lib/putchar.asm: -------------------------------------------------------------------------------- 1 | 2 | 3 | ; void putchar(char) 4 | LC3_GFLAG lc3_putchar LC3_GFLAG .FILL putchar 5 | 6 | putchar 7 | 8 | STR R7, R6, #-3 9 | STR R0, R6, #-2 10 | 11 | LDR R0, R6, #0 12 | OUT 13 | 14 | LDR R0, R6, #-2 15 | LDR R7, R6, #-3 16 | ADD R6, R6, #-1 17 | RET 18 | -------------------------------------------------------------------------------- /lcc-1.3/lc3lib/stdin_wait_read.asm: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;stdin_wait_read;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;;; short stdin_wait_read(); 3 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 | LC3_GFLAG lc3_stdin_wait_read LC3_GFLAG .FILL stdin_wait_read 5 | swr_STDIN_S .FILL xfe00 6 | 7 | stdin_wait_read 8 | ADD R6, R6, #-1 ; reserve place for return val 9 | 10 | STR R7, R6, #-1 ; push R7 11 | STR R0, R6, #-2 ; pop R0 12 | 13 | LD R7, swr_STDIN_S 14 | LDR R0, R7, #0 ; read status 15 | BRzp #-2 16 | 17 | LDR R7, R7, #2 ; read IO 18 | 19 | STR R7, R6, #0 ; put return val 20 | 21 | LDR R0, R6, #-2 ; pop R0 22 | LDR R7, R6, #-1 ; pop R7 23 | RET 24 | -------------------------------------------------------------------------------- /lcc-1.3/lc3lib/stdio.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | extern void printf(const char *format, ...); 5 | extern void scanf(const char *format, ...); 6 | -------------------------------------------------------------------------------- /lcc-1.3/lc3lib/stdout_wait_write.asm: -------------------------------------------------------------------------------- 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;stdout_wait_write;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2 | ;;; void stdout_wait_write(short val); 3 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 | LC3_GFLAG stdout_wait_write LC3_GFLAG .FILL lc3_stdout_wait_write 5 | sww_STDOUT_S .FILL xfe04 6 | 7 | lc3_stdout_wait_write 8 | ; I know that it is void function, but compiler is a bit stupid, 9 | ; and the caller will try to pop return value anyway 10 | ADD R6, R6, #-1 ; reserve place for return val 11 | 12 | STR R7, R6, #-1 ; push R7 13 | STR R0, R6, #-2 ; push R0 14 | 15 | LD R7, sww_STDOUT_S 16 | LDR R0, R7, #0 ; read status 17 | BRzp #-2 18 | 19 | LDR R0, R6, #1 ; get val 20 | STR R0, R7, #2 ; write IO 21 | 22 | STR R7, R6, #0 ; put return val 23 | 24 | LDR R0, R6, #-2 ; pop R0 25 | LDR R7, R6, #-1 ; pop R7 26 | RET 27 | -------------------------------------------------------------------------------- /lcc-1.3/lc3pp/Makefile.def: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Makefile (and Makefile.def) -- Makefile for the LC-3 tools 3 | # 4 | # "Copyright (c) 2003 by Steven S. Lumetta." 5 | # 6 | # Permission to use, copy, modify, and distribute this software and its 7 | # documentation for any purpose, without fee, and without written 8 | # agreement is hereby granted, provided that the above copyright notice 9 | # and the following two paragraphs appear in all copies of this software, 10 | # that the files COPYING and NO_WARRANTY are included verbatim with 11 | # any distribution, and that the contents of the file README are included 12 | # verbatim as part of a file named README with any distribution. 13 | # 14 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, 15 | # INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 16 | # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR 17 | # HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 18 | # 19 | # THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | # A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 22 | # BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 23 | # UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 24 | # 25 | # Author: Steve Lumetta 26 | # Version: 1 27 | # Creation Date: 18 October 2003 28 | # Filename: Makefile[.def] 29 | # History: 30 | # SSL 2 31 October 2003 31 | # Added lc3convert tool into distribution. 32 | # SSL 1 18 October 2003 33 | # Copyright notices and Gnu Public License marker added. 34 | # 35 | ############################################################################### 36 | 37 | # These path names are automatically set by configure. 38 | GCC = __GCC__ 39 | FLEX = __FLEX__ 40 | EXE = __EXE__ 41 | RM = __RM__ 42 | CP = __CP__ 43 | MKDIR = __MKDIR__ 44 | CHMOD = __CHMOD__ 45 | SED = __SED__ 46 | MAKE = __MAKE__ 47 | AR = __AR__ 48 | RANLIB = __RANLIB__ 49 | INSTALL_DIR = __INSTALL_DIR__ 50 | TOP_DIR = __TOP_DIR__ 51 | # End of configuration block. 52 | 53 | CFLAGS = -g ${EXTRAFLAGS} 54 | LDFLAGS = -g ${EXTRAFLAGS} 55 | LC3AS = ./lc3as 56 | 57 | %.o: %.c 58 | ${GCC} -c ${CFLAGS} -o $@ $< 59 | 60 | dist: lc3pp SourcePaste 61 | 62 | distclean:: 63 | ${RM} -f *.o *~ 64 | 65 | distclear: distclean 66 | ${RM} -f lc3pp${EXE} 67 | ${RM} -f SourceMerge${EXE} 68 | 69 | lc3pp: lc3pp.c 70 | ${GCC} ${CFLAGS} -o $@ $< 71 | 72 | SourcePaste: SourcePaste.c 73 | ${GCC} ${CFLAGS} -o $@ $< 74 | 75 | -------------------------------------------------------------------------------- /lcc-1.3/lib/Makefile.def: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Makefile (and Makefile.def) -- Makefile for the LC-3 tools 3 | # 4 | # "Copyright (c) 2003 by Steven S. Lumetta." 5 | # 6 | # Permission to use, copy, modify, and distribute this software and its 7 | # documentation for any purpose, without fee, and without written 8 | # agreement is hereby granted, provided that the above copyright notice 9 | # and the following two paragraphs appear in all copies of this software, 10 | # that the files COPYING and NO_WARRANTY are included verbatim with 11 | # any distribution, and that the contents of the file README are included 12 | # verbatim as part of a file named README with any distribution. 13 | # 14 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, 15 | # INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 16 | # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR 17 | # HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 18 | # 19 | # THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | # A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 22 | # BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 23 | # UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 24 | # 25 | # Author: Steve Lumetta 26 | # Version: 1 27 | # Creation Date: 18 October 2003 28 | # Filename: Makefile[.def] 29 | # History: 30 | # SSL 2 31 October 2003 31 | # Added lc3convert tool into distribution. 32 | # SSL 1 18 October 2003 33 | # Copyright notices and Gnu Public License marker added. 34 | # 35 | ############################################################################### 36 | 37 | # These path names are automatically set by configure. 38 | GCC = __GCC__ 39 | FLEX = __FLEX__ 40 | EXE = __EXE__ 41 | RM = __RM__ 42 | CP = __CP__ 43 | MKDIR = __MKDIR__ 44 | CHMOD = __CHMOD__ 45 | SED = __SED__ 46 | MAKE = __MAKE__ 47 | AR = __AR__ 48 | RANLIB = __RANLIB__ 49 | INSTALL_DIR = __INSTALL_DIR__ 50 | # End of configuration block. 51 | 52 | CFLAGS = -g -Wall ${EXTRAFLAGS} 53 | LDFLAGS = -g ${EXTRAFLAGS} 54 | LC3AS = ./lc3as 55 | 56 | %.o: %.c 57 | ${GCC} -c ${CFLAGS} -o $@ $< 58 | 59 | dist: liblcc.a 60 | 61 | distclean:: 62 | ${RM} -f *.o *~ 63 | 64 | distclear: distclean 65 | ${RM} -f liblcc.a 66 | 67 | liblcc.a: assert.o bbexit.o yynull.o 68 | -rm -f liblcc.a 69 | ${AR} cru $@ $< 70 | ${RANLIB} $@ 71 | 72 | -------------------------------------------------------------------------------- /lcc-1.3/lib/assert.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #ifndef EXPORT 4 | #define EXPORT 5 | #endif 6 | 7 | static char rcsid[] = "$Id: assert.c,v 1.1.1.1 2004/03/24 04:37:35 sjp Exp $"; 8 | 9 | EXPORT int _assert(char *e, char *file, int line) { 10 | fprintf(stderr, "assertion failed:"); 11 | if (e) 12 | fprintf(stderr, " %s", e); 13 | if (file) 14 | fprintf(stderr, " file %s", file); 15 | fprintf(stderr, " line %d\n", line); 16 | fflush(stderr); 17 | abort(); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /lcc-1.3/lib/bbexit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #ifndef EXPORT 4 | #define EXPORT 5 | #endif 6 | 7 | static char rcsid[] = "$Id: bbexit.c,v 1.1.1.1 2004/03/24 04:37:35 sjp Exp $"; 8 | 9 | EXPORT struct callsite { 10 | char *file, *name; 11 | union coordinate { 12 | struct { unsigned int index:6,x:10,y:16; } be; 13 | struct { unsigned int y:16,x:10,index:6; } le; 14 | unsigned int coord; 15 | } u; 16 | } *_caller, **_callerp = &_caller; 17 | 18 | EXPORT void _setcallerp(struct callsite **p) { 19 | _callerp = p; 20 | } 21 | 22 | static struct _bbdata { 23 | struct _bbdata *link; 24 | int npoints, *counts; 25 | union coordinate *coords; 26 | char **files; 27 | struct func { 28 | struct func *link; 29 | struct caller { 30 | struct caller *link; 31 | struct callsite *caller; 32 | int count; 33 | } *callers; 34 | char *name; 35 | union coordinate src; 36 | } *funcs; 37 | } tail, *_bblist = &tail; 38 | 39 | static void unpack(unsigned int coord, int *index, int *x, int *y) { 40 | static union { int x; char endian; } little = { 1 }; 41 | union coordinate u; 42 | 43 | u.coord = coord; 44 | if (little.endian) { 45 | *index = u.le.index; 46 | *x = u.le.x; 47 | *y = u.le.y; 48 | } else { 49 | *index = u.be.index; 50 | *x = u.be.x; 51 | *y = u.be.y; 52 | } 53 | } 54 | 55 | static void profout(struct _bbdata *p, FILE *fp) { 56 | int i, index, x, y; 57 | struct func *f; 58 | struct caller *q; 59 | 60 | for (i = 0; p->files[i]; i++) 61 | ; 62 | fprintf(fp, "%d\n", i); 63 | for (i = 0; p->files[i]; i++) 64 | fprintf(fp, "%s\n", p->files[i]); 65 | for (i = 0, f = p->funcs; f; i++, f = f->link) 66 | if (q = f->callers) 67 | for (i--; q; q = q->link) 68 | i++; 69 | fprintf(fp, "%d\n", i); 70 | for (f = p->funcs; f; f = f->link) { 71 | int n = 0; 72 | for (q = f->callers; q; n += q->count, q = q->link) { 73 | unpack(f->src.coord, &index, &x, &y); 74 | fprintf(fp, "%s %d %d %d %d", f->name, index, x, y, q->count); 75 | if (q->caller) { 76 | unpack(q->caller->u.coord, &index, &x, &y); 77 | fprintf(fp, " %s %s %d %d\n", q->caller->name, q->caller->file, x, y); 78 | } else 79 | fprintf(fp, " ? ? 0 0\n"); 80 | } 81 | if (n == 0) { 82 | unpack(f->src.coord, &index, &x, &y); 83 | fprintf(fp, "%s %d %d %d 0 ? ? 0 0\n", f->name, index, x, y); 84 | } 85 | } 86 | fprintf(fp, "%d\n", p->npoints); 87 | for (i = 0; i < p->npoints; i++) { 88 | unpack(p->coords[i].coord, &index, &x, &y); 89 | fprintf(fp, "%d %d %d %d\n", index, x, y, p->counts[i]); 90 | } 91 | } 92 | 93 | static void bbexit(void) { 94 | FILE *fp; 95 | 96 | if (_bblist != &tail && (fp = fopen("prof.out", "a"))) { 97 | for ( ; _bblist != &tail; _bblist = _bblist->link) 98 | profout(_bblist, fp); 99 | fclose(fp); 100 | } 101 | } 102 | 103 | EXPORT void _epilogue(struct func *callee) { 104 | *_callerp = 0; 105 | } 106 | 107 | EXPORT void _prologue(struct func *callee, struct _bbdata *yylink) { 108 | static struct caller callers[4096]; 109 | static int next; 110 | struct caller *p; 111 | 112 | if (!yylink->link) { 113 | yylink->link = _bblist; 114 | _bblist = yylink; 115 | if (next == 0) 116 | atexit(bbexit); 117 | } 118 | for (p = callee->callers; p; p = p->link) 119 | if (p->caller == *_callerp) { 120 | p->count++; 121 | break; 122 | } 123 | if (!p && next < sizeof callers/sizeof callers[0]) { 124 | p = &callers[next++]; 125 | p->caller = *_callerp; 126 | p->count = 1; 127 | p->link = callee->callers; 128 | callee->callers = p; 129 | } 130 | *_callerp = 0; 131 | } 132 | -------------------------------------------------------------------------------- /lcc-1.3/lib/yynull.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #ifndef EXPORT 4 | #define EXPORT 5 | #endif 6 | 7 | static char rcsid[] = "$Id: yynull.c,v 1.1.1.1 2004/03/24 04:37:35 sjp Exp $"; 8 | 9 | EXPORT void _YYnull(char *file, int line) { 10 | fprintf(stderr, "null pointer dereferenced:"); 11 | if (file) 12 | fprintf(stderr, " file %s,", file); 13 | fprintf(stderr, " line %d\n", line); 14 | fflush(stderr); 15 | abort(); 16 | } 17 | -------------------------------------------------------------------------------- /lcc-1.3/src/Makefile.def: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Makefile (and Makefile.def) -- Makefile for the LC-3 tools 3 | # 4 | # "Copyright (c) 2003 by Steven S. Lumetta." 5 | # 6 | # Permission to use, copy, modify, and distribute this software and its 7 | # documentation for any purpose, without fee, and without written 8 | # agreement is hereby granted, provided that the above copyright notice 9 | # and the following two paragraphs appear in all copies of this software, 10 | # that the files COPYING and NO_WARRANTY are included verbatim with 11 | # any distribution, and that the contents of the file README are included 12 | # verbatim as part of a file named README with any distribution. 13 | # 14 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, 15 | # INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 16 | # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR 17 | # HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 18 | # 19 | # THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | # A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" 22 | # BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 23 | # UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 24 | # 25 | # Author: Steve Lumetta 26 | # Version: 1 27 | # Creation Date: 18 October 2003 28 | # Filename: Makefile[.def] 29 | # History: 30 | # SSL 2 31 October 2003 31 | # Added lc3convert tool into distribution. 32 | # SSL 1 18 October 2003 33 | # Copyright notices and Gnu Public License marker added. 34 | # 35 | ############################################################################### 36 | 37 | # These path names are automatically set by configure. 38 | GCC = __GCC__ 39 | FLEX = __FLEX__ 40 | EXE = __EXE__ 41 | RM = __RM__ 42 | CP = __CP__ 43 | MKDIR = __MKDIR__ 44 | CHMOD = __CHMOD__ 45 | SED = __SED__ 46 | MAKE = __MAKE__ 47 | AR = __AR__ 48 | RANLIB = __RANLIB__ 49 | INSTALL_DIR = __INSTALL_DIR__ 50 | TOP_DIR = __TOP_DIR__ 51 | # End of configuration block. 52 | 53 | CFLAGS = -g ${EXTRAFLAGS} 54 | LDFLAGS = -g ${EXTRAFLAGS} 55 | LC3AS = ./lc3as 56 | 57 | GENENARED_C = dagcheck.c lc3.c lc3dtu.c sparc.c x86.c x86linux.c # alpha.c sparc.c mips.c x86.c x86linux.c 58 | 59 | librcc_OBJECTS = alloc.o bind.o dag.o decl.o \ 60 | enode.o error.o expr.o event.o \ 61 | init.o inits.o input.o lex.o list.o \ 62 | main.o output.o prof.o profio.o simp.o stmt.o \ 63 | string.o sym.o \ 64 | trace.o tree.o types.o null.o symbolic.o gen.o \ 65 | bytecode.o stab.o lc3_stab.o \ 66 | $(GENENARED_C:.c=.o) 67 | 68 | %.o: %.c 69 | ${GCC} -c ${CFLAGS} -o $@ $< 70 | 71 | $(GENENARED_C): %.c: %.md 72 | ${TOP_DIR}/lburg/lburg $< $@ 73 | 74 | dist: lburg rcc 75 | 76 | distclean: 77 | ${RM} -f *.o *~ 78 | cd ${TOP_DIR}/lburg && ${MAKE} distclean 79 | 80 | distclear: distclean 81 | ${RM} -f rcc${EXE} librcc.a 82 | cd ${TOP_DIR}/lburg && ${MAKE} distclear 83 | ${RM} -f Makefile 84 | ${RM} -f ${GENENARED_C} 85 | 86 | lburg: 87 | cd ${TOP_DIR}/lburg && ${MAKE} dist 88 | 89 | rcc: main.o librcc.a 90 | ${GCC} ${CFLAGS} -o $@ $^ 91 | 92 | librcc.a: ${librcc_OBJECTS} 93 | -rm -f librcc.a 94 | ${AR} cru librcc.a ${librcc_OBJECTS} 95 | ${RANLIB} librcc.a 96 | -------------------------------------------------------------------------------- /lcc-1.3/src/alloc.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | struct block { 3 | struct block *next; 4 | char *limit; 5 | char *avail; 6 | }; 7 | union align { 8 | long l; 9 | char *p; 10 | double d; 11 | int (*f)(void); 12 | }; 13 | union header { 14 | struct block b; 15 | union align a; 16 | }; 17 | #ifdef PURIFY 18 | union header *arena[3]; 19 | 20 | void *allocate(unsigned long n, unsigned a) { 21 | union header *new = malloc(sizeof *new + n); 22 | 23 | assert(a < NELEMS(arena)); 24 | if (new == NULL) { 25 | error("insufficient memory\n"); 26 | exit(1); 27 | } 28 | new->b.next = (void *)arena[a]; 29 | arena[a] = new; 30 | return new + 1; 31 | } 32 | 33 | void deallocate(unsigned a) { 34 | union header *p, *q; 35 | 36 | assert(a < NELEMS(arena)); 37 | for (p = arena[a]; p; p = q) { 38 | q = (void *)p->b.next; 39 | free(p); 40 | } 41 | arena[a] = NULL; 42 | } 43 | 44 | void *newarray(unsigned long m, unsigned long n, unsigned a) { 45 | return allocate(m*n, a); 46 | } 47 | #else 48 | static struct block 49 | first[] = { { NULL }, { NULL }, { NULL } }, 50 | *arena[] = { &first[0], &first[1], &first[2] }; 51 | static struct block *freeblocks; 52 | 53 | void *allocate(unsigned long n, unsigned a) { 54 | struct block *ap; 55 | 56 | assert(a < NELEMS(arena)); 57 | assert(n > 0); 58 | ap = arena[a]; 59 | n = roundup(n, sizeof (union align)); 60 | while (n > ap->limit - ap->avail) { 61 | if ((ap->next = freeblocks) != NULL) { 62 | freeblocks = freeblocks->next; 63 | ap = ap->next; 64 | } else 65 | { 66 | unsigned m = sizeof (union header) + n + roundup(10*1024, sizeof (union align)); 67 | ap->next = malloc(m); 68 | ap = ap->next; 69 | if (ap == NULL) { 70 | error("insufficient memory\n"); 71 | exit(1); 72 | } 73 | ap->limit = (char *)ap + m; 74 | } 75 | ap->avail = (char *)((union header *)ap + 1); 76 | ap->next = NULL; 77 | arena[a] = ap; 78 | 79 | } 80 | ap->avail += n; 81 | return ap->avail - n; 82 | } 83 | 84 | void *newarray(unsigned long m, unsigned long n, unsigned a) { 85 | return allocate(m*n, a); 86 | } 87 | void deallocate(unsigned a) { 88 | assert(a < NELEMS(arena)); 89 | arena[a]->next = freeblocks; 90 | freeblocks = first[a].next; 91 | first[a].next = NULL; 92 | arena[a] = &first[a]; 93 | } 94 | #endif 95 | -------------------------------------------------------------------------------- /lcc-1.3/src/bind.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | #undef yy 3 | #define yy \ 4 | xx(lc3, lc3IR) \ 5 | xx(lc3dtu, lc3dtuIR) \ 6 | xx(symbolic/osf, symbolic64IR) \ 7 | xx(symbolic/irix,symbolicIR) \ 8 | xx(symbolic, symbolicIR) \ 9 | xx(bytecode, bytecodeIR) \ 10 | xx(null, nullIR) 11 | 12 | #undef xx 13 | #define xx(a,b) extern Interface b; 14 | yy 15 | 16 | Binding bindings[] = { 17 | #undef xx 18 | #define xx(a,b) #a, &b, 19 | yy 20 | NULL, NULL 21 | }; 22 | #undef yy 23 | #undef xx 24 | -------------------------------------------------------------------------------- /lcc-1.3/src/config.h: -------------------------------------------------------------------------------- 1 | /* $Id: config.h,v 1.1.1.1 2004/03/24 04:37:33 sjp Exp $ */ 2 | typedef struct { 3 | unsigned char max_unaligned_load; 4 | Symbol (*rmap)(int); 5 | 6 | void (*blkfetch)(int size, int off, int reg, int tmp); 7 | void (*blkstore)(int size, int off, int reg, int tmp); 8 | void (*blkloop)(int dreg, int doff, 9 | int sreg, int soff, 10 | int size, int tmps[]); 11 | void (*_label)(Node); 12 | int (*_rule)(void*, int); 13 | short **_nts; 14 | void (*_kids)(Node, int, Node*); 15 | char **_string; 16 | char **_templates; 17 | char *_isinstruction; 18 | char **_ntname; 19 | void (*emit2)(Node); 20 | void (*doarg)(Node); 21 | void (*target)(Node); 22 | void (*clobber)(Node); 23 | } Xinterface; 24 | extern int askregvar(Symbol, Symbol); 25 | extern void blkcopy(int, int, int, int, int, int[]); 26 | extern unsigned emitasm(Node, int); 27 | extern int getregnum(Node); 28 | extern int mayrecalc(Node); 29 | extern int mkactual(int, int); 30 | extern void mkauto(Symbol); 31 | extern Symbol mkreg(char *, int, int, int); 32 | extern Symbol mkwildcard(Symbol *); 33 | extern int move(Node); 34 | extern int notarget(Node); 35 | extern void parseflags(int, char **); 36 | extern int range(Node, int, int); 37 | extern unsigned regloc(Symbol); /* omit */ 38 | extern void rtarget(Node, int, Symbol); 39 | extern void setreg(Node, Symbol); 40 | extern void spill(unsigned, int, Node); 41 | extern int widens(Node); 42 | 43 | extern int argoffset, maxargoffset; 44 | extern int bflag, dflag; 45 | extern int dalign, salign; 46 | extern int framesize; 47 | extern unsigned freemask[], usedmask[]; 48 | extern int offset, maxoffset; 49 | extern int swap; 50 | extern unsigned tmask[], vmask[]; 51 | typedef struct { 52 | unsigned listed:1; 53 | unsigned registered:1; 54 | unsigned emitted:1; 55 | unsigned copy:1; 56 | unsigned equatable:1; 57 | unsigned spills:1; 58 | unsigned mayrecalc:1; 59 | void *state; 60 | short inst; 61 | Node kids[3]; 62 | Node prev, next; 63 | Node prevuse; 64 | short argno; 65 | } Xnode; 66 | typedef struct { 67 | Symbol vbl; 68 | short set; 69 | short number; 70 | unsigned mask; 71 | } *Regnode; 72 | enum { IREG=0, FREG=1 }; 73 | typedef struct { 74 | char *name; 75 | unsigned int eaddr; /* omit */ 76 | int offset; 77 | Node lastuse; 78 | int usecount; 79 | Regnode regnode; 80 | Symbol *wildcard; 81 | } Xsymbol; 82 | enum { RX=2 }; 83 | typedef struct { 84 | int offset; 85 | unsigned freemask[2]; 86 | } Env; 87 | 88 | #define LBURG_MAX SHRT_MAX 89 | 90 | enum { VREG=(44<<4) }; 91 | 92 | /* Exported for the front end */ 93 | extern void blockbeg(Env *); 94 | extern void blockend(Env *); 95 | extern void emit(Node); 96 | extern Node gen(Node); 97 | 98 | extern unsigned emitbin(Node, int); 99 | 100 | #ifdef NDEBUG 101 | #define debug(x) (void)0 102 | #else 103 | #define debug(x) (void)(dflag&&((x),0)) 104 | #endif 105 | -------------------------------------------------------------------------------- /lcc-1.3/src/error.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | static char rcsid[] = "$Id: error.c,v 1.1.1.1 2004/03/24 04:37:33 sjp Exp $"; 4 | 5 | static void printtoken(void); 6 | int errcnt = 0; 7 | int errlimit = 20; 8 | char kind[] = { 9 | #define xx(a,b,c,d,e,f,g) f, 10 | #define yy(a,b,c,d,e,f,g) f, 11 | #include "token.h" 12 | }; 13 | int wflag; /* != 0 to suppress warning messages */ 14 | 15 | void test(int tok, char set[]) { 16 | if (t == tok) 17 | t = gettok(); 18 | else { 19 | expect(tok); 20 | skipto(tok, set); 21 | if (t == tok) 22 | t = gettok(); 23 | } 24 | } 25 | void expect(int tok) { 26 | if (t == tok) 27 | t = gettok(); 28 | else { 29 | error("syntax error; found"); 30 | printtoken(); 31 | fprint(stderr, " expecting `%k'\n", tok); 32 | } 33 | } 34 | void error(const char *fmt, ...) { 35 | va_list ap; 36 | 37 | if (errcnt++ >= errlimit) { 38 | errcnt = -1; 39 | error("too many errors\n"); 40 | exit(1); 41 | } 42 | va_start(ap, fmt); 43 | if (firstfile != file && firstfile && *firstfile) 44 | fprint(stderr, "%s: ", firstfile); 45 | fprint(stderr, "%w: ", &src); 46 | vfprint(stderr, NULL, fmt, ap); 47 | va_end(ap); 48 | } 49 | 50 | void skipto(int tok, char set[]) { 51 | int n; 52 | char *s; 53 | 54 | assert(set); 55 | for (n = 0; t != EOI && t != tok; t = gettok()) { 56 | for (s = set; *s && kind[t] != *s; s++) 57 | ; 58 | if (kind[t] == *s) 59 | break; 60 | if (n++ == 0) 61 | error("skipping"); 62 | if (n <= 8) 63 | printtoken(); 64 | else if (n == 9) 65 | fprint(stderr, " ..."); 66 | } 67 | if (n > 8) { 68 | fprint(stderr, " up to"); 69 | printtoken(); 70 | } 71 | if (n > 0) 72 | fprint(stderr, "\n"); 73 | } 74 | /* fatal - issue fatal error message and exit */ 75 | int fatal(const char *name, const char *fmt, int n) { 76 | print("\n"); 77 | errcnt = -1; 78 | error("compiler error in %s--", name); 79 | fprint(stderr, fmt, n); 80 | exit(EXIT_FAILURE); 81 | return 0; 82 | } 83 | 84 | /* printtoken - print current token preceeded by a space */ 85 | static void printtoken(void) { 86 | switch (t) { 87 | case ID: fprint(stderr, " `%s'", token); break; 88 | case ICON: 89 | fprint(stderr, " `%s'", vtoa(tsym->type, tsym->u.c.v)); 90 | break; 91 | case SCON: { 92 | int i, n; 93 | if (ischar(tsym->type->type)) { 94 | char *s = tsym->u.c.v.p; 95 | n = tsym->type->size; 96 | fprint(stderr, " \""); 97 | for (i = 0; i < 20 && i < n && *s; s++, i++) 98 | if (*s < ' ' || *s >= 0177) 99 | fprint(stderr, "\\%o", *s); 100 | else 101 | fprint(stderr, "%c", *s); 102 | } else { /* wchar_t string */ 103 | unsigned int *s = tsym->u.c.v.p; 104 | assert(tsym->type->type->size == widechar->size); 105 | n = tsym->type->size/widechar->size; 106 | fprint(stderr, " L\""); 107 | for (i = 0; i < 20 && i < n && *s; s++, i++) 108 | if (*s < ' ' || *s >= 0177) 109 | fprint(stderr, "\\x%x", *s); 110 | else 111 | fprint(stderr, "%c", *s); 112 | } 113 | if (i < n) 114 | fprint(stderr, " ..."); 115 | else 116 | fprint(stderr, "\""); 117 | break; 118 | } 119 | case FCON: 120 | fprint(stderr, " `%S'", token, (char*)cp - token); 121 | break; 122 | case '`': case '\'': fprint(stderr, " \"%k\"", t); break; 123 | default: fprint(stderr, " `%k'", t); 124 | } 125 | } 126 | 127 | /* warning - issue warning error message */ 128 | void warning(const char *fmt, ...) { 129 | va_list ap; 130 | 131 | va_start(ap, fmt); 132 | if (wflag == 0) { 133 | errcnt--; 134 | error("warning: "); 135 | vfprint(stderr, NULL, fmt, ap); 136 | } 137 | va_end(ap); 138 | } 139 | -------------------------------------------------------------------------------- /lcc-1.3/src/event.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | static char rcsid[] = "$Id: event.c,v 1.1.1.1 2004/03/24 04:37:33 sjp Exp $"; 4 | 5 | struct entry { 6 | Apply func; 7 | void *cl; 8 | }; 9 | 10 | Events events; 11 | void attach(Apply func, void *cl, List *list) { 12 | struct entry *p; 13 | 14 | NEW(p, PERM); 15 | p->func = func; 16 | p->cl = cl; 17 | *list = append(p, *list); 18 | } 19 | void apply(List event, void *arg1, void *arg2) { 20 | if (event) { 21 | List lp = event; 22 | do { 23 | struct entry *p = lp->x; 24 | (*p->func)(p->cl, arg1, arg2); 25 | lp = lp->link; 26 | } while (lp != event); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /lcc-1.3/src/inits.c: -------------------------------------------------------------------------------- 1 | void init(int argc, char *argv[]) { 2 | {extern void input_init(int, char *[]); input_init(argc, argv);} 3 | {extern void main_init(int, char *[]); main_init(argc, argv);} 4 | {extern void type_init(int, char *[]); type_init(argc, argv);} 5 | } 6 | -------------------------------------------------------------------------------- /lcc-1.3/src/input.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | static char rcsid[] = "$Id: input.c,v 1.1.1.1 2004/03/24 04:37:33 sjp Exp $"; 4 | 5 | static void pragma(void); 6 | static void resynch(void); 7 | 8 | static int bsize; 9 | static unsigned char buffer[MAXLINE+1 + BUFSIZE+1]; 10 | unsigned char *cp; /* current input character */ 11 | char *file; /* current input file name */ 12 | char *firstfile; /* first input file */ 13 | unsigned char *limit; /* points to last character + 1 */ 14 | char *line; /* current line */ 15 | int lineno; /* line number of current line */ 16 | 17 | void nextline(void) { 18 | do { 19 | if (cp >= limit) { 20 | fillbuf(); 21 | if (cp >= limit) 22 | cp = limit; 23 | if (cp == limit) 24 | return; 25 | } else { 26 | lineno++; 27 | for (line = (char *)cp; *cp==' ' || *cp=='\t'; cp++) 28 | ; 29 | if (*cp == '#') { 30 | resynch(); 31 | nextline(); 32 | } 33 | } 34 | } while (*cp == '\n' && cp == limit); 35 | } 36 | void fillbuf(void) { 37 | if (bsize == 0) 38 | return; 39 | if (cp >= limit) 40 | cp = &buffer[MAXLINE+1]; 41 | else 42 | { 43 | int n = limit - cp; 44 | unsigned char *s = &buffer[MAXLINE+1] - n; 45 | assert(s >= buffer); 46 | line = (char *)s - ((char *)cp - line); 47 | while (cp < limit) 48 | *s++ = *cp++; 49 | cp = &buffer[MAXLINE+1] - n; 50 | } 51 | if (feof(stdin)) 52 | bsize = 0; 53 | else 54 | bsize = fread(&buffer[MAXLINE+1], 1, BUFSIZE, stdin); 55 | if (bsize < 0) { 56 | error("read error\n"); 57 | exit(EXIT_FAILURE); 58 | } 59 | limit = &buffer[MAXLINE+1+bsize]; 60 | *limit = '\n'; 61 | } 62 | void input_init(int argc, char *argv[]) { 63 | static int inited; 64 | 65 | if (inited) 66 | return; 67 | inited = 1; 68 | main_init(argc, argv); 69 | limit = cp = &buffer[MAXLINE+1]; 70 | bsize = -1; 71 | lineno = 0; 72 | file = NULL; 73 | fillbuf(); 74 | if (cp >= limit) 75 | cp = limit; 76 | nextline(); 77 | } 78 | 79 | /* ident - handle #ident "string" */ 80 | static void ident(void) { 81 | while (*cp != '\n' && *cp != '\0') 82 | cp++; 83 | } 84 | 85 | /* pragma - handle #pragma ref id... */ 86 | static void pragma(void) { 87 | if ((t = gettok()) == ID && strcmp(token, "ref") == 0) 88 | for (;;) { 89 | while (*cp == ' ' || *cp == '\t') 90 | cp++; 91 | if (*cp == '\n' || *cp == 0) 92 | break; 93 | if ((t = gettok()) == ID && tsym) { 94 | tsym->ref++; 95 | use(tsym, src); 96 | } 97 | } 98 | } 99 | 100 | /* resynch - set line number/file name in # n [ "file" ], #pragma, etc. */ 101 | static void resynch(void) { 102 | for (cp++; *cp == ' ' || *cp == '\t'; ) 103 | cp++; 104 | if (limit - cp < MAXLINE) 105 | fillbuf(); 106 | if (strncmp((char *)cp, "pragma", 6) == 0) { 107 | cp += 6; 108 | pragma(); 109 | } else if (strncmp((char *)cp, "ident", 5) == 0) { 110 | cp += 5; 111 | ident(); 112 | } else if (*cp >= '0' && *cp <= '9') { 113 | line: for (lineno = 0; *cp >= '0' && *cp <= '9'; ) 114 | lineno = 10*lineno + *cp++ - '0'; 115 | lineno--; 116 | while (*cp == ' ' || *cp == '\t') 117 | cp++; 118 | if (*cp == '"') { 119 | file = (char *)++cp; 120 | while (*cp && *cp != '"' && *cp != '\n') 121 | cp++; 122 | file = stringn(file, (char *)cp - file); 123 | if (*cp == '\n') 124 | warning("missing \" in preprocessor line\n"); 125 | if (firstfile == 0) 126 | firstfile = file; 127 | } 128 | } else if (strncmp((char *)cp, "line", 4) == 0) { 129 | for (cp += 4; *cp == ' ' || *cp == '\t'; ) 130 | cp++; 131 | if (*cp >= '0' && *cp <= '9') 132 | goto line; 133 | if (Aflag >= 2) 134 | warning("unrecognized control line\n"); 135 | } else if (Aflag >= 2 && *cp != '\n') 136 | warning("unrecognized control line\n"); 137 | while (*cp) 138 | if (*cp++ == '\n') 139 | if (cp == limit + 1) { 140 | nextline(); 141 | if (cp == limit) 142 | break; 143 | } else 144 | break; 145 | } 146 | 147 | -------------------------------------------------------------------------------- /lcc-1.3/src/lc3_stab.h: -------------------------------------------------------------------------------- 1 | #ifndef _LC3_STAB_H 2 | #define _LC3_STAB_H 3 | 4 | #include "c.h" 5 | #include 6 | 7 | extern int lc3_stabFileId; 8 | 9 | void lc3_stabblock(int brace, int lev, Symbol *p); 10 | void lc3_stabinit(char *, int, char *[]); 11 | void lc3_stabline(Coordinate *); 12 | void lc3_stabsym(Symbol); 13 | 14 | 15 | 16 | // These are not used for debug info generation, but rather as general function 17 | // common to both lc3 targets. 18 | 19 | int calculate_address(int dstReg, int baseReg_, int offset, int withLDR, FILE *output); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lcc-1.3/src/list.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | 3 | static char rcsid[] = "$Id: list.c,v 1.1.1.1 2004/03/24 04:37:33 sjp Exp $"; 4 | 5 | static List freenodes; /* free list nodes */ 6 | 7 | /* append - append x to list, return new list */ 8 | List append(void *x, List list) { 9 | List new; 10 | 11 | if ((new = freenodes) != NULL) 12 | freenodes = freenodes->link; 13 | else 14 | NEW(new, PERM); 15 | if (list) { 16 | new->link = list->link; 17 | list->link = new; 18 | } else 19 | new->link = new; 20 | new->x = x; 21 | return new; 22 | } 23 | 24 | /* length - # elements in list */ 25 | int length(List list) { 26 | int n = 0; 27 | 28 | if (list) { 29 | List lp = list; 30 | do 31 | n++; 32 | while ((lp = lp->link) != list); 33 | } 34 | return n; 35 | } 36 | 37 | /* ltov - convert list to an NULL-terminated vector allocated in arena */ 38 | void *ltov(List *list, unsigned arena) { 39 | int i = 0; 40 | void **array = newarray(length(*list) + 1, sizeof array[0], arena); 41 | 42 | if (*list) { 43 | List lp = *list; 44 | do { 45 | lp = lp->link; 46 | array[i++] = lp->x; 47 | } while (lp != *list); 48 | #ifndef PURIFY 49 | lp = (*list)->link; 50 | (*list)->link = freenodes; 51 | freenodes = lp; 52 | #endif 53 | } 54 | *list = NULL; 55 | array[i] = NULL; 56 | return array; 57 | } 58 | -------------------------------------------------------------------------------- /lcc-1.3/src/null.c: -------------------------------------------------------------------------------- 1 | #include "c.h" 2 | #define I(f) null_##f 3 | 4 | static Node I(gen)(Node p) { return p; } 5 | static void I(address)(Symbol q, Symbol p, long n) {} 6 | static void I(blockbeg)(Env *e) {} 7 | static void I(blockend)(Env *e) {} 8 | static void I(defaddress)(Symbol p) {} 9 | static void I(defconst)(int suffix, int size, Value v) {} 10 | static void I(defstring)(int len, char *s) {} 11 | static void I(defsymbol)(Symbol p) {} 12 | static void I(emit)(Node p) {} 13 | static void I(export)(Symbol p) {} 14 | static void I(function)(Symbol f, Symbol caller[], Symbol callee[], int ncalls) {} 15 | static void I(global)(Symbol p) {} 16 | static void I(import)(Symbol p) {} 17 | static void I(local)(Symbol p) {} 18 | static void I(progbeg)(int argc, char *argv[]) {} 19 | static void I(progend)(void) {} 20 | static void I(segment)(int s) {} 21 | static void I(space)(int n) {} 22 | static void I(stabblock)(int brace, int lev, Symbol *p) {} 23 | static void I(stabend)(Coordinate *cp, Symbol p, Coordinate **cpp, Symbol *sp, Symbol *stab) {} 24 | static void I(stabfend)(Symbol p, int lineno) {} 25 | static void I(stabinit)(char *file, int argc, char *argv[]) {} 26 | static void I(stabline)(Coordinate *cp) {} 27 | static void I(stabsym)(Symbol p) {} 28 | static void I(stabtype)(Symbol p) {} 29 | 30 | static char rcsid[] = "$Id: null.c,v 1.1.1.1 2004/03/24 04:37:33 sjp Exp $"; 31 | 32 | Interface nullIR = { 33 | 1, 1, 0, /* char */ 34 | 2, 2, 0, /* short */ 35 | 4, 4, 0, /* int */ 36 | 8, 8, 1, /* long */ 37 | 8 ,8, 1, /* long long */ 38 | 4, 4, 1, /* float */ 39 | 8, 8, 1, /* double */ 40 | 16,16,1, /* long double */ 41 | 4, 4, 0, /* T* */ 42 | 0, 4, 0, /* struct */ 43 | 1, /* little_endian */ 44 | 0, /* mulops_calls */ 45 | 0, /* wants_callb */ 46 | 0, /* wants_argb */ 47 | 1, /* left_to_right */ 48 | 0, /* wants_dag */ 49 | 0, /* unsigned_char */ 50 | I(address), 51 | I(blockbeg), 52 | I(blockend), 53 | I(defaddress), 54 | I(defconst), 55 | I(defstring), 56 | I(defsymbol), 57 | I(emit), 58 | I(export), 59 | I(function), 60 | I(gen), 61 | I(global), 62 | I(import), 63 | I(local), 64 | I(progbeg), 65 | I(progend), 66 | I(segment), 67 | I(space), 68 | I(stabblock), 69 | I(stabend), 70 | I(stabfend), 71 | I(stabinit), 72 | I(stabline), 73 | I(stabsym), 74 | I(stabtype) 75 | }; 76 | -------------------------------------------------------------------------------- /lcc-1.3/src/ops.h: -------------------------------------------------------------------------------- 1 | /* $Id: ops.h,v 1.1.1.1 2004/03/24 04:37:33 sjp Exp $ */ 2 | 3 | gop(CNST,1) 4 | op(CNST,F,fdx) 5 | op(CNST,I,csilh) 6 | op(CNST,P,p) 7 | op(CNST,U,csilh) 8 | gop(ARG,2) 9 | op(ARG,B,-) 10 | op(ARG,F,fdx) 11 | op(ARG,I,ilh) 12 | op(ARG,P,p) 13 | op(ARG,U,ilh) 14 | gop(ASGN,3) 15 | op(ASGN,B,-) 16 | op(ASGN,F,fdx) 17 | op(ASGN,I,csilh) 18 | op(ASGN,P,p) 19 | op(ASGN,U,csilh) 20 | gop(INDIR,4) 21 | op(INDIR,B,-) 22 | op(INDIR,F,fdx) 23 | op(INDIR,I,csilh) 24 | op(INDIR,P,p) 25 | op(INDIR,U,csilh) 26 | gop(CVF,7) 27 | op(CVF,F,fdx) 28 | op(CVF,I,ilh) 29 | gop(CVI,8) 30 | op(CVI,F,fdx) 31 | op(CVI,I,csilh) 32 | op(CVI,U,csilhp) 33 | gop(CVP,9) 34 | op(CVP,U,p) 35 | gop(CVU,11) 36 | op(CVU,I,csilh) 37 | op(CVU,P,p) 38 | op(CVU,U,csilh) 39 | gop(NEG,12) 40 | op(NEG,F,fdx) 41 | op(NEG,I,ilh) 42 | gop(CALL,13) 43 | op(CALL,B,-) 44 | op(CALL,F,fdx) 45 | op(CALL,I,ilh) 46 | op(CALL,P,p) 47 | op(CALL,U,ilh) 48 | op(CALL,V,-) 49 | gop(RET,15) 50 | op(RET,F,fdx) 51 | op(RET,I,ilh) 52 | op(RET,P,p) 53 | op(RET,U,ilh) 54 | op(RET,V,-) 55 | gop(ADDRG,16) 56 | op(ADDRG,P,p) 57 | gop(ADDRF,17) 58 | op(ADDRF,P,p) 59 | gop(ADDRL,18) 60 | op(ADDRL,P,p) 61 | gop(ADD,19) 62 | op(ADD,F,fdx) 63 | op(ADD,I,ilh) 64 | op(ADD,P,p) 65 | op(ADD,U,ilhp) 66 | gop(SUB,20) 67 | op(SUB,F,fdx) 68 | op(SUB,I,ilh) 69 | op(SUB,P,p) 70 | op(SUB,U,ilhp) 71 | gop(LSH,21) 72 | op(LSH,I,ilh) 73 | op(LSH,U,ilh) 74 | gop(MOD,22) 75 | op(MOD,I,ilh) 76 | op(MOD,U,ilh) 77 | gop(RSH,23) 78 | op(RSH,I,ilh) 79 | op(RSH,U,ilh) 80 | gop(BAND,24) 81 | op(BAND,I,ilh) 82 | op(BAND,U,ilh) 83 | gop(BCOM,25) 84 | op(BCOM,I,ilh) 85 | op(BCOM,U,ilh) 86 | gop(BOR,26) 87 | op(BOR,I,ilh) 88 | op(BOR,U,ilh) 89 | gop(BXOR,27) 90 | op(BXOR,I,ilh) 91 | op(BXOR,U,ilh) 92 | gop(DIV,28) 93 | op(DIV,F,fdx) 94 | op(DIV,I,ilh) 95 | op(DIV,U,ilh) 96 | gop(MUL,29) 97 | op(MUL,F,fdx) 98 | op(MUL,I,ilh) 99 | op(MUL,U,ilh) 100 | gop(EQ,30) 101 | op(EQ,F,fdx) 102 | op(EQ,I,ilh) 103 | op(EQ,U,ilhp) 104 | gop(GE,31) 105 | op(GE,F,fdx) 106 | op(GE,I,ilh) 107 | op(GE,U,ilhp) 108 | gop(GT,32) 109 | op(GT,F,fdx) 110 | op(GT,I,ilh) 111 | op(GT,U,ilhp) 112 | gop(LE,33) 113 | op(LE,F,fdx) 114 | op(LE,I,ilh) 115 | op(LE,U,ilhp) 116 | gop(LT,34) 117 | op(LT,F,fdx) 118 | op(LT,I,ilh) 119 | op(LT,U,ilhp) 120 | gop(NE,35) 121 | op(NE,F,fdx) 122 | op(NE,I,ilh) 123 | op(NE,U,ilhp) 124 | gop(JUMP,36) 125 | op(JUMP,V,-) 126 | gop(LABEL,37) 127 | op(LABEL,V,-) 128 | gop(LOAD,14) 129 | op(LOAD,B,-) 130 | op(LOAD,F,fdx) 131 | op(LOAD,I,csilh) 132 | op(LOAD,P,p) 133 | op(LOAD,U,csilhp) 134 | -------------------------------------------------------------------------------- /lcc-1.3/test/known_problems/arithmetic_expressions/lfsr_random_using_xor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int random_test_16bits() { 4 | unsigned short lfsr = 0xACE1u; 5 | unsigned bit; 6 | unsigned period = 0; 7 | do 8 | { 9 | printf("%d: %d (%x)\n", period, lfsr, lfsr); 10 | /* taps: 16 14 13 11; characteristic polynomial: x^16 + x^14 + x^13 + x^11 + 1 */ 11 | bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1; 12 | lfsr = (lfsr >> 1) | (bit << 15); 13 | ++period; 14 | } while(lfsr != 0xACE1u); 15 | 16 | return 0; 17 | } 18 | 19 | 20 | 21 | int random_test_4bits() { 22 | const unsigned short initial = 0x1u; 23 | unsigned short lfsr = initial; 24 | unsigned bit; 25 | unsigned period = 0; 26 | do 27 | { 28 | printf("%d: %d (%x)\n", period, lfsr, lfsr); 29 | /* taps: 4 3; characteristic polynomial: x^4 + x^3 + 1 */ 30 | bit = ((lfsr >> 0) ^ (lfsr >> 1)) & 1; 31 | lfsr = (lfsr >> 1) | (bit << 3); 32 | ++period; 33 | } while(lfsr != initial); 34 | 35 | return 0; 36 | } 37 | 38 | int main(){ 39 | random_test_4bits(); 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /lcc-1.3/test/known_problems/constant_folding/constant_folding.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Status: 3 | * Workaround known 4 | * Description: 5 | * Constant folding. Fails to calculate correct folded value. 6 | * 1. Unsigned constants become truncated at 8'th bit. This happens 7 | * because lc3 has sizeof(int)==1, and lcc truncates unsigned constants 8 | * at 8*sizeof, to preserve semantics. 9 | * 2. Bitwise complement (BCOM) also fails the same way with signed constants. 10 | * From the source it seams that bitwise and (BAND) might also be affected. 11 | * Workaround: 12 | * 1. Don't use constant expressions. Assign constant and compute 13 | * expression in separate statements. 14 | * 2. Don't use unsigned constants. Express the same value as signed 15 | * (possibly negative) number. (Won't help with BCOM, BAND) 16 | * Source: 17 | * simplify() in src/simp.c: 18 | * see: l->u.v.i & ones(8*ty->size) 19 | * in: 20 | * case CVI+U: 21 | * case CVU+U: 22 | * case BAND+U: 23 | * case BAND+I: 24 | * case BCOM+U: 25 | * case BCOM+I: 26 | * Solution idea: 27 | * Because sizeof(int) == sizeof(char), we can't infer type from ty->size. 28 | * The ranges should be calculated according the ty matching Type variables 29 | * like: unsignedtype, unsignedlong, ... (from src/types.c) 30 | * There are probably more related problems waiting to emerge 31 | * "grep '[.>]size\>' *.c *.h" returns quite some number of uses of 32 | * ty->size. Maybe it might be good idea to introduce new field in Type 33 | * struct to distinguish betwean sizeof() size and valid range. 34 | */ 35 | 36 | #include 37 | 38 | #define UNSIGNED_CONST 0x00ffu 39 | // 40 | // Also doesn't work with any other constant bigger than 255 41 | // 42 | // #define UNSIGNED_CONST 0x0100u 43 | // #define UNSIGNED_CONST 0x1000u 44 | // #define UNSIGNED_CONST 0x8000u 45 | // 46 | // 47 | // But works fine if signed constants are used 48 | // 49 | // #define UNSIGNED_CONST 0x0100u 50 | // #define UNSIGNED_CONST 0x1000u 51 | // #define UNSIGNED_CONST 0x8000u 52 | // 53 | #define SIGNED_CONST 0x02ff 54 | 55 | int main() { 56 | /* 57 | * Unsigned truncation problem 58 | */ 59 | int i = UNSIGNED_CONST+1; 60 | 61 | printf("1. Badd: %d %x \n", i, i); 62 | 63 | i = UNSIGNED_CONST; 64 | i += 1; 65 | printf("1. Good: %d %x \n", i, i); 66 | 67 | /* 68 | * Unsigned truncation problem 69 | */ 70 | i = ~SIGNED_CONST; 71 | 72 | printf("2. Badd: %d %x \n", i, i); 73 | 74 | i = SIGNED_CONST; 75 | i = ~i; 76 | printf("2. Good: %d %x \n", i, i); 77 | 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /lcc-1.3/test/limitations/fig14.3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Function declarations */ 4 | double AreaOfCircle(double radius); 5 | 6 | int main() 7 | { 8 | double outer; /* Outer radius */ 9 | double inner; /* Inner radius */ 10 | double areaOfRing; /* Area of ring */ 11 | 12 | printf("Enter outer radius: "); 13 | scanf("%lf", &outer); 14 | 15 | printf("Enter inner radius: "); 16 | scanf("%lf", &inner); 17 | 18 | areaOfRing = AreaOfCircle(outer) - AreaOfCircle(inner); 19 | printf("The area of the ring is %f\n", areaOfRing); 20 | } 21 | 22 | /* Calculate area of circle given a radius */ 23 | double AreaOfCircle(double radius) 24 | { 25 | double pi = 3.14159265; 26 | 27 | return pi * radius * radius; 28 | } 29 | -------------------------------------------------------------------------------- /lcc-1.3/test/limitations/getchar.asm: -------------------------------------------------------------------------------- 1 | 2 | ; char getchar(void) 3 | LC3_GFLAG getchar LC3_GFLAG .FILL lc3_getchar 4 | 5 | lc3_getchar 6 | 7 | STR R7, R6, #-3 8 | STR R0, R6, #-2 9 | GETC 10 | OUT 11 | STR R0, R6, #-1 12 | LDR R0, R6, #-2 13 | LDR R7, R6, #-3 14 | ADD R6, R6, #-1 15 | RET 16 | -------------------------------------------------------------------------------- /lcc-1.3/test/limitations/init.c: -------------------------------------------------------------------------------- 1 | 2 | typedef struct { int codes[3]; char name[6]; } Word; 3 | 4 | Word words[] = { 5 | // 1, 2, 3, "if", 6 | { { 4, 5 }, { 'f', 'o', 'r' } }, 7 | // 6, 7, 8, {"else"}, 8 | // { { 9, 10, 11,}, 'w', 'h', 'i', 'l', 'e', }, 9 | // { 0 }, 10 | }, *wordlist = words; 11 | 12 | int x[][5] = { 1, 2, 3, 4, 0, { 5, 6 }, { 7 } }; 13 | int *y[] = { x[0], x[1], x[2], 0 }; 14 | 15 | 16 | main() 17 | { 18 | int i, j; 19 | 20 | for (i = 0; y[i]; i++) { 21 | for (j = 0; y[i][j]; j++) 22 | printf(" %d", y[i][j]); 23 | printf("\n"); 24 | } 25 | f(); 26 | g(wordlist); 27 | return 0; 28 | } 29 | 30 | f() { 31 | static char *keywords[] = {"if", "for", "else", "while", 0, }; 32 | char **p; 33 | 34 | for (p = keywords; *p; p++) 35 | printf("%s\n", *p); 36 | } 37 | 38 | g(p) 39 | Word *p; 40 | { 41 | int i; 42 | 43 | for ( ; p->codes[0]; p++) { 44 | for (i = 0; i < sizeof p->codes/sizeof(p->codes[0]); i++) 45 | printf("%d ", p->codes[i]); 46 | printf("%s\n", p->name); 47 | } 48 | h(); 49 | } 50 | 51 | h() 52 | { 53 | int i; 54 | 55 | for (i = 0; i < sizeof(words)/sizeof(Word); i++) 56 | printf("%d %d %d %s\n", words[i].codes[0], 57 | words[i].codes[1], words[i].codes[2], 58 | &words[i].name[0]); 59 | } 60 | -------------------------------------------------------------------------------- /lcc-1.3/test/limitations/makefile: -------------------------------------------------------------------------------- 1 | # Author: Ajay Ladsaria 2 | # Example Makefile to compile a C source file into LC-3 object code 3 | 4 | # Name of C source file 5 | CODE = fig18.1 6 | # Directory with rcc, gcc/cpp, gcc/include, other gcc files 7 | # Should be changed to an absolute path 8 | LCCDIR = ../../src 9 | # Directory with LC-3 library routines 10 | # Should be changed to an absolute path 11 | LC3LIB = ../../lc3lib 12 | 13 | all: $(CODE).obj 14 | 15 | remake: clean all 16 | 17 | # Assemble LC-3 .asm to LC-3 .obj 18 | # lc3as is distributed in a different package by Steven Lumetta 19 | $(CODE).obj: $(CODE).asm 20 | lc3as $(CODE).asm 21 | 22 | # Postprocessor (lc3pp) makes a couple passes on the LC-3 .asm outputted 23 | # by LCC 24 | $(CODE).asm: $(CODE).lcc 25 | ../../lc3pp/lc3pp $(LC3LIB) $(CODE).lcc $(CODE).asm 26 | #lc3pp $(LC3LIB) $(CODE).lcc $(CODE).asm 27 | 28 | # C compiler (lcc) 29 | # Options: -S stops after making the .asm 30 | # -Wo-lccdir= Tells it where to look for rcc, gcc stuff 31 | # -Wf-target=lc3 Tells it to make output for lc3 backend, the 32 | # other targets will not work correctly because 33 | # some target-independent code has been modified. 34 | # -I. Tells it to look for header files first in the 35 | # current directory 36 | $(CODE).lcc: $(CODE).c 37 | ../../etc/lcc -S -Wo-lccdir=$(LCCDIR) -Wf-target=lc3 -I. $(CODE).c -o $(CODE).lcc 38 | #lcc -S -Wo-lccdir=$(LCCDIR) -Wf-target=lc3 -I. $(CODE).c -o $(CODE).lcc 39 | 40 | $(CODE).c: 41 | 42 | clean: 43 | rm $(CODE).lcc $(CODE).asm $(CODE).obj $(CODE).sym 44 | 45 | -------------------------------------------------------------------------------- /lcc-1.3/test/limitations/printf.asm: -------------------------------------------------------------------------------- 1 | 2 | 3 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 | ; void printf(const char *format, ...) 5 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 6 | LC3_GFLAG printf LC3_GFLAG .FILL lc3_printf 7 | 8 | PRINTF_PERCENT .FILL -37 9 | PRINTF_C .FILL -99 10 | PRINTF_D .FILL -100 11 | PRINTF_S .FILL -115 12 | PRINTF_0 .FILL 48 ;postive ascii value of '0' 13 | PRINTF_MINUS .FILL 45 14 | PRINTF_BUF .BLKW 7 15 | 16 | 17 | lc3_printf 18 | ADD R6, R6, #-2 19 | STR R7, R6, #0 ;return address 20 | ADD R6, R6, #-1 21 | STR R5, R6, #0 22 | ADD R5, R6, #-1 23 | 24 | ADD R6, R6, #-1 25 | STR R4, R6, #0 26 | 27 | ADD R5, R5, #4 ;cheating with the bp (no longer bp) 28 | LDR R4, R5, #0 ;got addr of format string 29 | 30 | 31 | PRINTF_LOOP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 32 | 33 | LDR R0, R4, #0 34 | 35 | ADD R0, R0, #0 ;End of string? (0x0000) 36 | BRz PRINTF_DONE 37 | 38 | ADD R2, R0, #0 39 | LD R1, PRINTF_PERCENT 40 | ADD R2, R2, R1 41 | BRnp PRINTF_CHAR 42 | 43 | ADD R4, R4, #1 44 | LDR R0, R4, #0 45 | ;is it %c? 46 | ADD R2, R0, #0 47 | LD R3, PRINTF_C 48 | ADD R2, R2, R3 49 | BRnp PRINTF_CHECKSTR 50 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%c 51 | ADD R5, R5, #1 52 | LDR R0, R5, #0 53 | 54 | PRINTF_CHAR 55 | OUT 56 | 57 | ADD R4, R4, #1 58 | BRnzp PRINTF_LOOP 59 | 60 | PRINTF_CHECKSTR 61 | ;is it %s? 62 | ADD R2, R0, #0 63 | LD R7, PRINTF_S 64 | ADD R2, R2, R7 65 | BRnp PRINTF_CHECKDEC 66 | 67 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%s 68 | 69 | ADD R5, R5, #1 70 | LDR R0, R5, #0 71 | PUTS 72 | 73 | ADD R4, R4, #1 74 | BRnzp PRINTF_LOOP 75 | 76 | PRINTF_CHECKDEC 77 | ;is it %s? 78 | ADD R2, R0, #0 79 | LD R7, PRINTF_D 80 | ADD R2, R2, R7 81 | BRnp PRINTF_ERROR 82 | 83 | 84 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%d 85 | 86 | LEA R7, PRINTF_BUF 87 | ADD R7, R7, #5 88 | 89 | AND R2, R2, #0 90 | ADD R2, R2, #-10 ;going to divide by 10 by using sub loop 91 | 92 | ADD R5, R5, #1 ;acquire the binary number 93 | LDR R0, R5, #0 94 | 95 | ADD R0, R0, #0 96 | BRzp PRINTF_DECPOS 97 | 98 | NOT R0, R0 ;make num positive for sub loop 99 | ADD R0, R0, #1 100 | 101 | PRINTF_DECPOS 102 | 103 | AND R3, R3, #0 104 | ADD R3, R3, #-1 105 | 106 | PRINTF_DIVLOOP 107 | ADD R3, R3, #1 ;num/10 108 | ADD R0, R0, R2 ;R0 = num % 10 - 10 109 | BRzp PRINTF_DIVLOOP 110 | 111 | ADD R3, R3, #0 112 | BRz PRINTF_LASTDIGIT 113 | 114 | LD R1, PRINTF_0 115 | ADD R1, R1, R0 116 | ADD R1, R1, #10 117 | STR R1, R7, #0 118 | ADD R7, R7, #-1 ;stored ascii value of one digit 119 | 120 | ADD R0, R3, #0 ;num/10 121 | 122 | BRnzp PRINTF_DECPOS 123 | 124 | PRINTF_LASTDIGIT 125 | 126 | LD R1, PRINTF_0 127 | ADD R1, R1, R0 128 | ADD R1, R1, #10 129 | STR R1, R7, #0 ;stored ascii value of highest order digit 130 | 131 | LDR R0, R5, #0 132 | ADD R0, R0, #0 133 | BRzp PRINTF_DECSTRING 134 | 135 | LD R0, PRINTF_MINUS ;num was negative 136 | ADD R7, R7, #-1 137 | STR R0, R7, #0 ;stored ascii value negative sign 138 | 139 | PRINTF_DECSTRING ;print the calculated string 140 | ADD R0, R7, #0 141 | PUTS 142 | 143 | ADD R4, R4, #1 144 | BRnzp PRINTF_LOOP 145 | 146 | PRINTF_ERROR 147 | PRINTF_DONE 148 | 149 | LDR R4, R6, #0 ;restore R4 150 | ADD R6, R6, #1 151 | 152 | LDR R5, R6, #0 ;restore bp 153 | ADD R6, R6, #1 154 | 155 | LDR R7, R6, #0 ;restore ret addr 156 | ADD R6, R6, #1 157 | 158 | RET 159 | -------------------------------------------------------------------------------- /lcc-1.3/test/limitations/putchar.asm: -------------------------------------------------------------------------------- 1 | 2 | 3 | ; void putchar(char) 4 | LC3_GFLAG putchar LC3_GFLAG .FILL lc3_putchar 5 | 6 | lc3_putchar 7 | 8 | STR R7, R6, #-3 9 | STR R0, R6, #-2 10 | 11 | LDR R0, R6, #0 12 | OUT 13 | 14 | LDR R0, R6, #-2 15 | LDR R7, R6, #-3 16 | ADD R6, R6, #-1 17 | RET 18 | -------------------------------------------------------------------------------- /lcc-1.3/test/limitations/stdio.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | extern void printf(const char *format, ...); 5 | extern void scanf(const char *format, ...); 6 | -------------------------------------------------------------------------------- /lcc-1.3/test/limitations/wf1.c: -------------------------------------------------------------------------------- 1 | /* wf1 - print word frequencies; uses structures */ 2 | 3 | struct node { 4 | int count; /* frequency count */ 5 | struct node *left; /* left subtree */ 6 | struct node *right; /* right subtree */ 7 | char *word; /* word itself */ 8 | } words[2000]; 9 | int next; /* index of next free entry in words */ 10 | 11 | struct node *lookup(); 12 | 13 | main() { 14 | struct node *root; 15 | char word[20]; 16 | 17 | root = 0; 18 | next = 0; 19 | while (getword(word)) 20 | lookup(word, &root)->count++; 21 | tprint(root); 22 | return 0; 23 | } 24 | 25 | /* err - print error message s and die */ 26 | err(s) char *s; { 27 | printf("? %s\n", s); 28 | exit(1); 29 | } 30 | 31 | /* getword - get next input word into buf, return 0 on EOF */ 32 | int getword(buf) char *buf; { 33 | char *s; 34 | int c; 35 | 36 | while ((c = getchar()) != -1 && isletter(c) == 0) 37 | ; 38 | for (s = buf; c = isletter(c); c = getchar()) 39 | *s++ = c; 40 | *s = 0; 41 | if (s > buf) 42 | return (1); 43 | return (0); 44 | } 45 | 46 | /* isletter - return folded version of c if it is a letter, 0 otherwise */ 47 | int isletter(c) { 48 | if (c >= 'A' && c <= 'Z') 49 | c += 'a' - 'A'; 50 | if (c >= 'a' && c <= 'z') 51 | return (c); 52 | return (0); 53 | } 54 | 55 | /* lookup - lookup word in tree; install if necessary */ 56 | struct node *lookup(word, p) char *word; struct node **p; { 57 | int cond; 58 | char *malloc(); 59 | 60 | if (*p) { 61 | cond = strcmp(word, (*p)->word); 62 | if (cond < 0) 63 | return lookup(word, &(*p)->left); 64 | else if (cond > 0) 65 | return lookup(word, &(*p)->right); 66 | else 67 | return *p; 68 | } 69 | if (next >= 2000) 70 | err("out of node storage"); 71 | words[next].count = 0; 72 | words[next].left = words[next].right = 0; 73 | words[next].word = malloc(strlen(word) + 1); 74 | if (words[next].word == 0) 75 | err("out of word storage"); 76 | strcpy(words[next].word, word); 77 | return *p = &words[next++]; 78 | } 79 | 80 | /* tprint - print tree */ 81 | tprint(tree) struct node *tree; { 82 | if (tree) { 83 | tprint(tree->left); 84 | printf("%d\t%s\n", tree->count, tree->word); 85 | tprint(tree->right); 86 | } 87 | } 88 | 89 | /* strcmp - compare s1 and s2, return <0, 0, or >0 */ 90 | int strcmp(s1, s2) char *s1, *s2; { 91 | while (*s1 == *s2) { 92 | if (*s1++ == 0) 93 | return 0; 94 | ++s2; 95 | } 96 | if (*s1 == 0) 97 | return -1; 98 | else if (*s2 == 0) 99 | return 1; 100 | return *s1 - *s2; 101 | } 102 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/8q.c: -------------------------------------------------------------------------------- 1 | int up[15], down[15], rows[8], x[8]; 2 | int queens(), print(); 3 | 4 | main() 5 | { 6 | int i; 7 | 8 | for (i = 0; i < 15; i++) 9 | up[i] = down[i] = 1; 10 | for (i = 0; i < 8; i++) 11 | rows[i] = 1; 12 | queens(0); 13 | return 0; 14 | } 15 | 16 | queens(c) 17 | { 18 | int r; 19 | 20 | for (r = 0; r < 8; r++) 21 | if (rows[r] && up[r-c+7] && down[r+c]) { 22 | rows[r] = up[r-c+7] = down[r+c] = 0; 23 | x[c] = r; 24 | if (c == 7) 25 | print(); 26 | else 27 | queens(c + 1); 28 | rows[r] = up[r-c+7] = down[r+c] = 1; 29 | } 30 | } 31 | 32 | print() 33 | { 34 | int k; 35 | 36 | for (k = 0; k < 8; k++) 37 | printf("%c ", x[k]+'1'); 38 | printf("\n"); 39 | } 40 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/Makefile: -------------------------------------------------------------------------------- 1 | # Author: Ajay Ladsaria 2 | # Example Makefile to compile a C source file into LC-3 object code 3 | 4 | # Name of C source file 5 | CODE = fig16.14 6 | 7 | # Directory with rcc, cpp, lcc 8 | LCCDIR = ./ 9 | 10 | # Directory with LC-3 library routines 11 | LC3LIB = ../lc3lib 12 | 13 | all: $(CODE).obj 14 | 15 | remake: clean all 16 | 17 | # C compiler (lcc) 18 | $(CODE).obj: $(CODE).c 19 | lcc $(CODE).c -o $(CODE).obj 20 | 21 | $(CODE).c: 22 | 23 | clean: 24 | rm $(CODE).lcc $(CODE).asm $(CODE).obj $(CODE).sym 25 | 26 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/array.c: -------------------------------------------------------------------------------- 1 | int x[3][4], *y[3]; 2 | 3 | main() { 4 | int z[3][4]; 5 | int i, j, *p; 6 | 7 | for (i = 0; i < 3; i++) { 8 | for (j = 0; j < 4; j++) 9 | x[i][j] = 1000*i + j; 10 | y[i] = x[i]; 11 | } 12 | f(); 13 | for (i = 0; i < 3; i++) { 14 | y[i] = p = &z[i][0]; 15 | for (j = 0; j < 4; j++) 16 | p[j] = x[i][j]; 17 | } 18 | g(z, y); 19 | return 0; 20 | } 21 | 22 | f() { 23 | int i, j; 24 | 25 | for (i = 0; i < 3; i++) 26 | for (j = 0; j < 4; j++) 27 | printf(" %d", x[i][j]); 28 | printf("\n"); 29 | for (i = 0; i < 3; i++) 30 | for (j = 0; j < 4; j++) 31 | printf(" %d", y[i][j]); 32 | printf("\n"); 33 | } 34 | 35 | g(x, y) 36 | int x[][4], *y[]; 37 | { 38 | int i, j; 39 | 40 | for (i = 0; i < 3; i++) 41 | for (j = 0; j < 4; j++) 42 | printf(" %d", x[i][j]); 43 | printf("\n"); 44 | for (i = 0; i < 3; i++) 45 | for (j = 0; j < 4; j++) 46 | printf(" %d", y[i][j]); 47 | printf("\n"); 48 | } 49 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig14.1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void PrintBanner(); /* Function declaration */ 4 | 5 | int main() 6 | { 7 | PrintBanner(); /* Function call */ 8 | printf("A simple C program.\n"); 9 | PrintBanner(); 10 | } 11 | 12 | void PrintBanner() /* Function definition */ 13 | { 14 | printf("============================\n"); 15 | } 16 | 17 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig14.10.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Function declaration */ 4 | char ToUpper(char inchar); 5 | 6 | /* Function main: */ 7 | /* Prompt for a line of text, Read one character, */ 8 | /* convert to uppercase, print it out, then get another */ 9 | int main() 10 | { 11 | char echo = 'A'; /* Initialize input character */ 12 | char upcase; /* Converted character */ 13 | 14 | while (echo != '\n') { 15 | scanf("%c", &echo); 16 | upcase = ToUpper(echo); 17 | printf("%c", upcase); 18 | } 19 | } 20 | 21 | /* Function ToUpper: */ 22 | /* If the parameter is lower case return */ 23 | /* its uppercase ASCII value */ 24 | char ToUpper(char inchar) 25 | { 26 | char outchar; 27 | 28 | if ('a' <= inchar && inchar <= 'z') 29 | outchar = inchar - ('a' - 'A'); 30 | else 31 | outchar = inchar; 32 | 33 | return outchar; 34 | } 35 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig14.11.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int Squared(int x); 4 | 5 | int main() 6 | { 7 | int sideA; 8 | int sideB; 9 | int sideC; 10 | int maxC; 11 | 12 | printf("Enter the maximum length of hypotenuse: "); 13 | scanf("%d", &maxC); 14 | 15 | for (sideC = 1; sideC <= maxC; sideC++) { 16 | for (sideB = 1; sideB <= maxC; sideB++) { 17 | for (sideA = 1; sideA <= maxC; sideA++) { 18 | if (Squared(sideC) == Squared(sideA) + Squared(sideB)) 19 | printf("%d %d %d\n", sideA, sideB, sideC); 20 | } 21 | } 22 | } 23 | } 24 | 25 | /* Calculate the square of a number */ 26 | int Squared(int x) 27 | { 28 | return x * x; 29 | } 30 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig14.2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int Factorial(int n); /*! Function Declaration !*/ 4 | 5 | int main() /* Definition for main */ 6 | { 7 | int number; /* Number from user */ 8 | int answer; /* Answer of factorial */ 9 | 10 | printf("Input a number: "); /* Call to printf */ 11 | 12 | scanf("%d", &number); /* Call to scanf */ 13 | 14 | answer = Factorial(number); /*! Call to factorial !*/ 15 | 16 | printf("The factorial of %d is %d\n", number, answer); 17 | } 18 | 19 | int Factorial(int n) /*! Function Definition !*/ 20 | { 21 | int i; /* Iteration count */ 22 | int result = 1; /* Initialized result */ 23 | 24 | for (i = 1; i <= n; i++) /* Calculate factorial */ 25 | result = result * i; 26 | 27 | return result; /*! Return to caller !*/ 28 | } 29 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig15.1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i; 6 | int j; 7 | 8 | for (i = 0; i <= 10; i++) { 9 | j = i * 7; 10 | printf("%d x 7 = %d\n", i, j); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig15.2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int i; 6 | int j; 7 | 8 | for (i = 0; i <= 10; i++) 9 | j = i * 7; 10 | printf("%d x 7 = %d\n", i, j); 11 | } 12 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig15.3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int AllSum(int n); 4 | 5 | int main() 6 | { 7 | int in; /* Input value */ 8 | int sum; /* Value of 1+2+3+..+n */ 9 | 10 | printf("Input a number: "); 11 | scanf("%d", &in); 12 | 13 | sum = AllSum(in); 14 | printf("The AllSum of %d is %d\n", in, sum); 15 | } 16 | 17 | 18 | int AllSum(int n) 19 | { 20 | int result; /* Result to be returned */ 21 | int i; /* Iteration count */ 22 | 23 | for (i = 1; i <= n; i++) /* This calculates sum */ 24 | result = result + i; 25 | 26 | return result; /* Return to caller */ 27 | } 28 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig15.4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int year; 6 | 7 | printf("Input a year (i.e., 1996): "); 8 | scanf("%d", &year); 9 | 10 | if (year % 4 == 0) 11 | printf("This year is a leap year\n"); 12 | else 13 | printf("This year is not a leap year\n"); 14 | } 15 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig16.1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Swap(int firstVal, int secondVal); 4 | 5 | int main() 6 | { 7 | int valueA = 3; 8 | int valueB = 4; 9 | 10 | printf("Before Swap "); 11 | printf("valueA = %d and valueB = %d\n", valueA, valueB); 12 | 13 | Swap(valueA, valueB); 14 | 15 | printf("After Swap "); 16 | printf("valueA = %d and valueB = %d\n", valueA, valueB); 17 | } 18 | 19 | void Swap(int firstVal, int secondVal) 20 | { 21 | int tempVal; /* Holds firstVal when swapping */ 22 | 23 | tempVal = firstVal; 24 | firstVal = secondVal; 25 | secondVal = tempVal; 26 | } 27 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig16.10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX_NUMS 10 3 | 4 | int Average(int input_values[]); 5 | 6 | int main() 7 | { 8 | int index; /* Loop iteration variable */ 9 | int mean; /* average of numbers */ 10 | int numbers[MAX_NUMS]; /* Original input numbers */ 11 | 12 | 13 | /* Get input */ 14 | printf("Enter %d numbers.\n", MAX_NUMS); 15 | for (index = 0; index < MAX_NUMS; index++) { 16 | printf("Input number %d : ", index); 17 | scanf("%d", &numbers[index]); 18 | } 19 | 20 | mean = Average(numbers); 21 | 22 | printf("The average of these numbers is %d\n", mean); 23 | } 24 | 25 | int Average(int inputValues[]) 26 | { 27 | int index; 28 | int sum = 0; 29 | 30 | for (index = 0; index < MAX_NUMS; index++) { 31 | sum = sum + inputValues[index]; 32 | } 33 | 34 | return (sum / MAX_NUMS); 35 | } 36 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig16.12.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX_STRING 20 3 | 4 | int StringLength(char string[]); 5 | 6 | int main() 7 | { 8 | char input[MAX_STRING]; /* Input string */ 9 | int length = 0; 10 | 11 | printf("Input a word (less than 20 characters): "); 12 | scanf("%s", input); 13 | 14 | length = StringLength(input); 15 | printf("The word contains %d characters\n", length); 16 | } 17 | 18 | int StringLength(char string[]) 19 | { 20 | int index = 0; 21 | 22 | while (string[index] != '\0') 23 | index = index + 1; 24 | 25 | return index; 26 | } 27 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig16.13.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX_STRING 20 3 | 4 | int StringLength(char string[]); 5 | void CharSwap(char *firstVal, char *secondVal); 6 | void Reverse(char string[]); 7 | 8 | int main() 9 | { 10 | char input[MAX_STRING]; /* Input string */ 11 | 12 | printf("Input a word (less than 20 characters): "); 13 | scanf("%s", input); 14 | 15 | Reverse(input); 16 | printf("The word reversed is %s.\n", input); 17 | } 18 | 19 | int StringLength(char string[]) 20 | { 21 | int index = 0; 22 | 23 | while (string[index] != '\0') 24 | index = index + 1; 25 | 26 | return index; 27 | } 28 | 29 | void CharSwap(char *firstVal, char *secondVal) 30 | { 31 | char tempVal; /* Temporary location for swapping */ 32 | 33 | tempVal = *firstVal; 34 | *firstVal = *secondVal; 35 | *secondVal = tempVal; 36 | } 37 | 38 | void Reverse(char string[]) 39 | { 40 | int index; 41 | int length; 42 | 43 | length = StringLength(string); 44 | 45 | for (index = 0; index < (length / 2); index++) 46 | CharSwap(&string[index], &string[length - (index + 1)]); 47 | } 48 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig16.14.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX_NUMS 10 3 | 4 | void InsertionSort(int list[]); 5 | 6 | int main() 7 | { 8 | int index; /* iteration variable */ 9 | int numbers[MAX_NUMS]; /* list of number to be sorted */ 10 | 11 | /* Get input */ 12 | printf("Enter %d numbers.\n", MAX_NUMS); 13 | for (index = 0; index < MAX_NUMS; index++) { 14 | printf("Input number %d : ", index); 15 | scanf("%d", &numbers[index]); 16 | } 17 | 18 | InsertionSort(numbers); /* Call sorting routine */ 19 | 20 | /* Print sorted list */ 21 | printf("\nThe input set, in ascending order:\n"); 22 | for (index = 0; index < MAX_NUMS; index++) 23 | printf("%d\n", numbers[index]); 24 | } 25 | 26 | void InsertionSort(int list[]) 27 | { 28 | int unsorted; /* index for unsorted list items */ 29 | int sorted; /* index for sorted items */ 30 | int unsortedItem; /* Current item to be sorted */ 31 | 32 | /* This loop iterates from 1 thru MAX_NUMS */ 33 | for (unsorted = 1; unsorted < MAX_NUMS; unsorted++) { 34 | unsortedItem = list[unsorted]; 35 | 36 | /* This loop iterates from unsorted thru 0, unless 37 | we hit an element smaller than current item */ 38 | for (sorted = unsorted - 1; 39 | (sorted >= 0) && (list[sorted] > unsortedItem); 40 | sorted--) 41 | list[sorted + 1] = list[sorted]; 42 | 43 | list[sorted + 1] = unsortedItem; /* Insert item */ 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig16.4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void NewSwap(int *firstVal, int *secondVal); 4 | 5 | int main() 6 | { 7 | int valueA = 3; 8 | int valueB = 4; 9 | 10 | printf("Before Swap "); 11 | printf("valueA = %d and valueB = %d\n", valueA, valueB); 12 | 13 | NewSwap(&valueA, &valueB); 14 | 15 | printf("After Swap "); 16 | printf("valueA = %d and valueB = %d\n", valueA, valueB); 17 | } 18 | 19 | void NewSwap(int *firstVal, int *secondVal) 20 | { 21 | int tempVal; /* Holds firstVal when swapping */ 22 | 23 | tempVal = *firstVal; 24 | *firstVal = *secondVal; 25 | *secondVal = tempVal; 26 | } 27 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig16.6.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int IntDivide(int x, int y, int *quoPtr, int *remPtr); 4 | 5 | int main() 6 | { 7 | int dividend; /* The number to be divided */ 8 | int divisor; /* The number to divide by */ 9 | int quotient; /* Integer result of division */ 10 | int remainder; /* Integer remainder of division */ 11 | int error; /* Did something go wrong? */ 12 | 13 | printf("Input dividend: "); 14 | scanf("%d", ÷nd); 15 | printf("Input divisor: "); 16 | scanf("%d", &divisor); 17 | 18 | error = IntDivide(dividend,divisor,"ient,&remainder); 19 | 20 | if (!error) /* !error indicates no error */ 21 | printf("Answer: %d remainder %d\n", quotient, remainder); 22 | else 23 | printf("IntDivide failed.\n"); 24 | } 25 | 26 | int IntDivide(int x, int y, int *quoPtr, int *remPtr) 27 | { 28 | if (y != 0) { 29 | *quoPtr = x / y; /* Modify *quoPtr */ 30 | *remPtr = x % y; /* Modify *remPtr */ 31 | return 0; 32 | } 33 | else 34 | return -1; 35 | } 36 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig16.8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define NUM_STUDENTS 10 3 | 4 | int main() 5 | { 6 | int i; 7 | int Exam1[NUM_STUDENTS]; 8 | int Exam2[NUM_STUDENTS]; 9 | int Total[NUM_STUDENTS]; 10 | 11 | /* Input Exam 1 scores */ 12 | for (i = 0; i < NUM_STUDENTS; i++) { 13 | printf("Input Exam 1 score for student %d : ", i); 14 | scanf("%d", &Exam1[i]); 15 | } 16 | printf("\n"); 17 | 18 | /* Input Exam 2 scores */ 19 | for (i = 0; i < NUM_STUDENTS; i++) { 20 | printf("Input Exam 2 score for student %d : ", i); 21 | scanf("%d", &Exam2[i]); 22 | } 23 | printf("\n"); 24 | 25 | /* Calculate Total Points */ 26 | for (i = 0; i < NUM_STUDENTS; i++) { 27 | Total[i] = Exam1[i] + Exam2[i]; 28 | } 29 | 30 | /* Output the Total Points */ 31 | for (i = 0; i < NUM_STUDENTS; i++) { 32 | printf("Total for Student %d = %d\n", i, Total[i]); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig16.9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX_NUMS 10 3 | 4 | int main() 5 | { 6 | int index; /* Loop iteration variable */ 7 | int repIndex; /* Loop variable for rep loop */ 8 | int numbers[MAX_NUMS]; /* Original input numbers */ 9 | int repeats[MAX_NUMS]; /* Number of repeats */ 10 | 11 | /* Get input */ 12 | printf("Enter %d numbers.\n", MAX_NUMS); 13 | for (index = 0; index < MAX_NUMS; index++) { 14 | printf("Input number %d : ", index); 15 | scanf("%d", &numbers[index]); 16 | } 17 | 18 | /* Scan through entire array, counting number of */ 19 | /* repeats per element within the original array */ 20 | for (index = 0; index < MAX_NUMS; index++) { 21 | repeats[index] = 0; 22 | for (repIndex = 0; repIndex < MAX_NUMS; repIndex++) { 23 | if (numbers[repIndex] == numbers[index]) 24 | repeats[index]++; 25 | } 26 | } 27 | 28 | /* Print the results */ 29 | for (index = 0; index < MAX_NUMS; index++) 30 | printf("Original number %d. Number of repeats %d\n", 31 | numbers[index], repeats[index]); 32 | } 33 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig17.13.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int Fibonacci(int n); 4 | 5 | int main() 6 | { 7 | int in; 8 | int number; 9 | 10 | printf("Which Fibonacci number? "); 11 | scanf("%d", &in); 12 | 13 | number = Fibonacci(in); 14 | printf("That Fibonacci number is %d\n", number); 15 | } 16 | 17 | int Fibonacci(int n) 18 | { 19 | int sum; 20 | 21 | if (n == 0 || n == 1) 22 | return 1; 23 | else { 24 | sum = (Fibonacci(n-1) + Fibonacci(n-2)); 25 | return sum; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig17.18.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void IntToAscii(int i); 4 | 5 | int main() 6 | { 7 | int in; 8 | 9 | printf("Input number: "); 10 | scanf("%d", &in); 11 | 12 | IntToAscii(in); 13 | printf("\n"); 14 | } 15 | 16 | void IntToAscii(int num) 17 | { 18 | int prefix; 19 | int currDigit; 20 | 21 | if (num < 10) /* The terminal case */ 22 | printf("%c", num + '0'); 23 | else { 24 | prefix = num / 10; /* Convert the number */ 25 | IntToAscii(prefix); /* without last digit */ 26 | 27 | currDigit = num % 10; /* Then print last digit */ 28 | printf("%c", currDigit + '0'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/fig18.1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char inChar1; 6 | char inChar2; 7 | 8 | printf("Input character 1:\n"); 9 | inChar1 = getchar(); 10 | 11 | printf("Input character 2:\n"); 12 | inChar2 = getchar(); 13 | 14 | printf("Character 1 is %c\n", inChar1); 15 | printf("Character 2 is %c\n", inChar2); 16 | } 17 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/incr.c: -------------------------------------------------------------------------------- 1 | char gx = 'd'; 2 | char gy = 'd'; 3 | int a = 60; 4 | int b = 10; 5 | 6 | main() { 7 | memchar(); 8 | memint(); 9 | regchar(); 10 | regint(); 11 | } 12 | 13 | memchar() { 14 | char x, *p; 15 | 16 | &x, &p; 17 | x = gx; 18 | p = &gy; 19 | x = *p++; 20 | x = *++p; 21 | x = *p--; 22 | x = *--p; 23 | printf("%c %c\n",x,*p); 24 | } 25 | 26 | memint() { 27 | int x, *p; 28 | 29 | &x, &p; 30 | 31 | x = a; 32 | p = &b; 33 | x = *p++; 34 | x = *++p; 35 | x = *p--; 36 | x = *--p; 37 | printf("%d %x %o %b %d\n",x, x, x, x,*p); 38 | printf("%d %d\n", x,*p); 39 | } 40 | 41 | regchar() { 42 | register char x, *p; 43 | x = gx; 44 | p = &gy; 45 | 46 | x = *p++; 47 | x = *++p; 48 | x = *p--; 49 | x = *--p; 50 | printf("%c %c\n",x,*p); 51 | } 52 | 53 | regint() { 54 | register int x, *p; 55 | 56 | x = a; 57 | p = &b; 58 | x = *p++; 59 | x = *++p; 60 | x = *p--; 61 | x = *--p; 62 | printf("%x %d\n",x,*p); 63 | } 64 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/sort.c: -------------------------------------------------------------------------------- 1 | int nn[] = {10, 32, -1, 567, 3, 18, 1, -51, 789, 0}; 2 | 3 | main() { 4 | int i; 5 | 6 | sort(nn, (sizeof nn)/(sizeof nn[0])); 7 | for (i = 0; i < (sizeof nn)/(sizeof nn[0]); i++) { 8 | putd(nn[i]); 9 | putchar('\n'); 10 | } 11 | return 0; 12 | } 13 | 14 | /* putd - output decimal number */ 15 | putd(n) { 16 | if (n < 0) { 17 | putchar('-'); 18 | n = -n; 19 | } 20 | if (n/10) 21 | putd(n/10); 22 | putchar(n%10 + '0'); 23 | } 24 | 25 | int *xx; 26 | 27 | /* sort - sort a[0..n-1] into increasing order */ 28 | sort(a, n) int a[]; { 29 | quick(xx = a, 0, --n); 30 | } 31 | 32 | /* quick - quicksort a[lb..ub] */ 33 | quick(a, lb, ub) int a[]; { 34 | int k, partition(); 35 | 36 | if (lb >= ub) 37 | return; 38 | k = partition(a, lb, ub); 39 | quick(a, lb, k - 1); 40 | quick(a, k + 1, ub); 41 | } 42 | 43 | /* partition - partition a[i..j] */ 44 | int partition(a, i, j) int a[]; { 45 | int v, k; 46 | 47 | j++; 48 | k = i; 49 | v = a[k]; 50 | while (i < j) { 51 | i++; while (a[i] < v) i++; 52 | j--; while (a[j] > v) j--; 53 | if (i < j) exchange(&a[i], &a[j]); 54 | } 55 | exchange(&a[k], &a[j]); 56 | return j; 57 | } 58 | 59 | /* exchange - exchange *x and *y */ 60 | exchange(x, y) int *x, *y; { 61 | int t; 62 | 63 | printf("exchange(%d,%d)\n", x - xx, y - xx); 64 | t = *x; *x = *y; *y = t; 65 | } 66 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/spill.c: -------------------------------------------------------------------------------- 1 | main(){ 2 | f5(); 3 | } 4 | 5 | f(i){i=f()+f();} 6 | 7 | f2(i){i=f()+(i?f():1);} 8 | 9 | f3(int i,int *p){register r1=0,r2=0,r3=0,r4=0,r5=0,r6=0,r7=0,r8=0,r9=0,r10=0;*p++=i?f():0;} 10 | 11 | int aa[10],ab[10]; 12 | int i; 13 | f4(){register r6=0,r7=0,r8=0,r9=0,r10=0,r11=0;i=aa[i]+ab[i] && i && aa[i]-ab[i];} 14 | /* f4 causes parent to spill child on vax when odd double regs are enabled */ 15 | 16 | int j=1, k=2, m=3, n=3; 17 | //int *A, *B, x; 18 | int A[10] = {1,1,2,3,4,5,6,7,8,9}; 19 | int B[10] = {1,1,2,3,4,5,6,7,8,9}; 20 | int x=0; 21 | 22 | f5(){ 23 | x=A[k*m]*A[j*m]+B[k*n]*B[j*n]; 24 | printf("%d\n",x); 25 | x=A[k*m]*B[j*n]-B[k*n]*A[j*m]; 26 | printf("%d\n",x); 27 | } 28 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/stdio.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | extern void printf(const char *format, ...); 5 | extern void scanf(const char *format, ...); 6 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/struct.c: -------------------------------------------------------------------------------- 1 | typedef struct point { int x,y; } point; 2 | typedef struct rect { point pt1, pt2; } rect; 3 | 4 | point addpoint(point p1, point p2) { /* add two points */ 5 | p1.x += p2.x; 6 | p1.y += p2.y; 7 | return p1; 8 | } 9 | 10 | #define min(a, b) ((a) < (b) ? (a) : (b)) 11 | #define max(a, b) ((a) > (b) ? (a) : (b)) 12 | 13 | rect canonrect(rect r) { /* canonicalize rectangle coordinates */ 14 | rect temp; 15 | 16 | temp.pt1.x = min(r.pt1.x, r.pt2.x); 17 | temp.pt1.y = min(r.pt1.y, r.pt2.y); 18 | temp.pt2.x = max(r.pt1.x, r.pt2.x); 19 | temp.pt2.y = max(r.pt1.y, r.pt2.y); 20 | return temp; 21 | } 22 | 23 | point makepoint(int x, int y) { /* make a point from x and y components */ 24 | point p; 25 | 26 | p.x = x; 27 | p.y = y; 28 | return p; 29 | } 30 | 31 | rect makerect(point p1, point p2) { /* make a rectangle from two points */ 32 | rect r; 33 | 34 | r.pt1 = p1; 35 | r.pt2 = p2; 36 | return canonrect(r); 37 | } 38 | 39 | int ptinrect(point p, rect r) { /* is p in r? */ 40 | return p.x >= r.pt1.x && p.x < r.pt2.x 41 | && p.y >= r.pt1.y && p.y < r.pt2.y; 42 | } 43 | 44 | struct odd {char a[3]; } y = {'a', 'b', 0}; 45 | 46 | odd(struct odd y) { 47 | struct odd x = y; 48 | printf("%s\n", x.a); 49 | } 50 | 51 | main() { 52 | int i; 53 | point x, origin = { 0, 0 }, maxpt = { 320, 320 }; 54 | point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 }; 55 | rect screen = makerect(addpoint(maxpt, makepoint(-10, -10)), 56 | addpoint(origin, makepoint(10, 10))); 57 | 58 | for (i = 0; i < sizeof pts/sizeof pts[0]; i++) { 59 | printf("(%d,%d) is ", pts[i].x, 60 | (x = makepoint(pts[i].x, pts[i].y)).y); 61 | if (ptinrect(x, screen) == 0) 62 | printf("not "); 63 | printf("within [%d,%d; %d,%d]\n", screen.pt1.x, screen.pt1.y, 64 | screen.pt2.x, screen.pt2.y); 65 | } 66 | odd(y); 67 | return 0; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /lcc-1.3/test/regression/switch.c: -------------------------------------------------------------------------------- 1 | main() 2 | { 3 | int i; char *s; 4 | 5 | for (s = "bfnrtvx"; *s; s++) 6 | printf("%c = 0x%x\n", *s, backslash(*s)); 7 | f(); 8 | g(); 9 | h(); 10 | for (i = 0x1000; i&0x7000; i += 0x1000) 11 | big(i); 12 | limit(); 13 | return 0; 14 | } 15 | 16 | backslash(c) 17 | { 18 | switch (c) { 19 | case 'b': 20 | return '\b'; 21 | case 'f': 22 | return '\f'; 23 | case 'n': 24 | return '\n'; 25 | case 'r': 26 | return '\r'; 27 | case 't': 28 | return '\t'; 29 | case 'v': 30 | return '\v'; 31 | } 32 | return c; 33 | } 34 | 35 | f() { 36 | int i, x = 0, y; 37 | 38 | printf("f:\n"); 39 | for (i = 0; i <= 20; i++) { 40 | y = i; 41 | switch (i) { 42 | case 1: x = i; break; 43 | case 2: x = i; break; 44 | case 7: x = i; break; 45 | case 8: x = i; break; 46 | case 9: x = i; break; 47 | case 16: x = i; break; 48 | case 17: x = i; break; 49 | case 18: x = i; break; 50 | case 19: x = i; break; 51 | case 20: x = i; break; 52 | } 53 | printf("x = %d\n", x); 54 | } 55 | } 56 | 57 | g() { 58 | int i; 59 | 60 | printf("g:\n"); 61 | for (i = 1; i <= 10; i++) 62 | switch (i) { 63 | case 1: case 2: printf("1 %d\n", i); break; 64 | case 3: case 4: case 5: printf("2 %d\n", i); break; 65 | case 6: case 7: case 8: printf("3 %d\n", i); 66 | default: 67 | printf("d %d\n", i); break; 68 | case 1001: case 1002: case 1003: case 1004: 69 | printf("5 %d\n", i); break; 70 | case 3001: case 3002: case 3003: case 3004: 71 | printf("6 %d\n", i); break; 72 | } 73 | } 74 | 75 | h() 76 | { 77 | int i, n=0; 78 | 79 | printf("h:\n"); 80 | for (i = 1; i <= 500; i++) 81 | switch (i) { 82 | default: n++; continue; 83 | case 128: printf("i = %d\n", i); break; 84 | case 16: printf("i = %d\n", i); break; 85 | case 8: printf("i = %d\n", i); break; 86 | case 120: printf("i = %d\n", i); break; 87 | case 280: printf("i = %d\n", i); break; 88 | case 264: printf("i = %d\n", i); break; 89 | case 248: printf("i = %d\n", i); break; 90 | case 272: printf("i = %d\n", i); break; 91 | case 304: printf("i = %d\n", i); break; 92 | case 296: printf("i = %d\n", i); break; 93 | case 288: printf("i = %d\n", i); break; 94 | case 312: printf("i = %d\n", i); break; 95 | } 96 | printf("%d defaults\n", n); 97 | } 98 | 99 | big(x) int x; { 100 | switch(x&0x6000){ 101 | case -1: 102 | case -2: 103 | case 0x0000: 104 | printf("x = 0x%d\n", x); break; 105 | case 0x2000: 106 | printf("x = 0x%d\n", x); break; 107 | case 0x4000: 108 | printf("x = 0x%d\n", x); break; 109 | default: 110 | printf("x = 0x%d (default)\n", x); break; 111 | } 112 | } 113 | 114 | #define INT_MIN -32000 115 | #define INT_MAX 32000 116 | 117 | limit() { 118 | int i; 119 | 120 | for (i = INT_MIN; i <= INT_MIN+5; i++) 121 | switch (i) { 122 | case INT_MIN: printf("0\n"); break; 123 | case INT_MIN+1: printf("1\n"); break; 124 | case INT_MIN+2: printf("2\n"); break; 125 | case INT_MIN+3: printf("3\n"); break; 126 | case INT_MIN+4: printf("4\n"); break; 127 | default: printf("5\n"); break; 128 | } 129 | for (i = INT_MAX; i >= INT_MAX-5; i--) 130 | switch (i) { 131 | case INT_MAX: printf("0\n"); break; 132 | case INT_MAX-1: printf("1\n"); break; 133 | case INT_MAX-2: printf("2\n"); break; 134 | case INT_MAX-3: printf("3\n"); break; 135 | case INT_MAX-4: printf("4\n"); break; 136 | default: printf("5\n"); break; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /serial/C_console/lc3Terminal.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edga/lc3/c7e8222bd74923f02a80986c83197796a725136c/serial/C_console/lc3Terminal.exe -------------------------------------------------------------------------------- /serial/C_console/lc3Terminal.lnk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edga/lc3/c7e8222bd74923f02a80986c83197796a725136c/serial/C_console/lc3Terminal.lnk -------------------------------------------------------------------------------- /serial/C_console/register_lc3_filetypes.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo Creating file type and associate it with LC3 files 4 | regedit /s c:\lc3\bin\lc3_filetypes.reg 5 | REM ------ OBSOLETE: Now we use registers, because it is more flexible ------- 6 | REM assoc .obj 7 | REM assoc .obj=LC3_object 8 | REM ftype LC3_object="c:\lc3\bin\lc3Upload.cmd" "%%1" 9 | REM ftype LC3_object="c:\lc3\bin\lc3Terminal.exe" "%%1" 10 | REM 11 | REM assoc .asm=LC3_source 12 | REM assoc .c=LC3_source 13 | REM ftype LC3_source="c:\lc3\bin\lc3compile.cmd" "%%1" 14 | REM -------------------------------------------------------------------------- 15 | 16 | 17 | echo Creating "SendTo" menu item 18 | copy /y c:\lc3\bin\lc3Terminal.lnk "%USERPROFILE%\SendTo\" 19 | copy /y c:\lc3\bin\lc3Upload.lnk "%USERPROFILE%\SendTo\" 20 | 21 | echo Done 22 | pause -------------------------------------------------------------------------------- /serial/python/ProgramFileLoader.py: -------------------------------------------------------------------------------- 1 | import os 2 | from array import array 3 | 4 | class ProgramFileLoader: 5 | """Loads LC3 object file for serial programming""" 6 | 7 | class Error(Exception): 8 | def __init__(self, error, caption="Program file error"): 9 | self.caption = caption 10 | self.error = error 11 | def __str__(self): 12 | return "%s: %s" % (self.caption, self.error) 13 | 14 | def __init__(self, path): 15 | """Format of data file is: 16 | ...""" 17 | self.path = path 18 | size = os.path.getsize(path) 19 | if size < 6 or size % 2: 20 | raise self.Error("Size of selected file has to be multiple of 2 and file must containt at least 3 words", "File size error") 21 | size = size/2 22 | 23 | fdata = open(path, "rb") 24 | data = array('H') 25 | data.fromfile(fdata, size) 26 | fdata.close() 27 | if "foreign_endian": 28 | data.byteswap() 29 | 30 | if data[0] != (size-2): 31 | raise self.Error("Count field (%d) doesn't match file size (%d)" % (data[0], size-2), "File size error") 32 | 33 | self.chunks = [] 34 | self.chunks.append( (data[0], data[1], data[2:]) ) 35 | 36 | -------------------------------------------------------------------------------- /serial/python/hexDump.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import os 3 | from array import array 4 | 5 | 6 | def dumpLineVHDL(offset, line): 7 | print ('X"%04x", X"%04x", X"%04x", X"%04x", X"%04x", X"%04x", X"%04x", X"%04x",' % tuple(line)) +\ 8 | '-- addr %d - %d' % (offset, offset+7) 9 | 10 | def dumpLineHex(offset, line): 11 | print ("%04x: " % (offset)) + \ 12 | "%04x %04x %04x %04x %04x %04x %04x %04x" % tuple(line) 13 | 14 | def dumpFile(path): 15 | size = os.path.getsize(path)/2 16 | fdata = open(path, "rb") 17 | data = array('H') 18 | data.fromfile(fdata, size) 19 | fdata.close() 20 | if "foreign_endian": 21 | data.byteswap() 22 | # use first word as offset 23 | offset = data[0] 24 | 25 | if size % 8: 26 | for i in range(9-(size % 8)): 27 | data.append(0) 28 | size = (size+7)/8; 29 | 30 | ll = l = [] 31 | loffset = 0 32 | for i in range(size): 33 | s = (i*8) + 1 34 | l = list(data[s:s+8]) 35 | #print "%i: %s" % (i,l) 36 | if l != ll: 37 | if loffset < offset: 38 | print "*" 39 | dumpLine(offset, l) 40 | ll = l 41 | loffset = offset+8 42 | offset += 8 43 | #dumpLineVHDL(offset, l) 44 | dumpLineHex(offset, l) 45 | 46 | 47 | 48 | if __name__ == '__main__': 49 | import sys 50 | 51 | if len(sys.argv) != 2: 52 | print("Usage:\n"+ 53 | " %s LC3_OBJ_FILE\n") 54 | else: 55 | dumpFile(sys.argv[1]); 56 | 57 | -------------------------------------------------------------------------------- /serial/python/testing/cat.asm: -------------------------------------------------------------------------------- 1 | ;;; Test of software serial comunication. 2 | ;;; 3 | ;;; The data is read/written byte by byte 4 | ;;; 5 | 6 | .ORIG x3000 7 | 8 | LD R2, OS_SSR ; store OS_SSR and keep it there while in this proc 9 | 10 | Again: 11 | ; read the byte 12 | LDR R0, R2, 0 13 | BRzp -2 ; poll until data available 14 | LDR R0, R2, 2 15 | 16 | ; write the byte 17 | LDR R1, R2, 4 18 | BRzp -2 ; poll until transmission buffers ready 19 | STR R0, R2, 6 20 | 21 | BR Again 22 | 23 | OS_SSR .FILL xFE00 24 | 25 | SSEGS .FILL xFE10 26 | SSEGD .FILL xFE12 27 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 28 | ; Write R0 onto 7 segment display 29 | ;------------------------------- 30 | Write7seg 31 | LDI R1,SSEGS ; wait for the display to be ready 32 | BRzp -2 33 | STI R0,SSEGD ; write the character and return 34 | 35 | RET 36 | 37 | 38 | 39 | 40 | .END 41 | 42 | 43 | -------------------------------------------------------------------------------- /serial/python/testing/cat2.asm: -------------------------------------------------------------------------------- 1 | ;;; Test of software serial comunication. 2 | ;;; 3 | ;;; LoadWordFromSerial is function used in boot loader (it uses no extension instructions) 4 | ;;; WriteWordToSerial uses shift instruction extension 5 | 6 | 7 | .ORIG x3000 8 | 9 | Again: 10 | jsr LoadWordFromSerial 11 | jsr WriteWordToSerial 12 | BR Again 13 | 14 | ;;;;;;;;;;;;;;;;;;;; 15 | ; LoadWordFromSerial 16 | ;------------------- 17 | ; IN: -- 18 | ; OUT: R0 holds word just read 19 | ; KILL: R1, R2 20 | ;------------------- 21 | ; proc_size:14 22 | ;LOCALS: 23 | ; Used to detect shift has been performed 7 times 24 | Bit9 .FILL x0100 25 | 26 | LoadWordFromSerial 27 | LD R2, OS_SSR ; store OS_SSR and keep it there while in this proc 28 | 29 | ; read the First byte (most significant in LC3) 30 | LDR R0, R2, 0 31 | BRzp -2 ; poll until next word available 32 | LDR R0, R2, 2 33 | 34 | ; read the Second byte 35 | LDR R1, R2, 0 36 | BRzp -2 ; poll until next word available 37 | LDR R1, R2, 2 38 | 39 | ; shift: R0 := R0 << 8 40 | LD R2, Bit9 ; load constant 41 | ADD R0, R2, R0 ; prepare 42 | ; shift R0 8 times 43 | ADD R0, R0, R0 ; R0 := 2*R0 44 | BRzp -2 ; 7 times 45 | ADD R0, R0, R0 ; once more 46 | 47 | 48 | ; form result (concat bytes) 49 | ADD R0, R1, R0 50 | ret 51 | 52 | OS_SSR .FILL xFe00 53 | OS_SSR0 .FILL xFe04 54 | 55 | MASK .FILL x00FF 56 | 57 | WriteWordToSerial 58 | LD R2, OS_SSR0 ; store OS_SSR and keep it there while in this proc 59 | 60 | SRA R1, R0, 8 61 | 62 | ; write the First byte (most significant in LC3) 63 | LDR R3, R2, 0 64 | BRzp -2 ; poll until next word available 65 | STR R1, R2, 2 66 | 67 | ; write the Second byte 68 | LDR R3, R2, 0 69 | BRzp -2 ; poll until next word available 70 | STR R0, R2, 2 71 | 72 | ret 73 | 74 | SSEGS .FILL xFE10 75 | SSEGD .FILL xFE12 76 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 77 | ; Write R0 onto 7 segment display 78 | ;------------------------------- 79 | Write7seg 80 | LDI R1,SSEGS ; wait for the display to be ready 81 | BRzp -2 82 | STI R0,SSEGD ; write the character and return 83 | 84 | RET 85 | 86 | 87 | 88 | 89 | .END 90 | 91 | 92 | -------------------------------------------------------------------------------- /serial/python/testing/cmds.txt: -------------------------------------------------------------------------------- 1 | export ~/.bashrcsrouce ~/.bashrc 2 | time python 'c:\lc3\bin\serial_cat.py' -O cat.ser -s < /dev/null ; time python 'c:\lc3\bin\serial_cat.py' d.txt out.txt ; diff d.txt out.txt 3 | --------------------------------------------------------------------------------