├── manual ├── viking_manual_pt.pdf ├── viking_asm.sty ├── viking_manual_pt.out ├── viking_manual_pt.toc ├── viking_manual_pt.aux └── viking_manual_pt.log ├── README.md ├── examples ├── hello_world2.asm ├── hello_world.asm ├── ninetoone.asm ├── ninetoone.out ├── fibonacci.asm ├── mult.asm ├── div.asm ├── mulsi3.asm ├── ninetoone_debug.out ├── hello.asm ├── udivmodsi4.asm ├── divsi3.asm ├── modsi3.asm ├── function_call.asm ├── bubble_sort.asm ├── bubble_sort2.asm └── bubble_sort3.asm ├── simulator ├── run16.py ├── run32.py ├── vikingsim.py └── vikingsim3.py └── assembler ├── assemble16.py └── assemble32.py /manual/viking_manual_pt.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sjohann81/viking/HEAD/manual/viking_manual_pt.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Viking ISA 2 | 3 | This is an experimental ISA for a very simple load/store architecture. 4 | 5 | -------------------------------------------------------------------------------- /examples/hello_world2.asm: -------------------------------------------------------------------------------- 1 | main 2 | ldi r1,0xf000 3 | ldi r2,str 4 | loop 5 | ldb r3,r2 6 | stw r3,r1 7 | add r2,1 8 | bnz r3,loop 9 | hcf 10 | 11 | str "hello world!" 12 | -------------------------------------------------------------------------------- /examples/hello_world.asm: -------------------------------------------------------------------------------- 1 | main 2 | ldw sr,writec 3 | ldi r4,str 4 | ldi r3,loop 5 | loop 6 | ldb r2,r4 7 | stw r2,sr 8 | add r4,1 9 | bnz r2,r3 10 | hcf 11 | 12 | writec 0xf000 13 | str "hello world!" 14 | -------------------------------------------------------------------------------- /examples/ninetoone.asm: -------------------------------------------------------------------------------- 1 | main 2 | ldi r1,9 3 | ldi r2,32 4 | loop 5 | ldw sr,writei 6 | stw r1,sr 7 | ldw sr,writec 8 | stw r2,sr 9 | sub r1,1 10 | bnz r1,loop 11 | hcf 12 | 13 | writec 0xf000 14 | writei 0xf002 15 | -------------------------------------------------------------------------------- /examples/ninetoone.out: -------------------------------------------------------------------------------- 1 | 0000 9900 2 | 0002 9909 3 | 0004 9a00 4 | 0006 9a20 5 | 0008 9800 6 | 000a 9824 7 | 000c 4502 8 | 000e 5036 9 | 0010 9800 10 | 0012 9822 11 | 0014 4502 12 | 0016 5056 13 | 0018 6901 14 | 001a 9800 15 | 001c 9808 16 | 001e b020 17 | 0020 0003 18 | 0022 f000 19 | 0024 f002 20 | -------------------------------------------------------------------------------- /examples/fibonacci.asm: -------------------------------------------------------------------------------- 1 | main 2 | xor r1,r1,r1 3 | ldi r2,1 4 | ldi r4,21 5 | fib_loop 6 | ldw sr,writei 7 | stw r1,sr 8 | ldw sr,writec 9 | ldi r3,32 10 | stw r3,sr 11 | 12 | add r3,r1,r2 13 | and r1,r2,r2 14 | and r2,r3,r3 15 | 16 | sub r4,1 17 | bnz r4,fib_loop 18 | hcf 19 | 20 | writec 0xf000 21 | writei 0xf002 22 | -------------------------------------------------------------------------------- /examples/mult.asm: -------------------------------------------------------------------------------- 1 | main 2 | ldw r2,readi 3 | ldw r2,r2 4 | ldw r3,readi 5 | ldw r3,r3 6 | 7 | sub sp,2 8 | stw r2,sp 9 | sub sp,2 10 | stw r3,sp 11 | sub sp,2 12 | stw lr,sp 13 | ldi lr,ret_addr 14 | ldi sr,mulsi3 15 | bnz r7,sr 16 | ret_addr 17 | ldw lr,sp 18 | add sp,6 19 | 20 | and r1,sr,sr 21 | ldw sr,writei 22 | stw r1,sr 23 | hcf 24 | 25 | writei 0xf002 26 | readi 0xf006 27 | -------------------------------------------------------------------------------- /examples/div.asm: -------------------------------------------------------------------------------- 1 | main 2 | ldw r2,readi 3 | ldw r2,r0,r2 4 | ldw r3,readi 5 | ldw r3,r0,r3 6 | 7 | sub sp,2 8 | stw r0,r2,sp 9 | sub sp,2 10 | stw r0,r3,sp 11 | sub sp,2 12 | stw r0,lr,sp 13 | ldi lr,ret_addr 14 | ldi sr,divsi3 15 | bnz r0,r7,sr 16 | ret_addr 17 | ldw lr,r0,sp 18 | add sp,6 19 | 20 | and r1,sr,sr 21 | ldw sr,writei 22 | stw r0,r1,sr 23 | hcf 24 | 25 | 26 | writei 0xf002 27 | readi 0xf006 28 | -------------------------------------------------------------------------------- /examples/mulsi3.asm: -------------------------------------------------------------------------------- 1 | mulsi3 2 | sub sp,2 3 | stw r1,sp 4 | sub sp,2 5 | stw r2,sp 6 | sub sp,2 7 | stw r3,sp 8 | 9 | and r3,sp,sp 10 | add r3,10 11 | ldw r2,r3 12 | sub r3,2 13 | ldw r3,r3 14 | 15 | xor r1,r1,r1 16 | bez r3,14 17 | and sr,r3,r3 18 | and sr,1 19 | bez sr,2 20 | add r1,r1,r2 21 | lsl r2,r2 22 | lsr r3,r3 23 | bnz r7,-16 24 | 25 | and sr,r1,r1 26 | add sp,2 27 | ldw r3,sp 28 | add sp,2 29 | ldw r2,sp 30 | add sp,2 31 | ldw r1,sp 32 | 33 | bnz r7,lr 34 | -------------------------------------------------------------------------------- /examples/ninetoone_debug.out: -------------------------------------------------------------------------------- 1 | main 2 | 0000 9900 ldc0 r1,9 3 | 0002 9909 ldc1 r1,9 4 | 0004 9a00 ldc0 r2,32 5 | 0006 9a20 ldc1 r2,32 6 | loop 7 | 0008 9800 ldc0 at,writei 8 | 000a 9824 ldc1 at,writei 9 | 000c 4502 ldw sr,r0,at 10 | 000e 5036 stw r0,r1,sr 11 | 0010 9800 ldc0 at,writec 12 | 0012 9822 ldc1 at,writec 13 | 0014 4502 ldw sr,r0,at 14 | 0016 5056 stw r0,r2,sr 15 | 0018 6901 sub r1,1 16 | 001a 9800 ldc0 at,loop 17 | 001c 9808 ldc1 at,loop 18 | 001e b020 bnz r0,r1,at 19 | 0020 0003 hcf r0,r0,r0 20 | 21 | 0022 f000 writec 0xf000 22 | 0024 f002 writei 0xf002 23 | -------------------------------------------------------------------------------- /examples/hello.asm: -------------------------------------------------------------------------------- 1 | main 2 | 3 | ldi r2,ask 4 | ldi lr,retask 5 | bnz sp,print 6 | retask 7 | ldi r2,name 8 | ldi lr,retget 9 | bnz sp,getname 10 | retget 11 | ldi r2,str 12 | 13 | ldi r2,str 14 | ldi lr,retstr 15 | bnz sp,print 16 | retstr 17 | ldi r2,name 18 | ldi lr,retstr2 19 | bnz sp,print 20 | retstr2 21 | hcf 22 | 23 | print 24 | ldb r3,r2 25 | stw r3,0xf000 26 | add r2,1 27 | bnz r3,print 28 | bnz sp,lr 29 | 30 | getname 31 | ldw r3,0xf004 32 | stb r3,r2 33 | add r2,1 34 | bnz r3,getname 35 | bnz sp,lr 36 | 37 | str "\nhello " 38 | ask "enter your name: " 39 | name " " 40 | 41 | 42 | -------------------------------------------------------------------------------- /examples/udivmodsi4.asm: -------------------------------------------------------------------------------- 1 | udivmodsi4 2 | sub sp,2 3 | stw r1,sp 4 | sub sp,2 5 | stw r2,sp 6 | sub sp,2 7 | stw r3,sp 8 | sub sp,2 9 | stw r4,sp 10 | 11 | ldr r3,1 12 | xor r4,r4,r4 13 | 14 | and r2,sp,sp 15 | add r2,14 16 | ldw r1,r2 17 | sub r2,2 18 | ldw r2,r2 19 | 20 | sltu sr,r2,r1 21 | bez sr,8 22 | bez r3,6 23 | lsl r2,r2 24 | lsl r3,r3 25 | bnz r7,-12 26 | sltu sr,r1,r2 27 | bnz sr,4 28 | sub r1,r1,r2 29 | add r4,r4,r3 30 | lsr r3,r3 31 | lsr r2,r2 32 | bnz r3,-14 33 | 34 | and sr,sp,sp 35 | add sr,10 36 | ldw sr,sr 37 | bez sr,4 38 | and sr,r1,r1 39 | bez sr,2 40 | and sr,r4,r4 41 | 42 | ldw r4,sp 43 | add sp,2 44 | ldw r3,sp 45 | add sp,2 46 | ldw r2,sp 47 | add sp,2 48 | ldw r1,sp 49 | add sp,2 50 | bnz r7,lr 51 | -------------------------------------------------------------------------------- /examples/divsi3.asm: -------------------------------------------------------------------------------- 1 | divsi3 2 | sub sp,2 3 | stw r1,sp 4 | sub sp,2 5 | stw r2,sp 6 | sub sp,2 7 | stw r3,sp 8 | 9 | and r2,sp,sp 10 | add r2,10 11 | ldw r1,r2 12 | sub r2,2 13 | ldw r2,r2 14 | xor r3,r3,r3 15 | 16 | xor at,at,at 17 | slt sr,r1,at 18 | bez sr,4 19 | sub r1,at,r1 20 | or r3,1 21 | slt sr,r2,at 22 | bez sr,4 23 | sub r2,at,r2 24 | xor r3,1 25 | 26 | sub sp,2 27 | stw r1,sp 28 | sub sp,2 29 | stw r2,sp 30 | sub sp,2 31 | ldr sr,0 32 | stw sr,sp 33 | sub sp,2 34 | stw lr,sp 35 | ldi lr,ret_divsi3 36 | ldi sr,udivmodsi4 37 | bnz r7,sr 38 | ret_divsi3 39 | ldw lr,sp 40 | add sp,8 41 | bez r3,4 42 | xor at,at,at 43 | sub sr,at,sr 44 | 45 | add sp,2 46 | ldw r3,sp 47 | add sp,2 48 | ldw r2,sp 49 | add sp,2 50 | ldw r1,sp 51 | 52 | bnz r7,lr 53 | -------------------------------------------------------------------------------- /examples/modsi3.asm: -------------------------------------------------------------------------------- 1 | modsi3 2 | sub sp,2 3 | stw r1,sp 4 | sub sp,2 5 | stw r2,sp 6 | sub sp,2 7 | stw r3,sp 8 | 9 | and r2,sp,sp 10 | add r2,10 11 | ldw r1,r2 12 | sub r2,2 13 | ldw r2,r2 14 | xor r3,r3,r3 15 | 16 | xor at,at,at 17 | slt sr,r1,at 18 | bez sr,4 19 | sub r1,at,r1 20 | or r3,1 21 | slt sr,r2,at 22 | bez sr,4 23 | sub r2,at,r2 24 | xor r3,1 25 | 26 | sub sp,2 27 | stw r1,sp 28 | sub sp,2 29 | stw r2,sp 30 | sub sp,2 31 | ldr sr,1 32 | stw sr,sp 33 | sub sp,2 34 | stw lr,sp 35 | ldi lr,ret_modsi3 36 | ldi sr,udivmodsi4 37 | bnz r7,sr 38 | ret_modsi3 39 | ldw lr,sp 40 | add sp,8 41 | bez r3,4 42 | xor at,at,at 43 | sub sr,at,sr 44 | 45 | add sp,2 46 | ldw r3,sp 47 | add sp,2 48 | ldw r2,sp 49 | add sp,2 50 | ldw r1,sp 51 | 52 | bnz r7,lr 53 | -------------------------------------------------------------------------------- /examples/function_call.asm: -------------------------------------------------------------------------------- 1 | main 2 | ldi r1,str1 3 | sub sp,2 4 | stw r1,sp 5 | sub sp,2 6 | stw lr,sp 7 | ldi lr,ret_print1 8 | ldi sr,print_str 9 | bnz r7,sr 10 | ret_print1 11 | ldw lr,sp 12 | add sp,4 13 | 14 | ldi r1,str2 15 | sub sp,2 16 | stw r1,sp 17 | sub sp,2 18 | stw lr,sp 19 | ldi lr,ret_print2 20 | ldi sr,print_str 21 | bnz r7,sr 22 | ret_print2 23 | ldw lr,sp 24 | add sp,4 25 | 26 | hcf 27 | 28 | print_str 29 | ldw sr,writec 30 | sub sp,2 31 | stw r1,sp 32 | sub sp,2 33 | stw r2,sp 34 | 35 | and r1,sp,sp 36 | add r1,6 37 | ldw r1,r1 38 | print_loop 39 | ldb r2,r1 40 | stw r2,sr 41 | add r1,1 42 | bnz r2,-8 43 | 44 | ldw r2,sp 45 | add sp,2 46 | ldw r1,sp 47 | add sp,2 48 | bnz r7,lr 49 | 50 | 51 | writec 0xf000 52 | str1 "this is the first call\n" 53 | str2 "and this is the second!\n" 54 | -------------------------------------------------------------------------------- /manual/viking_asm.sty: -------------------------------------------------------------------------------- 1 | \ProvidesPackage{viking_asm} 2 | 3 | \RequirePackage{listings} 4 | 5 | \lstdefinelanguage[viking]{Assembler}{% 6 | % so listings can detect directives and register names 7 | alsoletter={.\$}, 8 | % strings, characters, and comments 9 | morestring=[b]", 10 | morestring=[b]', 11 | morecomment=[l]\;, 12 | % instructions 13 | morekeywords={[1]add, sub, and, or, xor, slt, sltu, ldr, ldc, % 14 | lsr, asr, ldb, stb, ldw, stw, bez, bnz, hcf, ldc0, ldc1, % 15 | nop, not, neg, lsl, ldi, seq, sne, sge, sgeu, beq, bne, blt, % 16 | bge, bltu, bgeu, lsrm, asrm, lslm, sgt, sle, sgtu, sleu, bgt, % 17 | ble, bgtu, bleu, mul, div, rem, mov, ldbu, jmp, jal, jmpr, % 18 | jalr, ret}, 19 | % assembler directives 20 | morekeywords={[2].align,.ascii,.asciiz,.byte,.data,.double,.extern,% 21 | .float,.globl,.half,.kdata,.ktext,.set,.space,.text,.word}, 22 | % register names 23 | morekeywords={[3]r0, r1, r2, r3, r4, r5, r6, r7, at, sr, lr, sp}, 24 | }[strings,comments,keywords] 25 | -------------------------------------------------------------------------------- /examples/bubble_sort.asm: -------------------------------------------------------------------------------- 1 | main 2 | ldi lr,ret_print1 3 | bnz r7,print_numbers 4 | ret_print1 5 | ldi lr,ret_sort 6 | bnz r7,sort 7 | ret_sort 8 | ldi lr,ret_print2 9 | bnz r7,print_numbers 10 | ret_print2 11 | hcf 12 | 13 | print_numbers 14 | ldi r1,0 15 | ldw r2,N 16 | ldi r3,numbers 17 | loop_print 18 | ldw r4,r3 19 | stw r4,0xf002 20 | ldi r4,32 21 | stw r4,0xf000 22 | add r1,1 23 | add r3,2 24 | sub r5,r1,r2 25 | bnz r5,loop_print 26 | ldi r4,10 27 | stw r4,0xf000 28 | bnz r7,lr 29 | 30 | sort 31 | ldw r1,i 32 | loop_i 33 | ldw r3,N 34 | sub r3,1 35 | slt r3,r1,r3 36 | bez r3,end_i 37 | 38 | xor r0,r0,r0 39 | add r2,r1,r0 40 | add r2,1 41 | stw r2,j 42 | loop_j 43 | ldw r1,i 44 | ldw r3,N 45 | slt r3,r2,r3 46 | bez r3,end_j 47 | 48 | ldi r4,numbers 49 | add r3,r4,r1 50 | add r3,r3,r1 51 | ldw r1,r3 52 | add r4,r4,r2 53 | add r4,r4,r2 54 | ldw r2,r4 55 | 56 | slt r1,r2,r1 57 | bez r1,skip 58 | 59 | ldw r1,r3 60 | stw r1,r4 61 | stw r2,r3 62 | skip 63 | ldw r2,j 64 | add r2,1 65 | stw r2,j 66 | bnz r7,loop_j 67 | end_j 68 | ldw r1,i 69 | add r1,1 70 | stw r1,i 71 | bnz r7,loop_i 72 | end_i 73 | bnz r7,lr 74 | 75 | i 0 76 | j 0 77 | N 10 78 | numbers -5 8 -22 123 77 -1 99 -33 10 12 79 | 80 | -------------------------------------------------------------------------------- /examples/bubble_sort2.asm: -------------------------------------------------------------------------------- 1 | main 2 | ldi lr,ret_print1 3 | bnz r7,print_numbers 4 | ret_print1 5 | ldi lr,ret_sort 6 | bnz r7,sort 7 | ret_sort 8 | ldi lr,ret_print2 9 | bnz r7,print_numbers 10 | ret_print2 11 | hcf 12 | 13 | print_numbers 14 | ldi r1,0 15 | ldw r2,N 16 | ldi r3,numbers 17 | loop_print 18 | ldw r4,r3 19 | stw r4,0xf002 20 | ldi r4,32 21 | stw r4,0xf000 22 | add r1,1 23 | add r3,2 24 | sub r5,r1,r2 25 | bnz r5,loop_print 26 | ldi r4,10 27 | stw r4,0xf000 28 | bnz r7,lr 29 | 30 | sort 31 | ldi r1,0 32 | loop_i 33 | ldw r3,N 34 | sub r3,1 35 | slt r3,r1,r3 36 | bez r3,end_i 37 | 38 | xor r0,r0,r0 39 | add r2,r1,r0 40 | add r2,1 41 | loop_j 42 | ldw r3,N 43 | slt r3,r2,r3 44 | bez r3,end_j 45 | 46 | ldi r5,numbers 47 | add r3,r5,r1 48 | add r3,r3,r1 49 | ldw r3,r3 50 | add r4,r5,r2 51 | add r4,r4,r2 52 | ldw r4,r4 53 | 54 | slt r5,r4,r3 55 | bez r5,skip 56 | 57 | xor r0,r0,r0 58 | add r0,r3,r0 59 | 60 | ldi r5,numbers 61 | add r3,r5,r1 62 | add r3,r3,r1 63 | stw r4,r3 64 | 65 | add r4,r5,r2 66 | add r4,r4,r2 67 | stw r0,r4 68 | skip 69 | add r2,1 70 | bnz r7,loop_j 71 | end_j 72 | add r1,1 73 | bnz r7,loop_i 74 | end_i 75 | 76 | bnz r7,lr 77 | 78 | N 10 79 | numbers -5 8 -22 123 77 -1 99 -33 10 12 80 | 81 | -------------------------------------------------------------------------------- /examples/bubble_sort3.asm: -------------------------------------------------------------------------------- 1 | main 2 | ldi sr,array1 3 | sub sp,2 4 | stw sr,sp 5 | ldw sr,array1_sz 6 | lsl sr,sr 7 | sub sp,2 8 | stw sr,sp 9 | sub sp,2 10 | stw lr,sp 11 | ldi lr,ret_sort1 12 | ldi sr,sort 13 | bnz r7,sr 14 | ret_sort1 15 | ldw lr,sp 16 | add sp,4 17 | 18 | ldi r1,array1 19 | ldw r2,array1_sz 20 | print_array1 21 | ldw r3,r1 22 | ldw r4,writei 23 | stw r3,r4 24 | ldi r3,32 25 | ldw r4,writec 26 | stw r3,r4 27 | add r1,2 28 | sub r2,1 29 | bnz r2,print_array1 30 | ldi r3,10 31 | stw r3,r4 32 | 33 | ldi sr,array2 34 | sub sp,2 35 | stw sr,sp 36 | ldw sr,array2_sz 37 | lsl sr,sr 38 | sub sp,2 39 | stw sr,sp 40 | sub sp,2 41 | stw lr,sp 42 | ldi lr,ret_sort2 43 | ldi sr,sort 44 | bnz r7,sr 45 | ret_sort2 46 | ldw lr,sp 47 | add sp,4 48 | 49 | ldi r1,array2 50 | ldw r2,array2_sz 51 | print_array2 52 | ldw r3,r1 53 | ldw r4,writei 54 | stw r3,r4 55 | ldi r3,32 56 | ldw r4,writec 57 | stw r3,r4 58 | add r1,2 59 | sub r2,1 60 | bnz r2,print_array2 61 | ldi r3,10 62 | stw r3,r4 63 | 64 | hcf 65 | 66 | sort 67 | sub sp,2 68 | stw r1,sp 69 | sub sp,2 70 | stw r2,sp 71 | sub sp,2 72 | stw r3,sp 73 | sub sp,2 74 | stw r4,sp 75 | xor r1,r1,r1 76 | beg_loop_i 77 | and r4,sp,sp 78 | add r4,10 79 | ldw r4,r4 80 | sub r4,2 81 | slt r4,r4,r1 82 | bnz r4,end_loop_i 83 | and r2,r1,r1 84 | add r2,2 85 | beg_loop_j 86 | and r4,sp,sp 87 | add r4,10 88 | ldw r4,r4 89 | sub r4,2 90 | slt r4,r4,r2 91 | bnz r4,end_loop_j 92 | and sr,sp,sp 93 | add sr,12 94 | ldw r3,sr 95 | add r3,r3,r1 96 | ldw r3,r3 97 | ldw r4,sr 98 | add r4,r4,r2 99 | ldw r4,r4 100 | sub sp,2 101 | stw r3,sp 102 | slt r3,r3,r4 103 | bnz r3,no_swap 104 | and sr,sp,sp 105 | add sr,14 106 | ldw r3,sr 107 | add r3,r3,r1 108 | stw r4,r3 109 | ldw r4,sr 110 | add r4,r4,r2 111 | ldw r3,sp 112 | stw r3,r4 113 | no_swap 114 | add sp,2 115 | add r2,2 116 | bnz r7,beg_loop_j 117 | end_loop_j 118 | add r1,2 119 | bnz r7,beg_loop_i 120 | end_loop_i 121 | ldw r4,sp 122 | add sp,2 123 | ldw r3,sp 124 | add sp,2 125 | ldw r2,sp 126 | add sp,2 127 | ldw r1,sp 128 | add sp,2 129 | bnz r7,lr 130 | 131 | writec 0xf000 132 | writei 0xf002 133 | array1 -5 3 23 -64 34 3 65 7 10 -4 10 134 | array1_sz 11 135 | array2 13121 6686 12335 6172 -13028 -4379 -3953 16045 -7613 -12561 -7188 -7141 -6281 8039 -12760 -2041 6212 -146 -3087 9151 -14015 7819 6590 -13079 549 13277 9033 -8114 -3338 -5071 136 | array2_sz 30 137 | -------------------------------------------------------------------------------- /manual/viking_manual_pt.out: -------------------------------------------------------------------------------- 1 | \BOOKMARK [0][-]{chapter.1}{A arquitetura Viking}{}% 1 2 | \BOOKMARK [1][-]{section.1.1}{Registradores}{chapter.1}% 2 3 | \BOOKMARK [1][-]{section.1.2}{Formatos de instru\347\343o}{chapter.1}% 3 4 | \BOOKMARK [2][-]{subsection.1.2.1}{Instru\347\365es tipo R}{section.1.2}% 4 5 | \BOOKMARK [2][-]{subsection.1.2.2}{Instru\347\365es tipo I}{section.1.2}% 5 6 | \BOOKMARK [1][-]{section.1.3}{Modos de endere\347amento}{chapter.1}% 6 7 | \BOOKMARK [1][-]{section.1.4}{Conjunto de instru\347\365es}{chapter.1}% 7 8 | \BOOKMARK [2][-]{subsection.1.4.1}{Computa\347\343o}{section.1.4}% 8 9 | \BOOKMARK [2][-]{subsection.1.4.2}{Deslocamento e rota\347\343o}{section.1.4}% 9 10 | \BOOKMARK [2][-]{subsection.1.4.3}{Carga e armazenamento}{section.1.4}% 10 11 | \BOOKMARK [2][-]{subsection.1.4.4}{Desvios condicionais}{section.1.4}% 11 12 | \BOOKMARK [1][-]{section.1.5}{Detalhes sobre a codifica\347\343o de instru\347\365es}{chapter.1}% 12 13 | \BOOKMARK [1][-]{section.1.6}{Caracter\355sticas \372nicas}{chapter.1}% 13 14 | \BOOKMARK [2][-]{subsection.1.6.1}{Carga de constantes}{section.1.6}% 14 15 | \BOOKMARK [2][-]{subsection.1.6.2}{Extens\343o de sinal}{section.1.6}% 15 16 | \BOOKMARK [2][-]{subsection.1.6.3}{Desvios condicionais}{section.1.6}% 16 17 | \BOOKMARK [2][-]{subsection.1.6.4}{Soma e subtra\347\343o de m\372ltipla precis\343o}{section.1.6}% 17 18 | \BOOKMARK [2][-]{subsection.1.6.5}{Deslocamento de m\372ltipla precis\343o}{section.1.6}% 18 19 | \BOOKMARK [2][-]{subsection.1.6.6}{Compara\347\365es de m\372ltipla precis\343o}{section.1.6}% 19 20 | \BOOKMARK [2][-]{subsection.1.6.7}{Outras opera\347\365es}{section.1.6}% 20 21 | \BOOKMARK [1][-]{section.1.7}{Tipos de dados}{chapter.1}% 21 22 | \BOOKMARK [0][-]{chapter.2}{S\355ntese de pseudo opera\347\365es}{}% 22 23 | \BOOKMARK [1][-]{section.2.1}{Pseudo opera\347\365es b\341sicas}{chapter.2}% 23 24 | \BOOKMARK [1][-]{section.2.2}{Opera\347\365es de deslocamento}{chapter.2}% 24 25 | \BOOKMARK [1][-]{section.2.3}{Pseudo opera\347\365es n\343o suportadas pelo montador}{chapter.2}% 25 26 | \BOOKMARK [2][-]{subsection.2.3.1}{Testes, sele\347\343o e desvios \(condicionais\)}{section.2.3}% 26 27 | \BOOKMARK [2][-]{subsection.2.3.2}{Opera\347\365es condicionais equivalentes}{section.2.3}% 27 28 | \BOOKMARK [2][-]{subsection.2.3.3}{Desvios incondicionais}{section.2.3}% 28 29 | \BOOKMARK [2][-]{subsection.2.3.4}{Opera\347\365es aritm\351ticas adicionais}{section.2.3}% 29 30 | \BOOKMARK [0][-]{chapter.3}{Programando com o processador Viking}{}% 30 31 | \BOOKMARK [1][-]{section.3.1}{Controle de fluxo do programa}{chapter.3}% 31 32 | \BOOKMARK [2][-]{subsection.3.1.1}{Sele\347\343o}{section.3.1}% 32 33 | \BOOKMARK [2][-]{subsection.3.1.2}{Repeti\347\343o}{section.3.1}% 33 34 | \BOOKMARK [1][-]{section.3.2}{Acesso \340 mem\363ria - vari\341veis}{chapter.3}% 34 35 | \BOOKMARK [1][-]{section.3.3}{Acesso \340 mem\363ria - vetores}{chapter.3}% 35 36 | \BOOKMARK [1][-]{section.3.4}{Chamadas de fun\347\343o e conven\347\365es de chamada}{chapter.3}% 36 37 | \BOOKMARK [2][-]{subsection.3.4.1}{Pilha}{section.3.4}% 37 38 | \BOOKMARK [2][-]{subsection.3.4.2}{Registradores}{section.3.4}% 38 39 | \BOOKMARK [2][-]{subsection.3.4.3}{Chamada e retorno de fun\347\365es}{section.3.4}% 39 40 | \BOOKMARK [0][-]{chapter.4}{Montagem de c\363digo e simula\347\343o}{}% 40 41 | \BOOKMARK [1][-]{section.4.1}{Montador}{chapter.4}% 41 42 | \BOOKMARK [2][-]{subsection.4.1.1}{Formato da linguagem de montagem}{section.4.1}% 42 43 | \BOOKMARK [2][-]{subsection.4.1.2}{Sintaxe de linha de comando}{section.4.1}% 43 44 | \BOOKMARK [1][-]{section.4.2}{Simulador}{chapter.4}% 44 45 | \BOOKMARK [2][-]{subsection.4.2.1}{Mapa de mem\363ria}{section.4.2}% 45 46 | \BOOKMARK [2][-]{subsection.4.2.2}{Sintaxe de linha de comando}{section.4.2}% 46 47 | \BOOKMARK [0][-]{appendix.A}{Exemplos}{}% 47 48 | \BOOKMARK [0][-]{appendix.B}{Rotinas mulsi3, divsi3, modsi3 e udivmodsi4}{}% 48 49 | -------------------------------------------------------------------------------- /manual/viking_manual_pt.toc: -------------------------------------------------------------------------------- 1 | \select@language {brazilian} 2 | \contentsline {chapter}{\numberline {1}A arquitetura Viking}{2}{chapter.1} 3 | \contentsline {section}{\numberline {1.1}Registradores}{3}{section.1.1} 4 | \contentsline {section}{\numberline {1.2}Formatos de instru\IeC {\c c}\IeC {\~a}o}{3}{section.1.2} 5 | \contentsline {subsection}{\numberline {1.2.1}Instru\IeC {\c c}\IeC {\~o}es tipo R}{3}{subsection.1.2.1} 6 | \contentsline {subsection}{\numberline {1.2.2}Instru\IeC {\c c}\IeC {\~o}es tipo I}{4}{subsection.1.2.2} 7 | \contentsline {section}{\numberline {1.3}Modos de endere\IeC {\c c}amento}{5}{section.1.3} 8 | \contentsline {section}{\numberline {1.4}Conjunto de instru\IeC {\c c}\IeC {\~o}es}{6}{section.1.4} 9 | \contentsline {subsection}{\numberline {1.4.1}Computa\IeC {\c c}\IeC {\~a}o}{6}{subsection.1.4.1} 10 | \contentsline {subsubsection}{AND - bitwise logical product}{6}{section*.1} 11 | \contentsline {subsubsection}{OR - bitwise logical sum}{6}{section*.2} 12 | \contentsline {subsubsection}{XOR - bitwise logical difference}{7}{section*.3} 13 | \contentsline {subsubsection}{SLT - set if less than}{7}{section*.4} 14 | \contentsline {subsubsection}{SLTU - set if less than (unsigned)}{8}{section*.5} 15 | \contentsline {subsubsection}{ADD - add}{8}{section*.6} 16 | \contentsline {subsubsection}{ADC - add with carry}{9}{section*.7} 17 | \contentsline {subsubsection}{SUB - subtract}{9}{section*.8} 18 | \contentsline {subsubsection}{SBC - subtract with carry}{9}{section*.9} 19 | \contentsline {subsubsection}{LDR - load register}{9}{section*.10} 20 | \contentsline {subsubsection}{LDC - load constant}{10}{section*.11} 21 | \contentsline {subsection}{\numberline {1.4.2}Deslocamento e rota\IeC {\c c}\IeC {\~a}o}{10}{subsection.1.4.2} 22 | \contentsline {subsubsection}{LSR - logical shift right}{10}{section*.12} 23 | \contentsline {subsubsection}{ASR - arithmetic shift right}{10}{section*.13} 24 | \contentsline {subsubsection}{ROR - rotate right through carry}{11}{section*.14} 25 | \contentsline {subsection}{\numberline {1.4.3}Carga e armazenamento}{11}{subsection.1.4.3} 26 | \contentsline {subsubsection}{LDB - load byte}{11}{section*.15} 27 | \contentsline {subsubsection}{STB - store byte}{11}{section*.16} 28 | \contentsline {subsubsection}{LDW - load word}{11}{section*.17} 29 | \contentsline {subsubsection}{STW - store word}{12}{section*.18} 30 | \contentsline {subsection}{\numberline {1.4.4}Desvios condicionais}{12}{subsection.1.4.4} 31 | \contentsline {subsubsection}{BEZ - branch if equal zero}{12}{section*.19} 32 | \contentsline {subsubsection}{BNZ - branch if not equal zero}{12}{section*.20} 33 | \contentsline {section}{\numberline {1.5}Detalhes sobre a codifica\IeC {\c c}\IeC {\~a}o de instru\IeC {\c c}\IeC {\~o}es}{13}{section.1.5} 34 | \contentsline {section}{\numberline {1.6}Caracter\IeC {\'\i }sticas \IeC {\'u}nicas}{14}{section.1.6} 35 | \contentsline {subsection}{\numberline {1.6.1}Carga de constantes}{14}{subsection.1.6.1} 36 | \contentsline {subsection}{\numberline {1.6.2}Extens\IeC {\~a}o de sinal}{15}{subsection.1.6.2} 37 | \contentsline {subsection}{\numberline {1.6.3}Desvios condicionais}{15}{subsection.1.6.3} 38 | \contentsline {subsection}{\numberline {1.6.4}Soma e subtra\IeC {\c c}\IeC {\~a}o de m\IeC {\'u}ltipla precis\IeC {\~a}o}{16}{subsection.1.6.4} 39 | \contentsline {subsection}{\numberline {1.6.5}Deslocamento de m\IeC {\'u}ltipla precis\IeC {\~a}o}{16}{subsection.1.6.5} 40 | \contentsline {subsection}{\numberline {1.6.6}Compara\IeC {\c c}\IeC {\~o}es de m\IeC {\'u}ltipla precis\IeC {\~a}o}{17}{subsection.1.6.6} 41 | \contentsline {subsection}{\numberline {1.6.7}Outras opera\IeC {\c c}\IeC {\~o}es}{17}{subsection.1.6.7} 42 | \contentsline {section}{\numberline {1.7}Tipos de dados}{18}{section.1.7} 43 | \contentsline {chapter}{\numberline {2}S\IeC {\'\i }ntese de pseudo opera\IeC {\c c}\IeC {\~o}es}{19}{chapter.2} 44 | \contentsline {section}{\numberline {2.1}Pseudo opera\IeC {\c c}\IeC {\~o}es b\IeC {\'a}sicas}{19}{section.2.1} 45 | \contentsline {section}{\numberline {2.2}Opera\IeC {\c c}\IeC {\~o}es de deslocamento}{20}{section.2.2} 46 | \contentsline {section}{\numberline {2.3}Pseudo opera\IeC {\c c}\IeC {\~o}es n\IeC {\~a}o suportadas pelo montador}{20}{section.2.3} 47 | \contentsline {subsection}{\numberline {2.3.1}Testes, sele\IeC {\c c}\IeC {\~a}o e desvios (condicionais)}{20}{subsection.2.3.1} 48 | \contentsline {subsection}{\numberline {2.3.2}Opera\IeC {\c c}\IeC {\~o}es condicionais equivalentes}{21}{subsection.2.3.2} 49 | \contentsline {subsection}{\numberline {2.3.3}Desvios incondicionais}{22}{subsection.2.3.3} 50 | \contentsline {subsection}{\numberline {2.3.4}Opera\IeC {\c c}\IeC {\~o}es aritm\IeC {\'e}ticas adicionais}{22}{subsection.2.3.4} 51 | \contentsline {chapter}{\numberline {3}Programando com o processador Viking}{23}{chapter.3} 52 | \contentsline {section}{\numberline {3.1}Controle de fluxo do programa}{23}{section.3.1} 53 | \contentsline {subsection}{\numberline {3.1.1}Sele\IeC {\c c}\IeC {\~a}o}{23}{subsection.3.1.1} 54 | \contentsline {subsubsection}{Igual a (==) e diferente de (!=)}{23}{section*.21} 55 | \contentsline {subsubsection}{Menor que (<) e maior ou igual a (>=)}{24}{section*.22} 56 | \contentsline {subsubsection}{Maior que (>) e menor ou igual a (<=)}{24}{section*.23} 57 | \contentsline {subsubsection}{Alternativas para menor ou igual a (<=) e maior ou igual a (>=)}{25}{section*.24} 58 | \contentsline {subsection}{\numberline {3.1.2}Repeti\IeC {\c c}\IeC {\~a}o}{25}{subsection.3.1.2} 59 | \contentsline {subsubsection}{Repeti\IeC {\c c}\IeC {\~a}o incondicional}{25}{section*.25} 60 | \contentsline {subsubsection}{Repeti\IeC {\c c}\IeC {\~a}o condicional}{26}{section*.26} 61 | \contentsline {section}{\numberline {3.2}Acesso \IeC {\`a} mem\IeC {\'o}ria - vari\IeC {\'a}veis}{26}{section.3.2} 62 | \contentsline {section}{\numberline {3.3}Acesso \IeC {\`a} mem\IeC {\'o}ria - vetores}{27}{section.3.3} 63 | \contentsline {section}{\numberline {3.4}Chamadas de fun\IeC {\c c}\IeC {\~a}o e conven\IeC {\c c}\IeC {\~o}es de chamada}{28}{section.3.4} 64 | \contentsline {subsection}{\numberline {3.4.1}Pilha}{28}{subsection.3.4.1} 65 | \contentsline {subsection}{\numberline {3.4.2}Registradores}{28}{subsection.3.4.2} 66 | \contentsline {subsection}{\numberline {3.4.3}Chamada e retorno de fun\IeC {\c c}\IeC {\~o}es}{29}{subsection.3.4.3} 67 | \contentsline {chapter}{\numberline {4}Montagem de c\IeC {\'o}digo e simula\IeC {\c c}\IeC {\~a}o}{31}{chapter.4} 68 | \contentsline {section}{\numberline {4.1}Montador}{31}{section.4.1} 69 | \contentsline {subsection}{\numberline {4.1.1}Formato da linguagem de montagem}{31}{subsection.4.1.1} 70 | \contentsline {subsection}{\numberline {4.1.2}Sintaxe de linha de comando}{32}{subsection.4.1.2} 71 | \contentsline {section}{\numberline {4.2}Simulador}{33}{section.4.2} 72 | \contentsline {subsection}{\numberline {4.2.1}Mapa de mem\IeC {\'o}ria}{34}{subsection.4.2.1} 73 | \contentsline {subsection}{\numberline {4.2.2}Sintaxe de linha de comando}{34}{subsection.4.2.2} 74 | \contentsline {chapter}{\numberline {A}Exemplos}{35}{appendix.A} 75 | \contentsline {chapter}{\numberline {B}Rotinas \textit {mulsi3}, \textit {divsi3}, \textit {modsi3} e \textit {udivmodsi4}}{38}{appendix.B} 76 | -------------------------------------------------------------------------------- /simulator/run16.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys, string 4 | 5 | context = [ 6 | 0x0000, 0x0000, 0x0000, 0x0000, # r0 - r3 7 | 0x0000, 0x0000, 0x0000, 0xdffe, # r4 - r7 8 | 0x0000, 0x0000 # pc, stack limit, carry 9 | ] 10 | 11 | carry = 0 12 | memory = [] 13 | terminput = [] 14 | 15 | def tohex(n): 16 | return "%s" % ("0000%x" % (n & 0xffff))[-4:] 17 | 18 | def check(program) : 19 | for lin in program : 20 | flds = string.split(lin) 21 | if len(flds) != 2 : 22 | return 1 23 | for f in flds : 24 | if f == '****' : 25 | return 1 26 | return 0 27 | 28 | def load(program) : 29 | lines = 0 30 | # load program into memory 31 | for lin in program : 32 | flds = string.split(lin) 33 | data = int(flds[1], 16) 34 | memory.append(data) 35 | lines += 1 36 | print ("[program (code + data): %d bytes]" % (len(memory) * 2)) 37 | 38 | # set the stack limit to the end of program section 39 | context[9] = (len(memory) * 2) + 2 40 | # fill the rest of memory with zeroes 41 | for i in range(lines, 28672) : 42 | memory.append(0) 43 | # set the stack pointer to the last memory position 44 | context[7] = len(memory) * 2 - 2 45 | print ("[memory size: %d]" % (len(memory) * 2)) 46 | 47 | def cycle() : 48 | global carry 49 | global terminput 50 | pc = context[8] 51 | # fetch an instruction from memory 52 | instruction = memory[pc >> 1] 53 | 54 | # predecode the instruction (extract opcode fields) 55 | opc = (instruction & 0xf000) >> 12 56 | imm = (instruction & 0x0800) >> 11 57 | rst = (instruction & 0x0700) >> 8 58 | rs1 = (instruction & 0x00e0) >> 5 59 | rs2 = (instruction & 0x001c) >> 2 60 | op2 = instruction & 0x0003 61 | immediate = instruction & 0x00ff 62 | 63 | # it's halt and catch fire, halt the simulator 64 | if instruction == 0x0003 : return 0 65 | 66 | # decode and execute 67 | if imm == 0 : 68 | if context[rs1] > 0x7fff : rs1 = context[rs1] - 0x10000 69 | else : rs1 = context[rs1] 70 | if context[rs2] > 0x7fff : rs2 = context[rs2] - 0x10000 71 | else : rs2 = context[rs2] 72 | else : 73 | if context[rst] > 0x7fff : rs1 = context[rst] - 0x10000 74 | else : rs1 = context[rst] 75 | if immediate > 0x7f : immediate -= 0x100 76 | rs2 = immediate 77 | 78 | if (opc == 10) : 79 | if op2 == 0 : context[rst] = (rs1 & 0xffff) >> 1 80 | elif op2 == 1 : context[rst] = rs1 >> 1 81 | elif op2 == 2 : context[rst] = (carry << 15) | ((rs1 & 0xffff) >> 1) 82 | else : print ("[error (invalid shift instruction)]") 83 | carry = rs1 & 1 84 | elif ((imm == 0 and (op2 == 0 or op2 == 1)) or imm == 1) : 85 | if opc == 0 : 86 | if (imm == 1) : rs2 &= 0xff 87 | context[rst] = rs1 & rs2 88 | elif opc == 1 : 89 | if (imm == 1) : rs2 &= 0xff 90 | context[rst] = rs1 | rs2 91 | elif opc == 2 : context[rst] = rs1 ^ rs2 92 | elif opc == 3 : 93 | if rs1 < rs2 : context[rst] = 1 94 | else : context[rst] = 0 95 | elif opc == 4 : 96 | if (rs1 & 0xffff) < (rs2 & 0xffff) : context[rst] = 1 97 | else : context[rst] = 0 98 | elif opc == 5 : 99 | if (imm == 0 and op2 == 1) : 100 | context[rst] = (rs1 & 0xffff) + (rs2 & 0xffff) + carry; 101 | else : 102 | context[rst] = (rs1 & 0xffff) + (rs2 & 0xffff) 103 | carry = (context[rst] & 0x10000) >> 16 104 | elif opc == 6 : 105 | if (imm == 0 and op2 == 1) : 106 | context[rst] = (rs1 & 0xffff) - (rs2 & 0xffff) - carry; 107 | else : 108 | context[rst] = (rs1 & 0xffff) - (rs2 & 0xffff) 109 | carry = (context[rst] & 0x10000) >> 16 110 | elif opc == 8 : context[rst] = rs2 111 | elif opc == 9 : context[rst] = (context[rst] << 8) | (rs2 & 0xff) 112 | elif opc == 12 : 113 | if (imm == 1) : 114 | if rs1 == 0 : pc = pc + rs2; 115 | else : 116 | if rs1 == 0 : pc = rs2 - 2 117 | elif opc == 13 : 118 | if (imm == 1) : 119 | if rs1 != 0 : pc = pc + rs2; 120 | else : 121 | if rs1 != 0 : pc = rs2 - 2 122 | else : print ("[error (invalid computation / branch instruction)]") 123 | elif (imm == 0 and op2 == 2) : 124 | if opc == 0 : 125 | if (rs2 & 0x1) : 126 | byte = memory[(rs2 & 0xffff) >> 1] & 0xff 127 | else : 128 | byte = memory[(rs2 & 0xffff) >> 1] >> 8 129 | 130 | if byte > 0x7f : context[rst] = byte - 0x100 131 | else : context[rst] = byte 132 | elif opc == 1 : 133 | if (rs2 & 0x1) : 134 | memory[(rs2 & 0xffff) >> 1] = (memory[(rs2 & 0xffff) >> 1] & 0xff00) | (rs1 & 0xff) 135 | else : 136 | memory[(rs2 & 0xffff) >> 1] = (memory[(rs2 & 0xffff) >> 1] & 0x00ff) | ((rs1 & 0xff) << 8) 137 | elif opc == 4 : 138 | if (rs2 & 0xffff) == 0xf004 : # emulate an input character device (address: 61444) 139 | if len(terminput) == 0 : 140 | terminput = raw_input() + '\0'; 141 | result = int(ord(terminput[0])) 142 | terminput = terminput[1:] 143 | context[rst] = result 144 | elif (rs2 & 0xffff) == 0xf006 : # emulate an input integer device (address: 61446) 145 | context[rst] = int(raw_input()); 146 | else : 147 | context[rst] = memory[(rs2 & 0xffff) >> 1] 148 | elif opc == 5 : 149 | if (rs2 & 0xffff) == 0xf000 : # emulate an output character device (address: 61440) 150 | sys.stdout.write(chr(rs1 & 0xff)) 151 | elif (rs2 & 0xffff) == 0xf002 : # emulate an output integer device (address: 61442) 152 | sys.stdout.write(str(rs1)) 153 | else : 154 | memory[(rs2 & 0xffff) >> 1] = rs1 155 | else : print ("[error (invalid load/store instruction)]") 156 | else : print ("[error (invalid instruction)]") 157 | 158 | # increment the program counter 159 | pc = pc + 2 160 | context[8] = pc 161 | # fix the stored word to the matching hardware size 162 | context[rst] &= 0xffff 163 | 164 | return 1 165 | 166 | def run(program) : 167 | codes = { 168 | 0x0000:"and", 0x1000:"or", 0x2000:"xor", 0x3000:"slt", 169 | 0x4000:"sltu", 0x5000:"add", 0x5001:"adc", 0x6000:"sub", 170 | 0x6001:"sbc", 0x8000:"ldr", 0x9000:"ldc", 0xa000:"lsr", 171 | 0xa001:"asr", 0xa002:"ror", 0x0002:"ldb", 0x1002:"stb", 172 | 0x4002:"ldw", 0x5002:"stw", 0xc000:"bez", 0xd000:"bnz" 173 | } 174 | cycles = 0; 175 | args = sys.argv[1:] 176 | 177 | while True : 178 | inst = memory[context[8] >> 1] 179 | last_pc = context[8] 180 | 181 | if not cycle() : break 182 | cycles += 1 183 | 184 | if context[7] < context[9] : 185 | print ("stack overflow detected!") 186 | break; 187 | 188 | if args : 189 | if (inst & 0x0800) : 190 | print ("pc: %04x instruction: %s r%d,%d" % (last_pc, codes[inst & 0xf000], (inst & 0x0700) >> 8, (inst & 0x00ff))) 191 | else : 192 | print ("pc: %04x instruction: %s r%d,r%d,r%d" % (last_pc, codes[inst & 0xf003], (inst & 0x0700) >> 8, (inst & 0x00e0) >> 5, (inst & 0x001c) >> 2)) 193 | print ("r0: [%04x] r1: [%04x] r2: [%04x] r3: [%04x]" % (context[0], context[1], context[2], context[3])) 194 | print ("r4: [%04x] r5: [%04x] r6: [%04x] r7: [%04x]\n" % (context[4], context[5], context[6], context[7])) 195 | a = raw_input() 196 | print ("\n[ok]") 197 | print ("%d cycles" % cycles) 198 | 199 | 200 | 201 | def main() : 202 | program = sys.stdin.readlines() 203 | if (check(program)) : 204 | print ("[program has errors]") 205 | else : 206 | load(program) 207 | sys.stdin = open('/dev/tty') 208 | run(program) 209 | 210 | if __name__ == "__main__" : main() 211 | -------------------------------------------------------------------------------- /simulator/run32.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys, string 4 | 5 | context = [ 6 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, # r0 - r3 7 | 0x00000000, 0x00000000, 0x00000000, 0x000ffffc, # r4 - r7 8 | 0x00000000, 0x00000000 # pc, stack limit 9 | ] 10 | 11 | carry = 0 12 | memory = [] 13 | terminput = [] 14 | 15 | def tohex(n): 16 | return "%s" % ("0000%x" % (n & 0xffff))[-4:] 17 | 18 | def check(program) : 19 | for lin in program : 20 | flds = string.split(lin) 21 | if len(flds) != 2 : 22 | return 1 23 | for f in flds : 24 | if f == '****' : 25 | return 1 26 | return 0 27 | 28 | def load(program) : 29 | lines = 0 30 | # load program into memory 31 | for lin in program : 32 | flds = string.split(lin) 33 | data = int(flds[1], 16) 34 | memory.append(data) 35 | lines += 1 36 | print ("[program (code + data): %d bytes]" % (len(memory) * 2)) 37 | 38 | # set the stack limit to the end of program section 39 | context[9] = (len(memory) * 2) + 2 40 | # fill the rest of memory with zeroes 41 | for i in range(lines, 524288) : 42 | memory.append(0) 43 | # set the stack pointer to the last memory position 44 | context[7] = len(memory) * 2 - 4 45 | print ("[memory size: %d]" % (len(memory) * 2)) 46 | 47 | def cycle() : 48 | global carry 49 | global terminput 50 | pc = context[8] 51 | # fetch an instruction from memory 52 | instruction = memory[pc >> 1] 53 | 54 | # predecode the instruction (extract opcode fields) 55 | opc = (instruction & 0xf000) >> 12 56 | imm = (instruction & 0x0800) >> 11 57 | rst = (instruction & 0x0700) >> 8 58 | rs1 = (instruction & 0x00e0) >> 5 59 | rs2 = (instruction & 0x001c) >> 2 60 | op2 = instruction & 0x0003 61 | immediate = instruction & 0x00ff 62 | 63 | # it's halt and catch fire, halt the simulator 64 | if instruction == 0x0003 : return 0 65 | 66 | # decode and execute 67 | if imm == 0 : 68 | if context[rs1] > 0x7fffffff : rs1 = context[rs1] - 0x100000000 69 | else : rs1 = context[rs1] 70 | if context[rs2] > 0x7fffffff : rs2 = context[rs2] - 0x100000000 71 | else : rs2 = context[rs2] 72 | else : 73 | if context[rst] > 0x7fffffff : rs1 = context[rst] - 0x100000000 74 | else : rs1 = context[rst] 75 | if immediate > 0x7f : immediate -= 0x100 76 | rs2 = immediate 77 | 78 | if (opc == 10) : 79 | if op2 == 0 : context[rst] = (rs1 & 0xffffffff) >> 1 80 | elif op2 == 1 : context[rst] = rs1 >> 1 81 | elif op2 == 2 : context[rst] = (carry << 31) | ((rs1 & 0xffffffff) >> 1) 82 | else : print ("[error (invalid shift instruction)]") 83 | carry = rs1 & 1 84 | elif ((imm == 0 and (op2 == 0 or op2 == 1)) or imm == 1) : 85 | if opc == 0 : 86 | if (imm == 1) : rs2 &= 0xff 87 | context[rst] = rs1 & rs2 88 | elif opc == 1 : 89 | if (imm == 1) : rs2 &= 0xff 90 | context[rst] = rs1 | rs2 91 | elif opc == 2 : context[rst] = rs1 ^ rs2 92 | elif opc == 3 : 93 | if rs1 < rs2 : context[rst] = 1 94 | else : context[rst] = 0 95 | elif opc == 4 : 96 | if (rs1 & 0xffffffff) < (rs2 & 0xffffffff) : context[rst] = 1 97 | else : context[rst] = 0 98 | elif opc == 5 : 99 | if (imm == 0 and op2 == 1) : 100 | context[rst] = (rs1 & 0xffffffff) + (rs2 & 0xffffffff) + carry 101 | else : 102 | context[rst] = (rs1 & 0xffffffff) + (rs2 & 0xffffffff) 103 | carry = (context[rst] & 0x100000000) >> 32 104 | elif opc == 6 : 105 | if (imm == 0 and op2 == 1) : 106 | context[rst] = (rs1 & 0xffffffff) - (rs2 & 0xffffffff) - carry 107 | else : 108 | context[rst] = (rs1 & 0xffffffff) - (rs2 & 0xffffffff) 109 | carry = (context[rst] & 0x100000000) >> 32 110 | elif opc == 8 : context[rst] = rs2 111 | elif opc == 9 : context[rst] = (context[rst] << 8) | (rs2 & 0xff) 112 | elif opc == 12 : 113 | if (imm == 1) : 114 | if rs1 == 0 : pc = pc + rs2; 115 | else : 116 | if rs1 == 0 : pc = rs2 - 2 117 | elif opc == 13 : 118 | if (imm == 1) : 119 | if rs1 != 0 : pc = pc + rs2; 120 | else : 121 | if rs1 != 0 : pc = rs2 - 2 122 | else : print ("[error (invalid computation / branch instruction)]") 123 | elif (imm == 0 and op2 == 2) : 124 | if opc == 0 : 125 | if (rs2 & 0x1) : 126 | byte = memory[(rs2 & 0xffffffff) >> 1] & 0xff 127 | else : 128 | byte = memory[(rs2 & 0xffffffff) >> 1] >> 8 129 | 130 | if byte > 0x7f : context[rst] = byte - 0x100 131 | else : context[rst] = byte 132 | elif opc == 1 : 133 | if (rs2 & 0x1) : 134 | memory[(rs2 & 0xffffffff) >> 1] = (memory[(rs2 & 0xffffffff) >> 1] & 0xff00) | (rs1 & 0xff) 135 | else : 136 | memory[(rs2 & 0xffffffff) >> 1] = (memory[(rs2 & 0xffffffff) >> 1] & 0x00ff) | ((rs1 & 0xff) << 8) 137 | elif opc == 4 : 138 | if (rs2 & 0xffffffff) == 0xf0000008 : # emulate an input character device 139 | if len(terminput) == 0 : 140 | terminput = raw_input() + '\0'; 141 | result = int(ord(terminput[0])) 142 | terminput = terminput[1:] 143 | context[rst] = result 144 | elif (rs2 & 0xffffffff) == 0xf000000c : # emulate an input integer device 145 | context[rst] = int(raw_input()); 146 | else : 147 | context[rst] = (memory[(rs2 & 0xffffffff) >> 1] << 16) | (memory[((rs2 & 0xffffffff) >> 1) + 1]) 148 | elif opc == 5 : 149 | if (rs2 & 0xffffffff) == 0xf0000000 : # emulate an output device 150 | sys.stdout.write(chr(rs1 & 0xff)) 151 | elif (rs2 & 0xffffffff) == 0xf0000004 : # emulate an output integer device 152 | sys.stdout.write(str(rs1)) 153 | else : 154 | memory[(rs2 & 0xffffffff) >> 1] = rs1 >> 16 155 | memory[((rs2 & 0xffffffff) >> 1) + 1] = rs1 & 0xffff 156 | else : print ("[error (invalid load/store instruction)]") 157 | else : print ("[error (invalid instruction)]") 158 | 159 | # increment the program counter 160 | pc = pc + 2 161 | context[8] = pc 162 | # fix the stored word to the matching hardware size 163 | context[rst] &= 0xffffffff 164 | 165 | return 1 166 | 167 | def run(program) : 168 | codes = { 169 | 0x0000:"and", 0x1000:"or", 0x2000:"xor", 0x3000:"slt", 170 | 0x4000:"sltu", 0x5000:"add", 0x6000:"sub", 0x8000:"ldr", 171 | 0x9000:"ldc", 0x0001:"lsr", 0x1001:"asr", 172 | 0x0002:"ldb", 0x1002:"stb", 0x4002:"ldw", 0x5002:"stw", 173 | 0xa000:"bez", 0xb000:"bnz" 174 | } 175 | cycles = 0; 176 | args = sys.argv[1:] 177 | 178 | while True : 179 | inst = memory[context[8] >> 1] 180 | last_pc = context[8] 181 | 182 | if not cycle() : break 183 | cycles += 1 184 | 185 | if context[7] < context[9] : 186 | print ("stack overflow detected!") 187 | break; 188 | 189 | if args : 190 | if (inst & 0x0800) : 191 | print ("pc: %08x instruction: %s r%d,%d" % (last_pc, codes[inst & 0xf000], (inst & 0x0700) >> 8, (inst & 0x00ff))) 192 | else : 193 | print ("pc: %08x instruction: %s r%d,r%d,r%d" % (last_pc, codes[inst & 0xf003], (inst & 0x0700) >> 8, (inst & 0x00e0) >> 5, (inst & 0x001c) >> 2)) 194 | print ("r0: [%08x] r1: [%08x] r2: [%08x] r3: [%08x]" % (context[0], context[1], context[2], context[3])) 195 | print ("r4: [%08x] r5: [%08x] r6: [%08x] r7: [%08x]\n" % (context[4], context[5], context[6], context[7])) 196 | a = raw_input() 197 | print ("\n[ok]") 198 | print ("%d cycles" % cycles) 199 | 200 | 201 | 202 | def main() : 203 | program = sys.stdin.readlines() 204 | if (check(program)) : 205 | print ("[program has errors]") 206 | else : 207 | load(program) 208 | sys.stdin = open('/dev/tty') 209 | run(program) 210 | 211 | if __name__ == "__main__" : main() 212 | -------------------------------------------------------------------------------- /manual/viking_manual_pt.aux: -------------------------------------------------------------------------------- 1 | \relax 2 | \providecommand\hyper@newdestlabel[2]{} 3 | \catcode `"\active 4 | \providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} 5 | \HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined 6 | \global\let\oldcontentsline\contentsline 7 | \gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} 8 | \global\let\oldnewlabel\newlabel 9 | \gdef\newlabel#1#2{\newlabelxx{#1}#2} 10 | \gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} 11 | \AtEndDocument{\ifx\hyper@anchor\@undefined 12 | \let\contentsline\oldcontentsline 13 | \let\newlabel\oldnewlabel 14 | \fi} 15 | \fi} 16 | \global\let\hyper@last\relax 17 | \gdef\HyperFirstAtBeginDocument#1{#1} 18 | \providecommand\HyField@AuxAddToFields[1]{} 19 | \providecommand\HyField@AuxAddToCoFields[2]{} 20 | \select@language{brazilian} 21 | \@writefile{toc}{\select@language{brazilian}} 22 | \@writefile{lof}{\select@language{brazilian}} 23 | \@writefile{lot}{\select@language{brazilian}} 24 | \@writefile{toc}{\contentsline {chapter}{\numberline {1}A arquitetura Viking}{2}{chapter.1}} 25 | \@writefile{lof}{\addvspace {10\p@ }} 26 | \@writefile{lot}{\addvspace {10\p@ }} 27 | \@writefile{toc}{\contentsline {section}{\numberline {1.1}Registradores}{3}{section.1.1}} 28 | \@writefile{toc}{\contentsline {section}{\numberline {1.2}Formatos de instru\IeC {\c c}\IeC {\~a}o}{3}{section.1.2}} 29 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.2.1}Instru\IeC {\c c}\IeC {\~o}es tipo R}{3}{subsection.1.2.1}} 30 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.2.2}Instru\IeC {\c c}\IeC {\~o}es tipo I}{4}{subsection.1.2.2}} 31 | \@writefile{toc}{\contentsline {section}{\numberline {1.3}Modos de endere\IeC {\c c}amento}{5}{section.1.3}} 32 | \@writefile{toc}{\contentsline {section}{\numberline {1.4}Conjunto de instru\IeC {\c c}\IeC {\~o}es}{6}{section.1.4}} 33 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.4.1}Computa\IeC {\c c}\IeC {\~a}o}{6}{subsection.1.4.1}} 34 | \@writefile{toc}{\contentsline {subsubsection}{AND - bitwise logical product}{6}{section*.1}} 35 | \@writefile{toc}{\contentsline {subsubsection}{OR - bitwise logical sum}{6}{section*.2}} 36 | \@writefile{toc}{\contentsline {subsubsection}{XOR - bitwise logical difference}{7}{section*.3}} 37 | \@writefile{toc}{\contentsline {subsubsection}{SLT - set if less than}{7}{section*.4}} 38 | \@writefile{toc}{\contentsline {subsubsection}{SLTU - set if less than (unsigned)}{8}{section*.5}} 39 | \@writefile{toc}{\contentsline {subsubsection}{ADD - add}{8}{section*.6}} 40 | \@writefile{toc}{\contentsline {subsubsection}{ADC - add with carry}{9}{section*.7}} 41 | \@writefile{toc}{\contentsline {subsubsection}{SUB - subtract}{9}{section*.8}} 42 | \@writefile{toc}{\contentsline {subsubsection}{SBC - subtract with carry}{9}{section*.9}} 43 | \@writefile{toc}{\contentsline {subsubsection}{LDR - load register}{9}{section*.10}} 44 | \@writefile{toc}{\contentsline {subsubsection}{LDC - load constant}{10}{section*.11}} 45 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.4.2}Deslocamento e rota\IeC {\c c}\IeC {\~a}o}{10}{subsection.1.4.2}} 46 | \@writefile{toc}{\contentsline {subsubsection}{LSR - logical shift right}{10}{section*.12}} 47 | \@writefile{toc}{\contentsline {subsubsection}{ASR - arithmetic shift right}{10}{section*.13}} 48 | \@writefile{toc}{\contentsline {subsubsection}{ROR - rotate right through carry}{11}{section*.14}} 49 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.4.3}Carga e armazenamento}{11}{subsection.1.4.3}} 50 | \@writefile{toc}{\contentsline {subsubsection}{LDB - load byte}{11}{section*.15}} 51 | \@writefile{toc}{\contentsline {subsubsection}{STB - store byte}{11}{section*.16}} 52 | \@writefile{toc}{\contentsline {subsubsection}{LDW - load word}{11}{section*.17}} 53 | \@writefile{toc}{\contentsline {subsubsection}{STW - store word}{12}{section*.18}} 54 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.4.4}Desvios condicionais}{12}{subsection.1.4.4}} 55 | \@writefile{toc}{\contentsline {subsubsection}{BEZ - branch if equal zero}{12}{section*.19}} 56 | \@writefile{toc}{\contentsline {subsubsection}{BNZ - branch if not equal zero}{12}{section*.20}} 57 | \@writefile{toc}{\contentsline {section}{\numberline {1.5}Detalhes sobre a codifica\IeC {\c c}\IeC {\~a}o de instru\IeC {\c c}\IeC {\~o}es}{13}{section.1.5}} 58 | \@writefile{toc}{\contentsline {section}{\numberline {1.6}Caracter\IeC {\'\i }sticas \IeC {\'u}nicas}{14}{section.1.6}} 59 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.6.1}Carga de constantes}{14}{subsection.1.6.1}} 60 | \newlabel{ref:constants}{{1.6.1}{14}{Carga de constantes}{subsection.1.6.1}{}} 61 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.6.2}Extens\IeC {\~a}o de sinal}{15}{subsection.1.6.2}} 62 | \newlabel{ref:sign_ext}{{1.6.2}{15}{Extensão de sinal}{subsection.1.6.2}{}} 63 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.6.3}Desvios condicionais}{15}{subsection.1.6.3}} 64 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.6.4}Soma e subtra\IeC {\c c}\IeC {\~a}o de m\IeC {\'u}ltipla precis\IeC {\~a}o}{16}{subsection.1.6.4}} 65 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.6.5}Deslocamento de m\IeC {\'u}ltipla precis\IeC {\~a}o}{16}{subsection.1.6.5}} 66 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.6.6}Compara\IeC {\c c}\IeC {\~o}es de m\IeC {\'u}ltipla precis\IeC {\~a}o}{17}{subsection.1.6.6}} 67 | \@writefile{toc}{\contentsline {subsection}{\numberline {1.6.7}Outras opera\IeC {\c c}\IeC {\~o}es}{17}{subsection.1.6.7}} 68 | \@writefile{toc}{\contentsline {section}{\numberline {1.7}Tipos de dados}{18}{section.1.7}} 69 | \newlabel{ref:data_types}{{1.7}{18}{Tipos de dados}{section.1.7}{}} 70 | \@writefile{toc}{\contentsline {chapter}{\numberline {2}S\IeC {\'\i }ntese de pseudo opera\IeC {\c c}\IeC {\~o}es}{19}{chapter.2}} 71 | \@writefile{lof}{\addvspace {10\p@ }} 72 | \@writefile{lot}{\addvspace {10\p@ }} 73 | \newlabel{ref:pseudo_ops}{{2}{19}{Síntese de pseudo operações}{chapter.2}{}} 74 | \@writefile{toc}{\contentsline {section}{\numberline {2.1}Pseudo opera\IeC {\c c}\IeC {\~o}es b\IeC {\'a}sicas}{19}{section.2.1}} 75 | \@writefile{toc}{\contentsline {section}{\numberline {2.2}Opera\IeC {\c c}\IeC {\~o}es de deslocamento}{20}{section.2.2}} 76 | \@writefile{toc}{\contentsline {section}{\numberline {2.3}Pseudo opera\IeC {\c c}\IeC {\~o}es n\IeC {\~a}o suportadas pelo montador}{20}{section.2.3}} 77 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.3.1}Testes, sele\IeC {\c c}\IeC {\~a}o e desvios (condicionais)}{20}{subsection.2.3.1}} 78 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.3.2}Opera\IeC {\c c}\IeC {\~o}es condicionais equivalentes}{21}{subsection.2.3.2}} 79 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.3.3}Desvios incondicionais}{22}{subsection.2.3.3}} 80 | \@writefile{toc}{\contentsline {subsection}{\numberline {2.3.4}Opera\IeC {\c c}\IeC {\~o}es aritm\IeC {\'e}ticas adicionais}{22}{subsection.2.3.4}} 81 | \@writefile{toc}{\contentsline {chapter}{\numberline {3}Programando com o processador Viking}{23}{chapter.3}} 82 | \@writefile{lof}{\addvspace {10\p@ }} 83 | \@writefile{lot}{\addvspace {10\p@ }} 84 | \@writefile{toc}{\contentsline {section}{\numberline {3.1}Controle de fluxo do programa}{23}{section.3.1}} 85 | \@writefile{toc}{\contentsline {subsection}{\numberline {3.1.1}Sele\IeC {\c c}\IeC {\~a}o}{23}{subsection.3.1.1}} 86 | \@writefile{toc}{\contentsline {subsubsection}{Igual a (==) e diferente de (!=)}{23}{section*.21}} 87 | \@writefile{toc}{\contentsline {subsubsection}{Menor que (<) e maior ou igual a (>=)}{24}{section*.22}} 88 | \@writefile{toc}{\contentsline {subsubsection}{Maior que (>) e menor ou igual a (<=)}{24}{section*.23}} 89 | \@writefile{toc}{\contentsline {subsubsection}{Alternativas para menor ou igual a (<=) e maior ou igual a (>=)}{25}{section*.24}} 90 | \@writefile{toc}{\contentsline {subsection}{\numberline {3.1.2}Repeti\IeC {\c c}\IeC {\~a}o}{25}{subsection.3.1.2}} 91 | \@writefile{toc}{\contentsline {subsubsection}{Repeti\IeC {\c c}\IeC {\~a}o incondicional}{25}{section*.25}} 92 | \@writefile{toc}{\contentsline {subsubsection}{Repeti\IeC {\c c}\IeC {\~a}o condicional}{26}{section*.26}} 93 | \@writefile{toc}{\contentsline {section}{\numberline {3.2}Acesso \IeC {\`a} mem\IeC {\'o}ria - vari\IeC {\'a}veis}{26}{section.3.2}} 94 | \@writefile{toc}{\contentsline {section}{\numberline {3.3}Acesso \IeC {\`a} mem\IeC {\'o}ria - vetores}{27}{section.3.3}} 95 | \@writefile{toc}{\contentsline {section}{\numberline {3.4}Chamadas de fun\IeC {\c c}\IeC {\~a}o e conven\IeC {\c c}\IeC {\~o}es de chamada}{28}{section.3.4}} 96 | \newlabel{ref:fcalls_conv}{{3.4}{28}{Chamadas de função e convenções de chamada}{section.3.4}{}} 97 | \@writefile{toc}{\contentsline {subsection}{\numberline {3.4.1}Pilha}{28}{subsection.3.4.1}} 98 | \newlabel{ref:stack}{{3.4.1}{28}{Pilha}{subsection.3.4.1}{}} 99 | \@writefile{toc}{\contentsline {subsection}{\numberline {3.4.2}Registradores}{28}{subsection.3.4.2}} 100 | \newlabel{ref:regs}{{3.4.2}{28}{Registradores}{subsection.3.4.2}{}} 101 | \@writefile{toc}{\contentsline {subsection}{\numberline {3.4.3}Chamada e retorno de fun\IeC {\c c}\IeC {\~o}es}{29}{subsection.3.4.3}} 102 | \newlabel{ref:fcalls}{{3.4.3}{29}{Chamada e retorno de funções}{subsection.3.4.3}{}} 103 | \@writefile{toc}{\contentsline {chapter}{\numberline {4}Montagem de c\IeC {\'o}digo e simula\IeC {\c c}\IeC {\~a}o}{31}{chapter.4}} 104 | \@writefile{lof}{\addvspace {10\p@ }} 105 | \@writefile{lot}{\addvspace {10\p@ }} 106 | \newlabel{ref:assembler}{{4}{31}{Montagem de código e simulação}{chapter.4}{}} 107 | \@writefile{toc}{\contentsline {section}{\numberline {4.1}Montador}{31}{section.4.1}} 108 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.1.1}Formato da linguagem de montagem}{31}{subsection.4.1.1}} 109 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.1.2}Sintaxe de linha de comando}{32}{subsection.4.1.2}} 110 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {4.1}ninetoone.asm}{32}{lstlisting.4.1}} 111 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {4.2}ninetoone.out}{33}{lstlisting.4.2}} 112 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {4.3}ninetoone\_debug.out}{33}{lstlisting.4.3}} 113 | \@writefile{toc}{\contentsline {section}{\numberline {4.2}Simulador}{33}{section.4.2}} 114 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.2.1}Mapa de mem\IeC {\'o}ria}{34}{subsection.4.2.1}} 115 | \@writefile{toc}{\contentsline {subsection}{\numberline {4.2.2}Sintaxe de linha de comando}{34}{subsection.4.2.2}} 116 | \@writefile{toc}{\contentsline {chapter}{\numberline {A}Exemplos}{35}{appendix.A}} 117 | \@writefile{lof}{\addvspace {10\p@ }} 118 | \@writefile{lot}{\addvspace {10\p@ }} 119 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {A.1}hello\_world.asm}{35}{lstlisting.A.1}} 120 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {A.2}fibonacci.asm}{35}{lstlisting.A.2}} 121 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {A.3}function\_call.asm}{35}{lstlisting.A.3}} 122 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {A.4}mult.asm}{36}{lstlisting.A.4}} 123 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {A.5}bubble\_sort.asm}{36}{lstlisting.A.5}} 124 | \@writefile{toc}{\contentsline {chapter}{\numberline {B}Rotinas \textit {mulsi3}, \textit {divsi3}, \textit {modsi3} e \textit {udivmodsi4}}{38}{appendix.B}} 125 | \@writefile{lof}{\addvspace {10\p@ }} 126 | \@writefile{lot}{\addvspace {10\p@ }} 127 | \newlabel{ref:muldiv}{{B}{38}{Rotinas \textit {mulsi3}, \textit {divsi3}, \textit {modsi3} e \textit {udivmodsi4}}{appendix.B}{}} 128 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {B.1}mulsi3.asm}{38}{lstlisting.B.1}} 129 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {B.2}divsi3.asm}{38}{lstlisting.B.2}} 130 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {B.3}modsi3.asm}{39}{lstlisting.B.3}} 131 | \@writefile{lol}{\contentsline {lstlisting}{\numberline {B.4}udivmodsi4.asm}{39}{lstlisting.B.4}} 132 | -------------------------------------------------------------------------------- /assembler/assemble16.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys, string 4 | 5 | codes = { 6 | "and":0x0000, "or":0x1000, "xor":0x2000, "slt":0x3000, 7 | "sltu":0x4000, "add":0x5000, "adc":0x5001, "sub":0x6000, 8 | "sbc":0x6001, "ldr":0x8000, "ldc":0x9000, "lsr":0xa000, 9 | "asr": 0xa001, "ror": 0xa002, "ldb":0x0002, "stb":0x1002, 10 | "ldw":0x4002, "stw":0x5002, "bez":0xc000, "bnz":0xd000, 11 | "hcf":0x0003, "ldc0":0x9000, "ldc1":0x9000 12 | } 13 | 14 | lookup = { 15 | "r0":0, "r1":1, "r2":2, "r3":3, 16 | "r4":4, "r5":5, "r6":6, "r7":7, 17 | "at":0, "sr":5, "lr":6, "sp":7 18 | } 19 | 20 | def is_number(s): 21 | try: 22 | int(s) 23 | return True 24 | except ValueError: 25 | return False 26 | 27 | def tohex(n): 28 | return "%s" % ("0000%x" % (n & 0xffff))[-4:] 29 | 30 | def getval(s) : 31 | "return numeric value of a symbol or number" 32 | if not s : return 0 # empty symbol - zero 33 | a = lookup.get(s) # get value or None if not in lookup 34 | if a == None : return int(s, 0) # just a number (prefix can be 0x.. 0o.. 0b..) 35 | else : return a 36 | 37 | def pass1(program) : 38 | "process pseudo operations" 39 | i = 0 40 | for lin in program : 41 | flds = string.split(lin) 42 | if flds : 43 | if flds[0] == ";" : 44 | program[i] = '\n' 45 | if flds[0] == "nop" : 46 | program[i] = "\tand r0,r0,r0\n" 47 | if flds[0] == "hcf" : 48 | program[i] = "\thcf r0,r0,r0\n" 49 | if len(flds) > 1 : 50 | parts = string.split(flds[1],",") 51 | if flds[0] == "not" : 52 | program[i] = "\txor " + parts[0] + ",-1\n" 53 | if flds[0] == "neg" : 54 | program[i] = "\txor " + parts[0] + ",-1\n" 55 | program.insert(i+1, "\tadd " + parts[0] + ",1\n") 56 | if flds[0] == "mov" : 57 | program[i] = "\tand " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 58 | if flds[0] == "lsr" : 59 | program[i] = "\tlsr " + parts[0] + "," + parts[1] + "," + "r0\n" 60 | if flds[0] == "asr" : 61 | program[i] = "\tasr " + parts[0] + "," + parts[1] + "," + "r0\n" 62 | if flds[0] == "ror" : 63 | program[i] = "\tror " + parts[0] + "," + parts[1] + "," + "r0\n" 64 | if flds[0] == "lsl" : 65 | program[i] = "\tadd " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 66 | if flds[0] == "rol" : 67 | program[i] = "\tadc " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 68 | if flds[0] == "ldi" : 69 | if is_number(parts[1]) : 70 | if ((int(parts[1]) < 256) and (int(parts[1]) >= -128)) : 71 | program[i] = "\tldr " + flds[1] + "\n" 72 | else : 73 | program[i] = "\tldr " + parts[0] + "," + str((int(parts[1]) >> 8) & 0xff) + "\n" 74 | program.insert(i+1, "\tldc " + parts[0] + "," + str(int(parts[1]) & 0xff) + "\n") 75 | else : 76 | program[i] = "\tldc0 " + flds[1] + "\n" 77 | program.insert(i+1, "\tldc1 " + flds[1] + "\n") 78 | if flds[0] == "ldb" and len(parts) == 2 : 79 | if lookup.get(parts[1]) == None : 80 | program[i] = "\tldc0 at," + parts[1] + "\n" 81 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 82 | program.insert(i+2, "\tldb " + parts[0] + ",r0,at\n") 83 | else : 84 | program[i] = "\tldb " + parts[0] + ",r0," + parts[1] + "\n" 85 | if flds[0] == "stb" and len(parts) == 2 : 86 | if lookup.get(parts[1]) == None : 87 | program[i] = "\tldc0 at," + parts[1] + "\n" 88 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 89 | program.insert(i+2, "\tstb r0," + parts[0] + ",at\n") 90 | else : 91 | program[i] = "\tstb r0," + parts[0] + "," + parts[1] + "\n" 92 | if flds[0] == "ldw" and len(parts) == 2 : 93 | if lookup.get(parts[1]) == None : 94 | program[i] = "\tldc0 at," + parts[1] + "\n" 95 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n"); 96 | program.insert(i+2, "\tldw " + parts[0] + ",r0,at\n") 97 | else : 98 | program[i] = "\tldw " + parts[0] + ",r0," + parts[1] + "\n" 99 | if flds[0] == "stw" and len(parts) == 2 : 100 | if lookup.get(parts[1]) == None : 101 | program[i] = "\tldc0 at," + parts[1] + "\n" 102 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 103 | program.insert(i+2, "\tstw r0," + parts[0] + ",at\n") 104 | else : 105 | program[i] = "\tstw r0," + parts[0] + "," + parts[1] + "\n" 106 | if flds[0] == "bez" and len(parts) == 2 : 107 | if lookup.get(parts[1]) == None : 108 | if is_number(parts[1]) == False : 109 | program[i] = "\tldc0 at," + parts[1] + "\n" 110 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 111 | program.insert(i+2, "\tbez r0," + parts[0] + ",at\n") 112 | else : 113 | program[i] = "\tbez r0," + parts[0] + "," + parts[1] + "\n" 114 | if flds[0] == "bnz" and len(parts) == 2 : 115 | if lookup.get(parts[1]) == None : 116 | if is_number(parts[1]) == False : 117 | program[i] = "\tldc0 at," + parts[1] + "\n" 118 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 119 | program.insert(i+2, "\tbnz r0," + parts[0] + ",at\n") 120 | else : 121 | program[i] = "\tbnz r0," + parts[0] + "," + parts[1] + "\n" 122 | if flds[0] == "lsrm" and len(parts) == 2 and is_number(parts[1]) == False : 123 | program[i] = "\tlsr " + parts[0] + "," + parts[0] + ",r0\n" 124 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 125 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 126 | if flds[0] == "asrm" and len(parts) == 2 and is_number(parts[1]) == False : 127 | program[i] = "\tasr " + parts[0] + "," + parts[0] + ",r0\n" 128 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 129 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 130 | if flds[0] == "lslm" and len(parts) == 2 and is_number(parts[1]) == False : 131 | program[i] = "\tadd " + parts[0] + "," + parts[0] + "," + + parts[0] + "\n" 132 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 133 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 134 | i += 1 135 | 136 | def pass2(program) : 137 | "determine addresses for labels and add to the lookup dictionary" 138 | global lookup 139 | pc = 0 140 | for lin in program : 141 | flds = string.split(lin) 142 | if not flds : continue # just an empty line 143 | if lin[0] > ' ' : 144 | symb = flds[0] # a symbol - save its address in lookup 145 | lookup[symb] = pc 146 | flds2 = ' '.join(flds[1:]) 147 | if flds2 : 148 | if flds2[0] == '"' and flds2[-1] == '"' : 149 | flds2 = lin 150 | flds2 = flds2[1:-1] 151 | flds2 = flds2.replace("\\t", chr(0x09)) 152 | flds2 = flds2.replace("\\n", chr(0x0a)) 153 | flds2 = flds2.replace("\\r", chr(0x0d)) 154 | while (flds2[0] != '"') : 155 | flds2 = flds2[1:] 156 | flds2 = flds2[1:-1] + '\0' 157 | while (len(flds2) % 2) != 0 : 158 | flds2 = flds2 + '\0' 159 | pc = pc + len(flds2) 160 | else: 161 | flds = flds[1:] 162 | for f in flds : 163 | pc = pc + 2 164 | else : 165 | pc = pc + 2 166 | 167 | def assemble(flds) : 168 | "assemble instruction to machine code" 169 | opval = codes.get(flds[0]) 170 | symb = lookup.get(flds[0]) 171 | if symb != None : 172 | return symb 173 | else : 174 | if opval == None : return int(flds[0], 0) # just a number (prefix can be 0x.. 0o.. 0b..) 175 | parts = string.split(flds[1],",") # break opcode fields 176 | if len(parts) == 2 : 177 | parts = [0,parts[0],parts[1]] 178 | if (flds[0] == "ldc0") : # ldc0 .. ldc1 are special steps of ldc 179 | return (opval | 0x0800 | (getval(parts[1]) << 8) | ((getval(parts[2]) >> 8) & 0xff)) 180 | else : 181 | return (opval | 0x0800 | (getval(parts[1]) << 8) | (getval(parts[2]) & 0xff)) 182 | if len(parts) == 3 : 183 | parts = [0,parts[0],parts[1],parts[2]] 184 | return (opval | (getval(parts[1]) << 8) | (getval(parts[2]) << 5) | (getval(parts[3]) << 2)) 185 | 186 | def pass3(program) : 187 | "translate assembly code and symbols to machine code" 188 | args = sys.argv[1:] 189 | if args : 190 | args = args[0] 191 | else : 192 | args = '' 193 | 194 | pc = 0 195 | 196 | if args == "debug" : 197 | for lin in program : 198 | flds = string.split(lin) 199 | if lin[0] > ' ' : flds = flds[1:] # drop symbol if there is one 200 | if not flds : print (lin), # print now if only a symbol 201 | else : 202 | try : 203 | flds2 = ' '.join(flds) 204 | if flds2[0] == '"' and flds2[-1] == '"' : 205 | flds2 = lin 206 | flds2 = flds2[1:-1] 207 | flds2 = flds2.replace("\\t", chr(0x09)) 208 | flds2 = flds2.replace("\\n", chr(0x0a)) 209 | flds2 = flds2.replace("\\r", chr(0x0d)) 210 | while (flds2[0] != '"') : 211 | flds2 = flds2[1:] 212 | flds2 = flds2[1:] + '\0' 213 | while (len(flds2) % 2) != 0 : 214 | flds2 = flds2 + '\0' 215 | flds3 = '' 216 | while True : 217 | flds3 += (str((int(ord(flds2[0])) << 8) | int(ord(flds2[1])))) + ' ' 218 | flds2 = flds2[2:] 219 | if flds2 == '' : break 220 | flds3 = string.split(flds3) 221 | instruction = assemble(flds3) 222 | print ("%04x %s %s" % (pc, tohex(instruction), lin)), 223 | pc = pc + 2 224 | flds3 = flds3[1:] 225 | for f in flds3 : 226 | instruction = assemble(flds3) 227 | print ("%04x %s" % (pc, tohex(instruction))) 228 | pc = pc + 2 229 | flds3 = flds3[1:] 230 | flds = '' 231 | else : 232 | if codes.get(flds[0]) == None : 233 | data = assemble(flds) 234 | print ("%04x %s %s" % (pc, tohex(data), lin)), 235 | pc = pc + 2 236 | flds = flds[1:] 237 | for f in flds : 238 | data = assemble(flds) 239 | print ("%04x %s" % (pc, tohex(data))) 240 | pc = pc + 2 241 | flds = flds[1:] 242 | else : 243 | instruction = assemble(flds) 244 | print ("%04x %s %s" % (pc, tohex(instruction), lin)), 245 | pc = pc + 2 246 | except : 247 | print ("**** ???? %s" % lin), 248 | else : 249 | for lin in program : 250 | flds = string.split(lin) 251 | if lin[0] > ' ' : flds = flds[1:] # drop symbol if there is one 252 | if not flds : continue 253 | try : 254 | flds2 = ' '.join(flds) 255 | if flds2[0] == '"' and flds2[-1] == '"' : 256 | flds2 = lin 257 | flds2 = flds2[1:-1] 258 | flds2 = flds2.replace("\\t", chr(0x09)) 259 | flds2 = flds2.replace("\\n", chr(0x0a)) 260 | flds2 = flds2.replace("\\r", chr(0x0d)) 261 | while (flds2[0] != '"') : 262 | flds2 = flds2[1:] 263 | flds2 = flds2[1:-1] + '\0' 264 | while (len(flds2) % 2) != 0 : 265 | flds2 = flds2 + '\0' 266 | flds3 = '' 267 | while True : 268 | flds3 += (str((int(ord(flds2[0])) << 8) | int(ord(flds2[1])))) + ' ' 269 | flds2 = flds2[2:] 270 | if flds2 == '' : break 271 | flds3 = string.split(flds3) 272 | instruction = assemble(flds3) 273 | print ("%04x %s" % (pc, tohex(instruction))) 274 | pc = pc + 2 275 | flds3 = flds3[1:] 276 | for f in flds3 : 277 | instruction = assemble(flds3) 278 | print ("%04x %s" % (pc, tohex(instruction))) 279 | pc = pc + 2 280 | flds3 = flds3[1:] 281 | flds = '' 282 | else : 283 | if codes.get(flds[0]) == None : 284 | data = assemble(flds) 285 | print ("%04x %s" % (pc, tohex(data))) 286 | pc = pc + 2 287 | flds = flds[1:] 288 | for f in flds : 289 | data = assemble(flds) 290 | print ("%04x %s" % (pc, tohex(data))) 291 | pc = pc + 2 292 | flds = flds[1:] 293 | else : 294 | instruction = assemble(flds) 295 | print ("%04x %s" % (pc, tohex(instruction))) 296 | pc = pc + 2 297 | except : 298 | print ("**** ???? %s" % lin), 299 | 300 | def main() : 301 | program = sys.stdin.readlines() 302 | pass1(program) 303 | pass2(program) 304 | pass3(program) 305 | 306 | if __name__ == "__main__" : main() 307 | -------------------------------------------------------------------------------- /assembler/assemble32.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys, string 4 | 5 | codes = { 6 | "and":0x0000, "or":0x1000, "xor":0x2000, "slt":0x3000, 7 | "sltu":0x4000, "add":0x5000, "adc":0x5001, "sub":0x6000, 8 | "sbc":0x6001, "ldr":0x8000, "ldc":0x9000, "lsr":0xa000, 9 | "asr": 0xa001, "ror": 0xa002, "ldb":0x0002, "stb":0x1002, 10 | "ldw":0x4002, "stw":0x5002, "bez":0xc000, "bnz":0xd000, "hcf":0x0003, 11 | "ldc0":0x9000, "ldc1":0x9000, "ldc2": 0x9000, "ldc3": 0x9000 12 | } 13 | 14 | lookup = { 15 | "r0":0, "r1":1, "r2":2, "r3":3, 16 | "r4":4, "r5":5, "r6":6, "r7":7, 17 | "at":0, "sr":5, "lr":6, "sp":7 18 | } 19 | 20 | def is_number(s): 21 | try: 22 | int(s) 23 | return True 24 | except ValueError: 25 | return False 26 | 27 | def tohex(n): 28 | return "%s" % ("0000%x" % (n & 0xffff))[-4:] 29 | 30 | def getval(s) : 31 | "return numeric value of a symbol or number" 32 | if not s : return 0 # empty symbol - zero 33 | a = lookup.get(s) # get value or None if not in lookup 34 | if a == None : return int(s, 0) # just a number (prefix can be 0x.. 0o.. 0b..) 35 | else : return a 36 | 37 | def pass1(program) : 38 | "process pseudo operations" 39 | i = 0 40 | for lin in program : 41 | flds = string.split(lin) 42 | if flds : 43 | if flds[0] == ";" : 44 | program[i] = '\n' 45 | if flds[0] == "nop" : 46 | program[i] = "\tand r0,r0,r0\n" 47 | if flds[0] == "hcf" : 48 | program[i] = "\thcf r0,r0,r0\n" 49 | if len(flds) > 1 : 50 | parts = string.split(flds[1],",") 51 | if flds[0] == "not" : 52 | program[i] = "\txor " + parts[0] + ",-1\n" 53 | if flds[0] == "neg" : 54 | program[i] = "\txor " + parts[0] + ",-1\n" 55 | program.insert(i+1, "\tadd " + parts[0] + ",1\n") 56 | if flds[0] == "mov" : 57 | program[i] = "\tand " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 58 | if flds[0] == "lsr" : 59 | program[i] = "\tlsr " + parts[0] + "," + parts[1] + "," + "r0\n" 60 | if flds[0] == "asr" : 61 | program[i] = "\tasr " + parts[0] + "," + parts[1] + "," + "r0\n" 62 | if flds[0] == "ror" : 63 | program[i] = "\tror " + parts[0] + "," + parts[1] + "," + "r0\n" 64 | if flds[0] == "lsl" : 65 | program[i] = "\tadd " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 66 | if flds[0] == "rol" : 67 | program[i] = "\tadc " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 68 | if flds[0] == "ldi" : 69 | if is_number(parts[1]) : 70 | if ((int(parts[1]) < 256) and (int(parts[1]) >= -128)) : 71 | program[i] = "\tldr " + flds[1] + "\n" 72 | else : 73 | if ((int(parts[1]) < 65536) and (int(parts[1]) >= -32768)) : 74 | program[i] = "\tldr " + parts[0] + "," + str((int(parts[1]) >> 8) & 0xff) + "\n" 75 | program.insert(i+1, "\tldc " + parts[0] + "," + str(int(parts[1]) & 0xff) + "\n") 76 | else : 77 | program[i] = "\tldc0 " + flds[1] + "\n" 78 | program.insert(i+1, "\tldc1 " + flds[1] + "\n") 79 | program.insert(i+2, "\tldc2 " + flds[1] + "\n") 80 | program.insert(i+3, "\tldc3 " + flds[1] + "\n") 81 | else : 82 | program[i] = "\tldc0 " + flds[1] + "\n" 83 | program.insert(i+1, "\tldc1 " + flds[1] + "\n") 84 | program.insert(i+2, "\tldc2 " + flds[1] + "\n") 85 | program.insert(i+3, "\tldc3 " + flds[1] + "\n") 86 | if flds[0] == "ldb" and len(parts) == 2 : 87 | if lookup.get(parts[1]) == None : 88 | program[i] = "\tldc0 sr," + parts[1] + "\n" 89 | program.insert(i+1, "\tldc1 sr," + parts[1] + "\n") 90 | program.insert(i+2, "\tldc2 sr," + parts[1] + "\n") 91 | program.insert(i+3, "\tldc3 sr," + parts[1] + "\n") 92 | program.insert(i+4, "\tldb " + parts[0] + ",r0,sr\n") 93 | else : 94 | program[i] = "\tldb " + parts[0] + ",r0," + parts[1] + "\n" 95 | if flds[0] == "stb" and len(parts) == 2 : 96 | if lookup.get(parts[1]) == None : 97 | program[i] = "\tldc0 sr," + parts[1] + "\n" 98 | program.insert(i+1, "\tldc1 sr," + parts[1] + "\n") 99 | program.insert(i+2, "\tldc2 sr," + parts[1] + "\n") 100 | program.insert(i+3, "\tldc3 sr," + parts[1] + "\n") 101 | program.insert(i+4, "\tstb r0," + parts[0] + ",sr\n") 102 | else : 103 | program[i] = "\tstb r0," + parts[0] + "," + parts[1] + "\n" 104 | if flds[0] == "ldw" and len(parts) == 2 : 105 | if lookup.get(parts[1]) == None : 106 | program[i] = "\tldc0 sr," + parts[1] + "\n" 107 | program.insert(i+1, "\tldc1 sr," + parts[1] + "\n") 108 | program.insert(i+2, "\tldc2 sr," + parts[1] + "\n") 109 | program.insert(i+3, "\tldc3 sr," + parts[1] + "\n") 110 | program.insert(i+4, "\tldw " + parts[0] + ",r0,sr\n") 111 | else : 112 | program[i] = "\tldw " + parts[0] + ",r0," + parts[1] + "\n" 113 | if flds[0] == "stw" and len(parts) == 2 : 114 | if lookup.get(parts[1]) == None : 115 | program[i] = "\tldc0 sr," + parts[1] + "\n" 116 | program.insert(i+1, "\tldc1 sr," + parts[1] + "\n") 117 | program.insert(i+2, "\tldc2 sr," + parts[1] + "\n") 118 | program.insert(i+3, "\tldc3 sr," + parts[1] + "\n") 119 | program.insert(i+4, "\tstw r0," + parts[0] + ",sr\n") 120 | else : 121 | program[i] = "\tstw r0," + parts[0] + "," + parts[1] + "\n" 122 | if flds[0] == "bez" and len(parts) == 2 : 123 | if lookup.get(parts[1]) == None : 124 | if is_number(parts[1]) == False : 125 | program[i] = "\tldc0 sr," + parts[1] + "\n" 126 | program.insert(i+1, "\tldc1 sr," + parts[1] + "\n") 127 | program.insert(i+2, "\tldc2 sr," + parts[1] + "\n") 128 | program.insert(i+3, "\tldc3 sr," + parts[1] + "\n") 129 | program.insert(i+4, "\tbez r0," + parts[0] + ",sr\n") 130 | else : 131 | program[i] = "\tbez r0," + parts[0] + "," + parts[1] + "\n" 132 | if flds[0] == "bnz" and len(parts) == 2 : 133 | if lookup.get(parts[1]) == None : 134 | if is_number(parts[1]) == False : 135 | program[i] = "\tldc0 sr," + parts[1] + "\n" 136 | program.insert(i+1, "\tldc1 sr," + parts[1] + "\n") 137 | program.insert(i+2, "\tldc2 sr," + parts[1] + "\n") 138 | program.insert(i+3, "\tldc3 sr," + parts[1] + "\n") 139 | program.insert(i+4, "\tbnz r0," + parts[0] + ",sr\n") 140 | else : 141 | program[i] = "\tbnz r0," + parts[0] + "," + parts[1] + "\n" 142 | if flds[0] == "lsrm" and len(parts) == 2 and is_number(parts[1]) == False : 143 | program[i] = "\tlsr " + parts[0] + "," + parts[0] + ",r0\n" 144 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 145 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 146 | if flds[0] == "asrm" and len(parts) == 2 and is_number(parts[1]) == False : 147 | program[i] = "\tasr " + parts[0] + "," + parts[0] + ",r0\n" 148 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 149 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 150 | if flds[0] == "lslm" and len(parts) == 2 and is_number(parts[1]) == False : 151 | program[i] = "\tadd " + parts[0] + "," + parts[0] + "," + + parts[0] + "\n" 152 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 153 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 154 | i += 1 155 | 156 | def pass2(program) : 157 | "determine addresses for labels and add to the lookup dictionary" 158 | global lookup 159 | pc = 0 160 | for lin in program : 161 | flds = string.split(lin) 162 | if not flds : continue # just an empty line 163 | if lin[0] > ' ' : 164 | symb = flds[0] # a symbol - save its address in lookup 165 | lookup[symb] = pc 166 | flds2 = ' '.join(flds[1:]) 167 | if flds2 : 168 | if (pc % 4 != 0) : # align to word boundry (32 bits) 169 | pc = pc + 2 170 | lookup[symb] = pc 171 | if flds2[0] == '"' and flds2[-1] == '"' : 172 | flds2 = lin 173 | flds2 = flds2[1:-1] 174 | flds2 = flds2.replace("\\t", chr(0x09)) 175 | flds2 = flds2.replace("\\n", chr(0x0a)) 176 | flds2 = flds2.replace("\\r", chr(0x0d)) 177 | while (flds2[0] != '"') : 178 | flds2 = flds2[1:] 179 | flds2 = flds2[1:-1] + '\0' 180 | while (len(flds2) % 4) != 0 : 181 | flds2 = flds2 + '\0' 182 | pc = pc + len(flds2) 183 | else: 184 | flds = flds[1:] 185 | for f in flds : 186 | pc = pc + 4 187 | else : 188 | pc = pc + 2 189 | 190 | def assemble(flds) : 191 | "assemble instruction to machine code" 192 | opval = codes.get(flds[0]) 193 | symb = lookup.get(flds[0]) 194 | if symb != None : 195 | return symb 196 | else : 197 | if opval == None : return int(flds[0], 0) # just a number (prefix can be 0x.. 0o.. 0b..) 198 | parts = string.split(flds[1],",") # break opcode fields 199 | if len(parts) == 2 : 200 | parts = [0,parts[0],parts[1]] 201 | if (flds[0] == "ldc0") : # ldc0 .. ldc3 are pseudo-ops 202 | return (opval | 0x0800 | (getval(parts[1]) << 8) | ((getval(parts[2]) >> 24) & 0xff)) 203 | elif (flds[0] == "ldc1") : 204 | return (opval | 0x0800 | (getval(parts[1]) << 8) | ((getval(parts[2]) >> 16) & 0xff)) 205 | elif (flds[0] == "ldc2") : 206 | return (opval | 0x0800 | (getval(parts[1]) << 8) | ((getval(parts[2]) >> 8) & 0xff)) 207 | else : 208 | return (opval | 0x0800 | (getval(parts[1]) << 8) | (getval(parts[2]) & 0xff)) 209 | if len(parts) == 3 : 210 | parts = [0,parts[0],parts[1],parts[2]] 211 | return (opval | (getval(parts[1]) << 8) | (getval(parts[2]) << 5) | (getval(parts[3]) << 2)) 212 | 213 | def pass3(program) : 214 | "translate assembly code and symbols to machine code" 215 | args = sys.argv[1:] 216 | if args : 217 | args = args[0] 218 | else : 219 | args = '' 220 | 221 | pc = 0 222 | 223 | if args == "debug" : 224 | for lin in program : 225 | flds = string.split(lin) 226 | if lin[0] > ' ' : flds = flds[1:] # drop symbol if there is one 227 | if not flds : print (lin), # print now if only a symbol 228 | else : 229 | try : 230 | flds2 = ' '.join(flds) 231 | if flds2[0] == '"' and flds2[-1] == '"' : 232 | if (pc % 4 != 0) : # align to word boundry (32 bits) 233 | print ("%08x %s" % (pc, tohex(0))) 234 | pc = pc + 2 235 | flds2 = lin 236 | flds2 = flds2[1:-1] 237 | flds2 = flds2.replace("\\t", chr(0x09)) 238 | flds2 = flds2.replace("\\n", chr(0x0a)) 239 | flds2 = flds2.replace("\\r", chr(0x0d)) 240 | while (flds2[0] != '"') : 241 | flds2 = flds2[1:] 242 | flds2 = flds2[1:-1] + '\0' 243 | while (len(flds2) % 4) != 0 : 244 | flds2 = flds2 + '\0' 245 | flds3 = '' 246 | while True : 247 | flds3 += (str((int(ord(flds2[0])) << 8) | int(ord(flds2[1])))) + ' ' 248 | flds2 = flds2[2:] 249 | if flds2 == '' : break 250 | flds3 = string.split(flds3) 251 | instruction = assemble(flds3) 252 | print ("%08x %s %s" % (pc, tohex(instruction), lin)), 253 | pc = pc + 2 254 | flds3 = flds3[1:] 255 | for f in flds3 : 256 | instruction = assemble(flds3) 257 | print ("%08x %s" % (pc, tohex(instruction))) 258 | pc = pc + 2 259 | flds3 = flds3[1:] 260 | flds = '' 261 | else : 262 | if codes.get(flds[0]) == None : 263 | if (pc % 4 != 0) : # align to word boundry (32 bits) 264 | print ("%08x %s" % (pc, tohex(0))) 265 | pc = pc + 2 266 | data = assemble(flds) 267 | print ("%08x %s %s" % (pc, tohex(data >> 16), lin)), 268 | print ("%08x %s" % (pc+2, tohex(data & 0xffff))), 269 | pc = pc + 4 270 | flds = flds[1:] 271 | for f in flds : 272 | data = assemble(flds) 273 | print ("%08x %s" % (pc, tohex(data >> 16))) 274 | print ("%08x %s" % (pc+2, tohex(data & 0xffff))) 275 | pc = pc + 4 276 | flds = flds[1:] 277 | else : 278 | instruction = assemble(flds) 279 | print ("%08x %s %s" % (pc, tohex(instruction), lin)), 280 | pc = pc + 2 281 | except : 282 | print ("**** ???? %s" % lin), 283 | else : 284 | for lin in program : 285 | flds = string.split(lin) 286 | if lin[0] > ' ' : flds = flds[1:] # drop symbol if there is one 287 | if not flds : continue 288 | try : 289 | flds2 = ' '.join(flds) 290 | if flds2[0] == '"' and flds2[-1] == '"' : 291 | if (pc % 4 != 0) : # align to word boundry (32 bits) 292 | print ("%08x %s" % (pc, tohex(0))) 293 | pc = pc + 2 294 | flds2 = lin 295 | flds2 = flds2[1:-1] 296 | flds2 = flds2.replace("\\t", chr(0x09)) 297 | flds2 = flds2.replace("\\n", chr(0x0a)) 298 | flds2 = flds2.replace("\\r", chr(0x0d)) 299 | while (flds2[0] != '"') : 300 | flds2 = flds2[1:] 301 | flds2 = flds2[1:-1] + '\0' 302 | while (len(flds2) % 4) != 0 : 303 | flds2 = flds2 + '\0' 304 | flds3 = '' 305 | while True : 306 | flds3 += (str((int(ord(flds2[0])) << 8) | int(ord(flds2[1])))) + ' ' 307 | flds2 = flds2[2:] 308 | if flds2 == '' : break 309 | flds3 = string.split(flds3) 310 | instruction = assemble(flds3) 311 | print ("%08x %s" % (pc, tohex(instruction))) 312 | pc = pc + 2 313 | flds3 = flds3[1:] 314 | for f in flds3 : 315 | instruction = assemble(flds3) 316 | print ("%08x %s" % (pc, tohex(instruction))) 317 | pc = pc + 2 318 | flds3 = flds3[1:] 319 | flds = '' 320 | else : 321 | if codes.get(flds[0]) == None : 322 | if (pc % 4 != 0) : # align to word boundry (32 bits) 323 | print ("%08x %s" % (pc, tohex(0))) 324 | pc = pc + 2 325 | data = assemble(flds) 326 | print ("%08x %s" % (pc, tohex(data >> 16))) 327 | print ("%08x %s" % (pc+2, tohex(data & 0xffff))) 328 | pc = pc + 4 329 | flds = flds[1:] 330 | for f in flds : 331 | data = assemble(flds) 332 | print ("%08x %s" % (pc, tohex(data >> 16))) 333 | print ("%08x %s" % (pc+2, tohex(data & 0xffff))) 334 | pc = pc + 4 335 | flds = flds[1:] 336 | else : 337 | instruction = assemble(flds) 338 | print ("%08x %s" % (pc, tohex(instruction))) 339 | pc = pc + 2 340 | except : 341 | print ("**** ???? %s" % lin), 342 | 343 | def main() : 344 | program = sys.stdin.readlines() 345 | pass1(program) 346 | pass2(program) 347 | pass3(program) 348 | 349 | if __name__ == "__main__" : main() 350 | -------------------------------------------------------------------------------- /simulator/vikingsim.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys, string 4 | from Tkinter import * 5 | from tkMessageBox import * 6 | from tkFileDialog import askopenfilename, asksaveasfilename 7 | from tkSimpleDialog import * 8 | 9 | # 10 | # assembler 11 | # 12 | codes = { 13 | "and":0x0000, "or":0x1000, "xor":0x2000, "slt":0x3000, 14 | "sltu":0x4000, "add":0x5000, "adc":0x5001, "sub":0x6000, 15 | "sbc":0x6001, "ldr":0x8000, "ldc":0x9000, "lsr":0xa000, 16 | "asr": 0xa001, "ror": 0xa002, "ldb":0x0002, "stb":0x1002, 17 | "ldw":0x4002, "stw":0x5002, "bez":0xc000, "bnz":0xd000, 18 | "hcf":0x0003, "ldc0":0x9000, "ldc1":0x9000 19 | } 20 | 21 | lookup = { 22 | "r0":0, "r1":1, "r2":2, "r3":3, 23 | "r4":4, "r5":5, "r6":6, "r7":7, 24 | "at":0, "sr":5, "lr":6, "sp":7 25 | } 26 | 27 | def is_number(s): 28 | try: 29 | int(s) 30 | return True 31 | except ValueError: 32 | return False 33 | 34 | def tohex(n): 35 | return "%s" % ("0000%x" % (n & 0xffff))[-4:] 36 | 37 | def getval(s) : 38 | "return numeric value of a symbol or number" 39 | if not s : return 0 # empty symbol - zero 40 | a = lookup.get(s) # get value or None if not in lookup 41 | if a == None : return int(s, 0) # just a number (prefix can be 0x.. 0o.. 0b..) 42 | else : return a 43 | 44 | def pass1(program) : 45 | "process pseudo operations" 46 | i = 0 47 | for lin in program : 48 | flds = string.split(lin) 49 | if flds : 50 | if flds[0] == ";" : 51 | program[i] = "\n" 52 | if flds[0] == "nop" : 53 | program[i] = "\tand r0,r0,r0\n" 54 | if flds[0] == "hcf" : 55 | program[i] = "\thcf r0,r0,r0\n" 56 | if len(flds) > 1 : 57 | parts = string.split(flds[1],",") 58 | if flds[0] == "not" : 59 | program[i] = "\txor " + parts[0] + ",-1\n" 60 | if flds[0] == "neg" : 61 | program[i] = "\txor " + parts[0] + ",-1\n" 62 | program.insert(i+1, "\tadd " + parts[0] + ",1\n") 63 | if flds[0] == "mov" : 64 | program[i] = "\tand " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 65 | if flds[0] == "lsr" : 66 | program[i] = "\tlsr " + parts[0] + "," + parts[1] + "," + "r0\n" 67 | if flds[0] == "asr" : 68 | program[i] = "\tasr " + parts[0] + "," + parts[1] + "," + "r0\n" 69 | if flds[0] == "ror" : 70 | program[i] = "\tror " + parts[0] + "," + parts[1] + "," + "r0\n" 71 | if flds[0] == "lsl" : 72 | program[i] = "\tadd " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 73 | if flds[0] == "rol" : 74 | program[i] = "\tadc " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 75 | if flds[0] == "ldi" : 76 | if is_number(parts[1]) : 77 | if ((int(parts[1]) < 256) and (int(parts[1]) >= -128)) : 78 | program[i] = "\tldr " + flds[1] + "\n" 79 | else : 80 | program[i] = "\tldr " + parts[0] + "," + str((int(parts[1]) >> 8) & 0xff) + "\n" 81 | program.insert(i+1, "\tldc " + parts[0] + "," + str(int(parts[1]) & 0xff) + "\n") 82 | else : 83 | program[i] = "\tldc0 " + flds[1] + "\n" 84 | program.insert(i+1, "\tldc1 " + flds[1] + "\n") 85 | if flds[0] == "ldb" and len(parts) == 2 : 86 | if lookup.get(parts[1]) == None : 87 | program[i] = "\tldc0 at," + parts[1] + "\n" 88 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 89 | program.insert(i+2, "\tldb " + parts[0] + ",r0,at\n") 90 | else : 91 | program[i] = "\tldb " + parts[0] + ",r0," + parts[1] + "\n" 92 | if flds[0] == "stb" and len(parts) == 2 : 93 | if lookup.get(parts[1]) == None : 94 | program[i] = "\tldc0 at," + parts[1] + "\n" 95 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 96 | program.insert(i+2, "\tstb r0," + parts[0] + ",at\n") 97 | else : 98 | program[i] = "\tstb r0," + parts[0] + "," + parts[1] + "\n" 99 | if flds[0] == "ldw" and len(parts) == 2 : 100 | if lookup.get(parts[1]) == None : 101 | program[i] = "\tldc0 at," + parts[1] + "\n" 102 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 103 | program.insert(i+2, "\tldw " + parts[0] + ",r0,at\n") 104 | else : 105 | program[i] = "\tldw " + parts[0] + ",r0," + parts[1] + "\n" 106 | if flds[0] == "stw" and len(parts) == 2 : 107 | if lookup.get(parts[1]) == None : 108 | program[i] = "\tldc0 at," + parts[1] + "\n" 109 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 110 | program.insert(i+2, "\tstw r0," + parts[0] + ",at\n") 111 | else : 112 | program[i] = "\tstw r0," + parts[0] + "," + parts[1] + "\n" 113 | if flds[0] == "bez" and len(parts) == 2 : 114 | if lookup.get(parts[1]) == None : 115 | if is_number(parts[1]) == False : 116 | program[i] = "\tldc0 at," + parts[1] + "\n" 117 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 118 | program.insert(i+2, "\tbez r0," + parts[0] + ",at\n") 119 | else : 120 | program[i] = "\tbez r0," + parts[0] + "," + parts[1] + "\n" 121 | if flds[0] == "bnz" and len(parts) == 2 : 122 | if lookup.get(parts[1]) == None : 123 | if is_number(parts[1]) == False : 124 | program[i] = "\tldc0 at," + parts[1] + "\n" 125 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 126 | program.insert(i+2, "\tbnz r0," + parts[0] + ",at\n") 127 | else : 128 | program[i] = "\tbnz r0," + parts[0] + "," + parts[1] + "\n" 129 | if flds[0] == "lsrm" and len(parts) == 2 and is_number(parts[1]) == False : 130 | program[i] = "\tlsr " + parts[0] + "," + parts[0] + ",r0\n" 131 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 132 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 133 | if flds[0] == "asrm" and len(parts) == 2 and is_number(parts[1]) == False : 134 | program[i] = "\tasr " + parts[0] + "," + parts[0] + ",r0\n" 135 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 136 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 137 | if flds[0] == "lslm" and len(parts) == 2 and is_number(parts[1]) == False : 138 | program[i] = "\tadd " + parts[0] + "," + parts[0] + "," + + parts[0] + "\n" 139 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 140 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 141 | i += 1 142 | 143 | def pass2(program) : 144 | "determine addresses for labels and add to the lookup dictionary" 145 | global lookup 146 | pc = 0 147 | for lin in program : 148 | flds = string.split(lin) 149 | if not flds : continue # just an empty line 150 | if lin[0] > ' ' : 151 | symb = flds[0] # a symbol - save its address in lookup 152 | lookup[symb] = pc 153 | textsym.insert(END, "%s" % tohex(pc) + ' ' + str(symb)) 154 | flds2 = ' '.join(flds[1:]) 155 | if flds2 : 156 | if flds2[0] == '"' and flds2[-1] == '"' : 157 | flds2 = lin 158 | flds2 = flds2[1:-1] 159 | flds2 = flds2.replace("\\t", chr(0x09)) 160 | flds2 = flds2.replace("\\n", chr(0x0a)) 161 | flds2 = flds2.replace("\\r", chr(0x0d)) 162 | while (flds2[0] != '"') : 163 | flds2 = flds2[1:] 164 | flds2 = flds2[1:] + '\0' 165 | while (len(flds2) % 2) != 0 : 166 | flds2 = flds2 + '\0' 167 | pc = pc + len(flds2) 168 | else: 169 | flds = flds[1:] 170 | for f in flds : 171 | pc = pc + 2 172 | else : 173 | pc = pc + 2 174 | 175 | def assemble(flds) : 176 | "assemble instruction to machine code" 177 | opval = codes.get(flds[0]) 178 | symb = lookup.get(flds[0]) 179 | if symb != None : 180 | return symb 181 | else : 182 | if opval == None : return int(flds[0], 0) # just a number (prefix can be 0x.. 0o.. 0b..) 183 | parts = string.split(flds[1],",") # break opcode fields 184 | if len(parts) == 2 : 185 | parts = [0,parts[0],parts[1]] 186 | if (flds[0] == "ldc0") : # ldc0 .. ldc1 are special steps of ldc 187 | return (opval | 0x0800 | (getval(parts[1]) << 8) | ((getval(parts[2]) >> 8) & 0xff)) 188 | else : 189 | return (opval | 0x0800 | (getval(parts[1]) << 8) | (getval(parts[2]) & 0xff)) 190 | if len(parts) == 3 : 191 | parts = [0,parts[0],parts[1],parts[2]] 192 | return (opval | (getval(parts[1]) << 8) | (getval(parts[2]) << 5) | (getval(parts[3]) << 2)) 193 | 194 | def pass3(program) : 195 | "translate assembly code and symbols to machine code" 196 | pc = 0 197 | code = "" 198 | 199 | for lin in program : 200 | if lin == '' : continue 201 | flds = string.split(lin) 202 | if lin[0] > ' ' : flds = flds[1:] # drop symbol if there is one 203 | if not flds : continue 204 | try : 205 | flds2 = ' '.join(flds) 206 | if flds2[0] == '"' and flds2[-1] == '"' : 207 | flds2 = lin 208 | flds2 = flds2[1:-1] 209 | flds2 = flds2.replace("\\t", chr(0x09)) 210 | flds2 = flds2.replace("\\n", chr(0x0a)) 211 | flds2 = flds2.replace("\\r", chr(0x0d)) 212 | while (flds2[0] != '"') : 213 | flds2 = flds2[1:] 214 | flds2 = flds2[1:] + '\0' 215 | while (len(flds2) % 2) != 0 : 216 | flds2 = flds2 + '\0' 217 | flds3 = '' 218 | while True : 219 | flds3 += (str((int(ord(flds2[0])) << 8) | int(ord(flds2[1])))) + ' ' 220 | flds2 = flds2[2:] 221 | if flds2 == '' : break 222 | flds3 = string.split(flds3) 223 | instruction = assemble(flds3) 224 | code += ("%04x %s\n" % (pc, tohex(instruction))) 225 | pc = pc + 2 226 | flds3 = flds3[1:] 227 | for f in flds3 : 228 | instruction = assemble(flds3) 229 | code += ("%04x %s\n" % (pc, tohex(instruction))) 230 | pc = pc + 2 231 | flds3 = flds3[1:] 232 | flds = '' 233 | else : 234 | if codes.get(flds[0]) == None : 235 | data = assemble(flds) 236 | code += ("%04x %s\n" % (pc, tohex(data))) 237 | pc = pc + 2 238 | flds = flds[1:] 239 | for f in flds : 240 | data = assemble(flds) 241 | code += ("%04x %s\n" % (pc, tohex(data))) 242 | pc = pc + 2 243 | flds = flds[1:] 244 | else : 245 | instruction = assemble(flds) 246 | code += ("%04x %s\n" % (pc, tohex(instruction))) 247 | pc = pc + 2 248 | except : 249 | code += ("???? %s" % lin) 250 | return code 251 | 252 | def check(program) : 253 | for lin in program : 254 | flds = string.split(lin) 255 | if len(flds) != 2 and flds != [] : 256 | return 1 257 | for f in flds : 258 | if f == '****' : 259 | return 1 260 | return 0 261 | 262 | def load(program) : 263 | global memory 264 | codes = { 265 | 0x0000:"and", 0x1000:"or", 0x2000:"xor", 0x3000:"slt", 266 | 0x4000:"sltu", 0x5000:"add", 0x5001:"adc", 0x6000:"sub", 267 | 0x6001:"sbc", 0x8000:"ldr", 0x9000:"ldc", 0xa000:"lsr", 268 | 0xa001:"asr", 0xa002:"ror", 0x0002:"ldb", 0x1002:"stb", 269 | 0x4002:"ldw", 0x5002:"stw", 0xc000:"bez", 0xd000:"bnz" 270 | } 271 | memory = [] 272 | 273 | textdump.delete(0, END) 274 | lines = 0 275 | # load program into memory 276 | for lin in program : 277 | flds = string.split(lin) 278 | data = int(flds[1], 16) 279 | memory.append(data) 280 | if (data & 0x0800) : 281 | if (data & 0xf000) in codes : 282 | textdump.insert(END, lin + " %s r%d,%d" % (codes[data & 0xf000], (data & 0x0700) >> 8, (data & 0x00ff))) 283 | else : 284 | textdump.insert(END, lin + " ???") 285 | else : 286 | if (data & 0xf003) in codes : 287 | textdump.insert(END, lin + " %s r%d,r%d,r%d" % (codes[data & 0xf003], (data & 0x0700) >> 8, (data & 0x00e0) >> 5, (data & 0x001c) >> 2)) 288 | else : 289 | textdump.insert(END, lin + " ???") 290 | lines += 1 291 | out.insert(END, " done. Program size: " + str(len(memory) * 2) + " bytes (code + data).\n") 292 | out.see(END) 293 | 294 | # set the stack limit to the end of program section 295 | context[9] = (len(memory) * 2) + 2 296 | # reset breakpoint 297 | context[10] = context[9] 298 | 299 | # fill the rest of memory with zeroes 300 | for i in range(lines, 28672) : 301 | memory.append(0) 302 | reset() 303 | 304 | def loaderror(program) : 305 | global memory 306 | codes = { 307 | 0x0000:"and", 0x1000:"or", 0x2000:"xor", 0x3000:"slt", 308 | 0x4000:"sltu", 0x5000:"add", 0x5001:"adc", 0x6000:"sub", 309 | 0x6001:"sbc", 0x8000:"ldr", 0x9000:"ldc", 0xa000:"lsr", 310 | 0xa001:"asr", 0xa002:"ror", 0x0002:"ldb", 0x1002:"stb", 311 | 0x4002:"ldw", 0x5002:"stw", 0xc000:"bez", 0xd000:"bnz" 312 | } 313 | memory = [] 314 | 315 | textdump.delete(0, END) 316 | lines = 0 317 | # load program into memory 318 | for lin in program : 319 | flds = string.split(lin) 320 | try : 321 | data = int(flds[1], 16) 322 | if (data & 0x0800) : 323 | if (data & 0xf000) in codes : 324 | textdump.insert(END, lin + " %s r%d,%d" % (codes[data & 0xf000], (data & 0x0700) >> 8, (data & 0x00ff))) 325 | else : 326 | textdump.insert(END, lin + " ???") 327 | else : 328 | if (data & 0xf003) in codes : 329 | textdump.insert(END, lin + " %s r%d,r%d,r%d" % (codes[data & 0xf003], (data & 0x0700) >> 8, (data & 0x00e0) >> 5, (data & 0x001c) >> 2)) 330 | else : 331 | textdump.insert(END, lin + " ???") 332 | except : 333 | textdump.insert(END, lin) 334 | lines += 1 335 | out.insert(END, " program has errors.\n") 336 | out.see(END) 337 | reset() 338 | 339 | 340 | def assembler() : 341 | global lookup 342 | out.insert(END, "\nAssembling...") 343 | out.see(END) 344 | source_program = str(textasm.get('1.0', 'end').encode("utf8")) 345 | textsym.delete(0, END) 346 | program = source_program.splitlines() 347 | 348 | lookup = { 349 | "r0":0, "r1":1, "r2":2, "r3":3, 350 | "r4":4, "r5":5, "r6":6, "r7":7, 351 | "at":0, "sr":5, "lr":6, "sp":7 352 | } 353 | 354 | pass1(program) 355 | pass2(program) 356 | code = pass3(program).splitlines() 357 | 358 | if (check(code)) : 359 | loaderror(code) 360 | else : 361 | load(code) 362 | 363 | # 364 | # simulator and user interface 365 | # 366 | context = [ 367 | 0x0000, 0x0000, 0x0000, 0x0000, # r0 - r3 368 | 0x0000, 0x0000, 0x0000, 0xdffe, # r4 - r7 369 | 0x0000, 0x0000, 0x0000 # pc, stack limit, breakpoint 370 | ] 371 | 372 | carry = 0 373 | memory = [] 374 | terminput = [] 375 | 376 | cycles = 0 377 | cycle_delay = 1 378 | RUNNING = -1 379 | STOPPED = -2 380 | machine = STOPPED 381 | 382 | reg_names = ['r0 (at) : ', 'r1 : ', 'r2 : ', 'r3 : ', 'r4 : ', 'r5 (sr) : ', 'r6 (lr) : ', 'r7 (sp) : ', '\nPC : '] 383 | 384 | def cycle() : 385 | global carry, cycles, terminput 386 | pc = context[8] 387 | # fetch an instruction from memory 388 | instruction = memory[pc >> 1] 389 | 390 | # predecode the instruction (extract opcode fields) 391 | opc = (instruction & 0xf000) >> 12 392 | imm = (instruction & 0x0800) >> 11 393 | rst = (instruction & 0x0700) >> 8 394 | rs1 = (instruction & 0x00e0) >> 5 395 | rs2 = (instruction & 0x001c) >> 2 396 | op2 = instruction & 0x0003 397 | immediate = instruction & 0x00ff 398 | 399 | # it's halt and catch fire, halt the simulator 400 | if instruction == 0x0003 : return 0 401 | 402 | # decode and execute 403 | if imm == 0 : 404 | if context[rs1] > 0x7fff : rs1 = context[rs1] - 0x10000 405 | else : rs1 = context[rs1] 406 | if context[rs2] > 0x7fff : rs2 = context[rs2] - 0x10000 407 | else : rs2 = context[rs2] 408 | else : 409 | if context[rst] > 0x7fff : rs1 = context[rst] - 0x10000 410 | else : rs1 = context[rst] 411 | if immediate > 0x7f : immediate -= 0x100 412 | rs2 = immediate 413 | 414 | if (opc == 10) : 415 | if op2 == 0 : context[rst] = (rs1 & 0xffff) >> 1 416 | elif op2 == 1 : context[rst] = rs1 >> 1 417 | elif op2 == 2 : context[rst] = (carry << 15) | ((rs1 & 0xffff) >> 1) 418 | else : 419 | out.insert(END, ("\nInvalid shift instruction at %04x.\n" % context[8])) 420 | out.see(END) 421 | carry = rs1 & 1 422 | elif ((imm == 0 and (op2 == 0 or op2 == 1)) or imm == 1) : 423 | if opc == 0 : 424 | if (imm == 1) : rs2 &= 0xff 425 | context[rst] = rs1 & rs2 426 | elif opc == 1 : 427 | if (imm == 1) : rs2 &= 0xff 428 | context[rst] = rs1 | rs2 429 | elif opc == 2 : context[rst] = rs1 ^ rs2 430 | elif opc == 3 : 431 | if rs1 < rs2 : context[rst] = 1 432 | else : context[rst] = 0 433 | elif opc == 4 : 434 | if (rs1 & 0xffff) < (rs2 & 0xffff) : context[rst] = 1 435 | else : context[rst] = 0 436 | elif opc == 5 : 437 | if (imm == 0 and op2 == 1) : 438 | context[rst] = (rs1 & 0xffff) + (rs2 & 0xffff) + carry; 439 | else : 440 | context[rst] = (rs1 & 0xffff) + (rs2 & 0xffff) 441 | carry = (context[rst] & 0x10000) >> 16 442 | elif opc == 6 : 443 | if (imm == 0 and op2 == 1) : 444 | context[rst] = (rs1 & 0xffff) - (rs2 & 0xffff) - carry; 445 | else : 446 | context[rst] = (rs1 & 0xffff) - (rs2 & 0xffff) 447 | carry = (context[rst] & 0x10000) >> 16 448 | elif opc == 8 : context[rst] = rs2 449 | elif opc == 9 : context[rst] = (context[rst] << 8) | (rs2 & 0xff) 450 | elif opc == 12 : 451 | if (imm == 1) : 452 | if rs1 == 0 : pc = pc + rs2; 453 | else : 454 | if rs1 == 0 : pc = rs2 - 2 455 | elif opc == 13 : 456 | if (imm == 1) : 457 | if rs1 != 0 : pc = pc + rs2; 458 | else : 459 | if rs1 != 0 : pc = rs2 - 2 460 | else : 461 | out.insert(END, ("\nInvalid computation / branch instruction at %04x.\n" % context[8])) 462 | out.see(END) 463 | elif (imm == 0 and op2 == 2) : 464 | if opc == 0 : 465 | if (rs2 & 0x1) : 466 | byte = memory[(rs2 & 0xffff) >> 1] & 0xff 467 | else : 468 | byte = memory[(rs2 & 0xffff) >> 1] >> 8 469 | 470 | if byte > 0x7f : context[rst] = byte - 0x100 471 | else : context[rst] = byte 472 | elif opc == 1 : 473 | if (rs2 & 0x1) : 474 | memory[(rs2 & 0xffff) >> 1] = (memory[(rs2 & 0xffff) >> 1] & 0xff00) | (rs1 & 0xff) 475 | else : 476 | memory[(rs2 & 0xffff) >> 1] = (memory[(rs2 & 0xffff) >> 1] & 0x00ff) | ((rs1 & 0xff) << 8) 477 | elif opc == 4 : 478 | if (rs2 & 0xffff) == 0xf004 : # emulate an input character device (address: 61444) 479 | if len(terminput) == 0 : 480 | terminput = askstring("Input", "string val:") + '\0'; 481 | result = int(ord(terminput[0])) 482 | terminput = terminput[1:] 483 | context[rst] = result 484 | elif (rs2 & 0xffff) == 0xf006 : # emulate an input integer device (address: 61446) 485 | result = askstring("Input", "int val:") 486 | if result : 487 | context[rst] = int(result) 488 | else : 489 | context[rst] = memory[(rs2 & 0xffff) >> 1] 490 | elif opc == 5 : 491 | if (rs2 & 0xffff) == 0xf000 : # emulate an output character device (address: 61440) 492 | out.insert(END, chr(rs1 & 0xff)) 493 | out.see(END) 494 | elif (rs2 & 0xffff) == 0xf002 : # emulate an output integer device (address: 61442) 495 | out.insert(END, str(rs1)) 496 | out.see(END) 497 | else : 498 | memory[(rs2 & 0xffff) >> 1] = rs1 499 | else : 500 | out.insert(END, ("\nInvalid load/store instruction at %04x.\n" % context[8])) 501 | out.see(END) 502 | else : 503 | out.insert(END, ("\nInvalid instruction at %04x.\n" % context[8])) 504 | out.see(END) 505 | 506 | # increment the program counter 507 | pc = pc + 2 508 | context[8] = pc 509 | # fix the stored word to the matching hardware size 510 | context[rst] &= 0xffff 511 | 512 | cycles += 1 513 | # update register labels 514 | refresh_regs() 515 | 516 | return 1 517 | 518 | 519 | def newprogram() : 520 | textasm.delete('1.0', END) 521 | textasm.delete('1.0', END) 522 | 523 | def openprogram() : 524 | name = askopenfilename(defaultextension=".asm", filetypes=(("Assembly file", "*.asm"),("All Files", "*.*"))) 525 | if (name) : 526 | program = open(name, "r") 527 | if program : 528 | program.seek(0) 529 | textasm.delete('1.0', END) 530 | for lin in program : 531 | textasm.insert(END, lin) 532 | program.close() 533 | 534 | def openadditionalprogram() : 535 | name = askopenfilename(defaultextension=".asm", filetypes=(("Assembly file", "*.asm"),("All Files", "*.*"))) 536 | if (name) : 537 | program = open(name, "r") 538 | if program : 539 | program.seek(0) 540 | textasm.insert(END, "\n") 541 | for lin in program : 542 | textasm.insert(END, lin) 543 | program.close() 544 | 545 | def saveprogram() : 546 | name = asksaveasfilename(defaultextension=".asm", filetypes=(("Assembly file", "*.asm"),("All Files", "*.*"))) 547 | if (name) : 548 | program = open(name, "w") 549 | if program : 550 | program.write(textasm.get('1.0', 'end')) 551 | program.close() 552 | 553 | def reset() : 554 | global cycles, machine 555 | # clear GPRs 556 | for i in range(8) : 557 | context[i] = 0 558 | # set the stack pointer to the last memory position 559 | context[7] = len(memory) * 2 - 2 560 | # set pc to zero 561 | context[8] = 0 562 | # reset breakpoint 563 | machine = STOPPED 564 | 565 | cycles = 0 566 | refresh_regs() 567 | textdump.focus() 568 | textdump.activate(0) 569 | textdump.see(0) 570 | 571 | def run() : 572 | global machine 573 | 574 | if len(memory) > 0 : 575 | if machine == STOPPED : 576 | machine = RUNNING 577 | run_step() 578 | else : 579 | showerror("Error", "No program in memory.") 580 | 581 | def run_step() : 582 | inst = memory[context[8] >> 1] 583 | last_pc = context[8] 584 | 585 | if cycle() : 586 | textdump.focus() 587 | textdump.activate(context[8] >> 1) 588 | textdump.see(context[8] >> 1) 589 | 590 | if context[8] == context[10] : 591 | out.insert(END, ("\nBreakpoint at %04x.\n" % context[8])) 592 | out.see(END) 593 | else: 594 | if context[7] < context[9] : 595 | out.insert(END, ("\nStack overflow detected at %04x.\n" % context[8])) 596 | out.see(END) 597 | else : 598 | if machine != STOPPED : 599 | root.after(cycle_delay, run_step) 600 | else : 601 | out.insert(END, ("\nProgram halted at %04x.\n" % context[8])) 602 | out.see(END) 603 | 604 | def stop() : 605 | global machine 606 | machine = STOPPED 607 | 608 | def step() : 609 | if len(memory) > 0 : 610 | stop() 611 | inst = memory[context[8] >> 1] 612 | last_pc = context[8] 613 | 614 | if cycle() : 615 | textdump.focus() 616 | textdump.activate(context[8] >> 1) 617 | textdump.see(context[8] >> 1) 618 | 619 | if context[7] < context[9] : 620 | out.insert(END, ("\nStack overflow detected at %04x.\n" % context[8])) 621 | out.see(END) 622 | else : 623 | out.insert(END, ("\nProgram halted at %04x.\n" % context[8])) 624 | out.see(END) 625 | else : 626 | showerror("Error", "No program in memory.") 627 | 628 | def refresh_regs() : 629 | for i in range(9) : 630 | root.reg_label[i].set(reg_names[i] + tohex(context[i])) 631 | root.cycle.set("Cycle: " + str(cycles) + "\n") 632 | 633 | def set_breakpoint() : 634 | result = askstring("Set breakpoint", "Program address (hex):") 635 | if result : 636 | context[10] = int(result, 16) 637 | 638 | def set_cycledelay() : 639 | global cycle_delay 640 | result = askstring("Set machine cycle delay", "Delay (ms):") 641 | if result > 0 : 642 | cycle_delay = int(result) 643 | 644 | def clear_term() : 645 | out.delete('1.0', END) 646 | 647 | def memdump() : 648 | memwindow = Toplevel(root) 649 | memwindow.title("Memory dump") 650 | memwindow.geometry("600x652+50+50") 651 | memwindow.resizable(0,0) 652 | mem_dump = Listbox(memwindow, height=24, width=65, font=('Courier', 11)) 653 | mem_dumpscroll = Scrollbar(memwindow, command=mem_dump.yview) 654 | mem_dump.configure(yscrollcommand=mem_dumpscroll.set) 655 | mem_dump.pack(side=LEFT, fill=BOTH) 656 | mem_dumpscroll.pack(side=LEFT, fill=Y) 657 | 658 | k = 0 659 | while k < len(memory) * 2 : 660 | dump_line = str(tohex(k)) + ': ' 661 | l = 0 662 | while l < 8 : 663 | dump_line = dump_line + tohex(memory[k / 2 + l]) + ' ' 664 | l += 1 665 | dump_line += '|' 666 | l = 0 667 | while l < 8 : 668 | ch1 = memory[k / 2 + l] >> 8 669 | ch2 = memory[k / 2 + l] & 0xff 670 | if ((ch1 >= 32) and (ch1 <= 126)) : 671 | dump_line += chr(ch1) 672 | else : 673 | dump_line += '.' 674 | if ((ch2 >= 32) and (ch2 <= 126)) : 675 | dump_line += chr(ch2) 676 | else : 677 | dump_line += '.' 678 | l += 1 679 | dump_line += '|' 680 | mem_dump.insert(END, dump_line) 681 | k += 16 682 | 683 | root = Tk() 684 | menu = Menu(root) 685 | root.geometry("1000x692+30+30") 686 | root.resizable(0,0) 687 | root.config(menu=menu) 688 | 689 | programmenu = Menu(menu) 690 | menu.add_cascade(label="Program", menu=programmenu) 691 | programmenu.add_command(label="New", command=newprogram) 692 | programmenu.add_command(label="Load", command=openprogram) 693 | programmenu.add_command(label="Load additional file", command=openadditionalprogram) 694 | programmenu.add_command(label="Save as", command=saveprogram) 695 | programmenu.add_separator() 696 | programmenu.add_command(label="Assemble", command=assembler) 697 | programmenu.add_separator() 698 | programmenu.add_command(label="Exit", command=root.quit) 699 | 700 | machinemenu = Menu(menu) 701 | menu.add_cascade(label="Machine", menu=machinemenu) 702 | machinemenu.add_command(label="Reset", command=reset) 703 | machinemenu.add_command(label="Stop", command=stop) 704 | machinemenu.add_command(label="Run", command=run) 705 | machinemenu.add_command(label="Step", command=step) 706 | machinemenu.add_separator() 707 | machinemenu.add_command(label="Set breakpoint", command=set_breakpoint) 708 | machinemenu.add_command(label="Set machine cycle delay", command=set_cycledelay) 709 | machinemenu.add_command(label="Clear terminal", command=clear_term) 710 | machinemenu.add_command(label="Memory dump", command=memdump) 711 | 712 | topframe = Frame(root) 713 | topframe.pack() 714 | middleframe = Frame(root) 715 | middleframe.pack() 716 | bottomframe = Frame(root) 717 | bottomframe.pack() 718 | 719 | Label(topframe, text="Program:", width=46, font=('Courier', 11, 'bold'), anchor=W).pack(side=LEFT) 720 | Label(topframe, text="Object code / disassembly:", width=28, font=('Courier', 11, 'bold'), anchor=W).pack(side=LEFT) 721 | Label(topframe, text="Symbol table:", width=22, font=('Courier', 11, 'bold'), anchor=W).pack(side=LEFT) 722 | Label(topframe, text="Registers:", width=16, font=('Courier', 11, 'bold'), anchor=W).pack(side=LEFT) 723 | 724 | asmxscrollbar = Scrollbar(middleframe, orient=HORIZONTAL) 725 | asmyscrollbar = Scrollbar(middleframe) 726 | textasm = Text(middleframe, wrap=NONE, xscrollcommand=asmxscrollbar.set, yscrollcommand=asmyscrollbar.set, height=24, width=44, font=('Courier', 11)) 727 | asmxscrollbar.pack(side=BOTTOM, fill=X) 728 | textasm.pack(side=LEFT, fill=BOTH) 729 | asmyscrollbar.pack(side=LEFT, fill=Y) 730 | asmxscrollbar.config(command=textasm.xview) 731 | asmyscrollbar.config(command=textasm.yview) 732 | 733 | textdump = Listbox(middleframe, height=24, width=26, font=('Courier', 11)) 734 | textdumpscroll = Scrollbar(middleframe, command=textdump.yview) 735 | textdump.configure(yscrollcommand=textdumpscroll.set) 736 | textdump.pack(side=LEFT, fill=BOTH) 737 | textdumpscroll.pack(side=LEFT, fill=Y) 738 | 739 | textsym = Listbox(middleframe, height=24, width=18, font=('Courier', 11)) 740 | textsymscroll = Scrollbar(middleframe, command=textsym.yview) 741 | textsym.configure(yscrollcommand=textsymscroll.set) 742 | textsym.pack(side=LEFT, fill=BOTH) 743 | textsymscroll.pack(side=LEFT, fill=Y) 744 | 745 | root.reg_label = [] 746 | for i in range(9): 747 | root.reg_label.append(StringVar()) 748 | 749 | for i in range(9) : 750 | Label(middleframe, textvariable=root.reg_label[i], width=25, font=('Courier', 11)).pack() 751 | 752 | Label(middleframe, text="\nControl:\n", width=25, font=('Courier', 11, 'bold')).pack() 753 | 754 | root.cycle = StringVar() 755 | Label(middleframe, textvariable=root.cycle, width=25, font=('Courier', 11)).pack() 756 | 757 | refresh_regs() 758 | 759 | Button(middleframe, text='Reset', width=14, command=reset).pack() 760 | Button(middleframe, text='Stop', width=14, command=stop).pack() 761 | Button(middleframe, text='Run', width=14, command=run).pack() 762 | Button(middleframe, text='Step', width=14, command=step).pack() 763 | 764 | out = Text(bottomframe, height=14, width=122, font=('Courier', 10)) 765 | outscroll = Scrollbar(bottomframe, command=out.yview) 766 | out.configure(yscrollcommand=outscroll.set) 767 | out.pack(side=LEFT, fill=BOTH) 768 | outscroll.pack(side=LEFT, fill=Y) 769 | 770 | mainloop() 771 | -------------------------------------------------------------------------------- /simulator/vikingsim3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import sys, string, tkinter 4 | from tkinter import * 5 | from tkinter import messagebox 6 | from tkinter import filedialog 7 | from tkinter import simpledialog 8 | 9 | # 10 | # assembler 11 | # 12 | codes = { 13 | "and":0x0000, "or":0x1000, "xor":0x2000, "slt":0x3000, 14 | "sltu":0x4000, "add":0x5000, "adc":0x5001, "sub":0x6000, 15 | "sbc":0x6001, "ldr":0x8000, "ldc":0x9000, "lsr":0xa000, 16 | "asr": 0xa001, "ror": 0xa002, "ldb":0x0002, "stb":0x1002, 17 | "ldw":0x4002, "stw":0x5002, "bez":0xc000, "bnz":0xd000, 18 | "hcf":0x0003, "ldc0":0x9000, "ldc1":0x9000 19 | } 20 | 21 | lookup = { 22 | "r0":0, "r1":1, "r2":2, "r3":3, 23 | "r4":4, "r5":5, "r6":6, "r7":7, 24 | "at":0, "sr":5, "lr":6, "sp":7 25 | } 26 | 27 | def is_number(s): 28 | try: 29 | int(s) 30 | return True 31 | except ValueError: 32 | return False 33 | 34 | def tohex(n): 35 | return "%s" % ("0000%x" % (n & 0xffff))[-4:] 36 | 37 | def getval(s) : 38 | "return numeric value of a symbol or number" 39 | if not s : return 0 # empty symbol - zero 40 | a = lookup.get(s) # get value or None if not in lookup 41 | if a == None : return int(s, 0) # just a number (prefix can be 0x.. 0o.. 0b..) 42 | else : return a 43 | 44 | def pass1(program) : 45 | "process pseudo operations" 46 | i = 0 47 | for lin in program : 48 | flds = lin.split() 49 | 50 | if flds : 51 | if flds[0] == ";" : 52 | program[i] = "\n" 53 | if flds[0] == "nop" : 54 | program[i] = "\tand r0,r0,r0\n" 55 | if flds[0] == "hcf" : 56 | program[i] = "\thcf r0,r0,r0\n" 57 | if len(flds) > 1 : 58 | parts = flds[1].split(',') 59 | 60 | if flds[0] == "not" : 61 | program[i] = "\txor " + parts[0] + ",-1\n" 62 | if flds[0] == "neg" : 63 | program[i] = "\txor " + parts[0] + ",-1\n" 64 | program.insert(i+1, "\tadd " + parts[0] + ",1\n") 65 | if flds[0] == "mov" : 66 | program[i] = "\tand " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 67 | if flds[0] == "lsr" : 68 | program[i] = "\tlsr " + parts[0] + "," + parts[1] + "," + "r0\n" 69 | if flds[0] == "asr" : 70 | program[i] = "\tasr " + parts[0] + "," + parts[1] + "," + "r0\n" 71 | if flds[0] == "ror" : 72 | program[i] = "\tror " + parts[0] + "," + parts[1] + "," + "r0\n" 73 | if flds[0] == "lsl" : 74 | program[i] = "\tadd " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 75 | if flds[0] == "rol" : 76 | program[i] = "\tadc " + parts[0] + "," + parts[1] + "," + parts[1] + "\n" 77 | if flds[0] == "ldi" : 78 | if is_number(parts[1]) : 79 | if ((int(parts[1]) < 256) and (int(parts[1]) >= -128)) : 80 | program[i] = "\tldr " + flds[1] + "\n" 81 | else : 82 | program[i] = "\tldr " + parts[0] + "," + str((int(parts[1]) >> 8) & 0xff) + "\n" 83 | program.insert(i+1, "\tldc " + parts[0] + "," + str(int(parts[1]) & 0xff) + "\n") 84 | else : 85 | program[i] = "\tldc0 " + flds[1] + "\n" 86 | program.insert(i+1, "\tldc1 " + flds[1] + "\n") 87 | if flds[0] == "ldb" and len(parts) == 2 : 88 | if lookup.get(parts[1]) == None : 89 | program[i] = "\tldc0 at," + parts[1] + "\n" 90 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 91 | program.insert(i+2, "\tldb " + parts[0] + ",r0,at\n") 92 | else : 93 | program[i] = "\tldb " + parts[0] + ",r0," + parts[1] + "\n" 94 | if flds[0] == "stb" and len(parts) == 2 : 95 | if lookup.get(parts[1]) == None : 96 | program[i] = "\tldc0 at," + parts[1] + "\n" 97 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 98 | program.insert(i+2, "\tstb r0," + parts[0] + ",at\n") 99 | else : 100 | program[i] = "\tstb r0," + parts[0] + "," + parts[1] + "\n" 101 | if flds[0] == "ldw" and len(parts) == 2 : 102 | if lookup.get(parts[1]) == None : 103 | program[i] = "\tldc0 at," + parts[1] + "\n" 104 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 105 | program.insert(i+2, "\tldw " + parts[0] + ",r0,at\n") 106 | else : 107 | program[i] = "\tldw " + parts[0] + ",r0," + parts[1] + "\n" 108 | if flds[0] == "stw" and len(parts) == 2 : 109 | if lookup.get(parts[1]) == None : 110 | program[i] = "\tldc0 at," + parts[1] + "\n" 111 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 112 | program.insert(i+2, "\tstw r0," + parts[0] + ",at\n") 113 | else : 114 | program[i] = "\tstw r0," + parts[0] + "," + parts[1] + "\n" 115 | if flds[0] == "bez" and len(parts) == 2 : 116 | if lookup.get(parts[1]) == None : 117 | if is_number(parts[1]) == False : 118 | program[i] = "\tldc0 at," + parts[1] + "\n" 119 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 120 | program.insert(i+2, "\tbez r0," + parts[0] + ",at\n") 121 | else : 122 | program[i] = "\tbez r0," + parts[0] + "," + parts[1] + "\n" 123 | if flds[0] == "bnz" and len(parts) == 2 : 124 | if lookup.get(parts[1]) == None : 125 | if is_number(parts[1]) == False : 126 | program[i] = "\tldc0 at," + parts[1] + "\n" 127 | program.insert(i+1, "\tldc1 at," + parts[1] + "\n") 128 | program.insert(i+2, "\tbnz r0," + parts[0] + ",at\n") 129 | else : 130 | program[i] = "\tbnz r0," + parts[0] + "," + parts[1] + "\n" 131 | if flds[0] == "lsrm" and len(parts) == 2 and is_number(parts[1]) == False : 132 | program[i] = "\tlsr " + parts[0] + "," + parts[0] + ",r0\n" 133 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 134 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 135 | if flds[0] == "asrm" and len(parts) == 2 and is_number(parts[1]) == False : 136 | program[i] = "\tasr " + parts[0] + "," + parts[0] + ",r0\n" 137 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 138 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 139 | if flds[0] == "lslm" and len(parts) == 2 and is_number(parts[1]) == False : 140 | program[i] = "\tadd " + parts[0] + "," + parts[0] + "," + + parts[0] + "\n" 141 | program.insert(i+1, "\tsub " + parts[1] + ",1\n") 142 | program.insert(i+2, "\tbnz " + parts[1] + ",-6\n") 143 | i += 1 144 | 145 | def pass2(program) : 146 | "determine addresses for labels and add to the lookup dictionary" 147 | global lookup 148 | pc = 0 149 | for lin in program : 150 | flds = lin.split() 151 | 152 | if not flds : continue # just an empty line 153 | if lin[0] > ' ' : 154 | symb = flds[0] # a symbol - save its address in lookup 155 | lookup[symb] = pc 156 | textsym.insert(END, "%s" % tohex(pc) + ' ' + str(symb)) 157 | flds2 = ' '.join(flds[1:]) 158 | if flds2 : 159 | if flds2[0] == '"' and flds2[-1] == '"' : 160 | flds2 = lin 161 | flds2 = flds2[1:-1] 162 | flds2 = flds2.replace("\\t", chr(0x09)) 163 | flds2 = flds2.replace("\\n", chr(0x0a)) 164 | flds2 = flds2.replace("\\r", chr(0x0d)) 165 | while (flds2[0] != '"') : 166 | flds2 = flds2[1:] 167 | flds2 = flds2[1:] + '\0' 168 | while (len(flds2) % 2) != 0 : 169 | flds2 = flds2 + '\0' 170 | pc = pc + len(flds2) 171 | else: 172 | flds = flds[1:] 173 | for f in flds : 174 | pc = pc + 2 175 | else : 176 | pc = pc + 2 177 | 178 | def assemble(flds) : 179 | "assemble instruction to machine code" 180 | opval = codes.get(flds[0]) 181 | symb = lookup.get(flds[0]) 182 | if symb != None : 183 | return symb 184 | else : 185 | if opval == None : return int(flds[0], 0) # just a number (prefix can be 0x.. 0o.. 0b..) 186 | parts = flds[1].split(',') # break opcode fields 187 | 188 | if len(parts) == 2 : 189 | parts = [0,parts[0],parts[1]] 190 | if (flds[0] == "ldc0") : # ldc0 .. ldc1 are special steps of ldc 191 | return (opval | 0x0800 | (getval(parts[1]) << 8) | ((getval(parts[2]) >> 8) & 0xff)) 192 | else : 193 | return (opval | 0x0800 | (getval(parts[1]) << 8) | (getval(parts[2]) & 0xff)) 194 | if len(parts) == 3 : 195 | parts = [0,parts[0],parts[1],parts[2]] 196 | return (opval | (getval(parts[1]) << 8) | (getval(parts[2]) << 5) | (getval(parts[3]) << 2)) 197 | 198 | def pass3(program) : 199 | "translate assembly code and symbols to machine code" 200 | pc = 0 201 | code = "" 202 | 203 | for lin in program : 204 | if lin == '' : continue 205 | flds = lin.split() 206 | 207 | if lin[0] > ' ' : flds = flds[1:] # drop symbol if there is one 208 | if not flds : continue 209 | try : 210 | flds2 = ' '.join(flds) 211 | if flds2[0] == '"' and flds2[-1] == '"' : 212 | flds2 = lin 213 | flds2 = flds2[1:-1] 214 | flds2 = flds2.replace("\\t", chr(0x09)) 215 | flds2 = flds2.replace("\\n", chr(0x0a)) 216 | flds2 = flds2.replace("\\r", chr(0x0d)) 217 | while (flds2[0] != '"') : 218 | flds2 = flds2[1:] 219 | flds2 = flds2[1:] + '\0' 220 | while (len(flds2) % 2) != 0 : 221 | flds2 = flds2 + '\0' 222 | flds3 = '' 223 | while True : 224 | flds3 += (str((int(ord(flds2[0])) << 8) | int(ord(flds2[1])))) + ' ' 225 | flds2 = flds2[2:] 226 | if flds2 == '' : break 227 | flds3 = flds3.split() 228 | 229 | instruction = assemble(flds3) 230 | code += ("%04x %s\n" % (pc, tohex(instruction))) 231 | pc = pc + 2 232 | flds3 = flds3[1:] 233 | for f in flds3 : 234 | instruction = assemble(flds3) 235 | code += ("%04x %s\n" % (pc, tohex(instruction))) 236 | pc = pc + 2 237 | flds3 = flds3[1:] 238 | flds = '' 239 | else : 240 | if codes.get(flds[0]) == None : 241 | data = assemble(flds) 242 | code += ("%04x %s\n" % (pc, tohex(data))) 243 | pc = pc + 2 244 | flds = flds[1:] 245 | for f in flds : 246 | data = assemble(flds) 247 | code += ("%04x %s\n" % (pc, tohex(data))) 248 | pc = pc + 2 249 | flds = flds[1:] 250 | else : 251 | instruction = assemble(flds) 252 | code += ("%04x %s\n" % (pc, tohex(instruction))) 253 | pc = pc + 2 254 | except : 255 | code += ("???? %s" % lin) 256 | return code 257 | 258 | def check(program) : 259 | for lin in program : 260 | flds = lin.split() 261 | 262 | if len(flds) != 2 and flds != [] : 263 | return 1 264 | for f in flds : 265 | if f == '****' : 266 | return 1 267 | return 0 268 | 269 | def load(program) : 270 | global memory 271 | codes = { 272 | 0x0000:"and", 0x1000:"or", 0x2000:"xor", 0x3000:"slt", 273 | 0x4000:"sltu", 0x5000:"add", 0x5001:"adc", 0x6000:"sub", 274 | 0x6001:"sbc", 0x8000:"ldr", 0x9000:"ldc", 0xa000:"lsr", 275 | 0xa001:"asr", 0xa002:"ror", 0x0002:"ldb", 0x1002:"stb", 276 | 0x4002:"ldw", 0x5002:"stw", 0xc000:"bez", 0xd000:"bnz" 277 | } 278 | memory = [] 279 | 280 | textdump.delete(0, END) 281 | lines = 0 282 | # load program into memory 283 | for lin in program : 284 | flds = lin.split() 285 | 286 | data = int(flds[1], 16) 287 | memory.append(data) 288 | if (data & 0x0800) : 289 | if (data & 0xf000) in codes : 290 | textdump.insert(END, lin + " %s r%d,%d" % (codes[data & 0xf000], (data & 0x0700) >> 8, (data & 0x00ff))) 291 | else : 292 | textdump.insert(END, lin + " ???") 293 | else : 294 | if (data & 0xf003) in codes : 295 | textdump.insert(END, lin + " %s r%d,r%d,r%d" % (codes[data & 0xf003], (data & 0x0700) >> 8, (data & 0x00e0) >> 5, (data & 0x001c) >> 2)) 296 | else : 297 | textdump.insert(END, lin + " ???") 298 | lines += 1 299 | out.insert(END, " done. Program size: " + str(len(memory) * 2) + " bytes (code + data).\n") 300 | out.see(END) 301 | 302 | # set the stack limit to the end of program section 303 | context[9] = (len(memory) * 2) + 2 304 | # reset breakpoint 305 | context[10] = context[9] 306 | 307 | # fill the rest of memory with zeroes 308 | for i in range(lines, 28672) : 309 | memory.append(0) 310 | reset() 311 | 312 | def loaderror(program) : 313 | global memory 314 | codes = { 315 | 0x0000:"and", 0x1000:"or", 0x2000:"xor", 0x3000:"slt", 316 | 0x4000:"sltu", 0x5000:"add", 0x5001:"adc", 0x6000:"sub", 317 | 0x6001:"sbc", 0x8000:"ldr", 0x9000:"ldc", 0xa000:"lsr", 318 | 0xa001:"asr", 0xa002:"ror", 0x0002:"ldb", 0x1002:"stb", 319 | 0x4002:"ldw", 0x5002:"stw", 0xc000:"bez", 0xd000:"bnz" 320 | } 321 | memory = [] 322 | 323 | textdump.delete(0, END) 324 | lines = 0 325 | # load program into memory 326 | for lin in program : 327 | flds = lin.split() 328 | 329 | try : 330 | data = int(flds[1], 16) 331 | if (data & 0x0800) : 332 | if (data & 0xf000) in codes : 333 | textdump.insert(END, lin + " %s r%d,%d" % (codes[data & 0xf000], (data & 0x0700) >> 8, (data & 0x00ff))) 334 | else : 335 | textdump.insert(END, lin + " ???") 336 | else : 337 | if (data & 0xf003) in codes : 338 | textdump.insert(END, lin + " %s r%d,r%d,r%d" % (codes[data & 0xf003], (data & 0x0700) >> 8, (data & 0x00e0) >> 5, (data & 0x001c) >> 2)) 339 | else : 340 | textdump.insert(END, lin + " ???") 341 | except : 342 | textdump.insert(END, lin) 343 | lines += 1 344 | out.insert(END, " program has errors.\n") 345 | out.see(END) 346 | reset() 347 | 348 | 349 | def assembler() : 350 | global lookup 351 | out.insert(END, "\nAssembling...") 352 | out.see(END) 353 | source_program = str(textasm.get('1.0', 'end')) 354 | textsym.delete(0, END) 355 | program = source_program.splitlines() 356 | 357 | lookup = { 358 | "r0":0, "r1":1, "r2":2, "r3":3, 359 | "r4":4, "r5":5, "r6":6, "r7":7, 360 | "at":0, "sr":5, "lr":6, "sp":7 361 | } 362 | 363 | pass1(program) 364 | pass2(program) 365 | code = pass3(program).splitlines() 366 | 367 | if (check(code)) : 368 | loaderror(code) 369 | else : 370 | load(code) 371 | 372 | # 373 | # simulator and user interface 374 | # 375 | context = [ 376 | 0x0000, 0x0000, 0x0000, 0x0000, # r0 - r3 377 | 0x0000, 0x0000, 0x0000, 0xdffe, # r4 - r7 378 | 0x0000, 0x0000, 0x0000 # pc, stack limit, breakpoint 379 | ] 380 | 381 | carry = 0 382 | memory = [] 383 | terminput = [] 384 | 385 | cycles = 0 386 | cycle_delay = 1 387 | RUNNING = -1 388 | STOPPED = -2 389 | machine = STOPPED 390 | 391 | reg_names = ['r0 (at) : ', 'r1 : ', 'r2 : ', 'r3 : ', 'r4 : ', 'r5 (sr) : ', 'r6 (lr) : ', 'r7 (sp) : ', '\nPC : '] 392 | 393 | def cycle() : 394 | global carry, cycles, terminput 395 | pc = context[8] 396 | # fetch an instruction from memory 397 | instruction = memory[pc >> 1] 398 | 399 | # predecode the instruction (extract opcode fields) 400 | opc = (instruction & 0xf000) >> 12 401 | imm = (instruction & 0x0800) >> 11 402 | rst = (instruction & 0x0700) >> 8 403 | rs1 = (instruction & 0x00e0) >> 5 404 | rs2 = (instruction & 0x001c) >> 2 405 | op2 = instruction & 0x0003 406 | immediate = instruction & 0x00ff 407 | 408 | # it's halt and catch fire, halt the simulator 409 | if instruction == 0x0003 : return 0 410 | 411 | # decode and execute 412 | if imm == 0 : 413 | if context[rs1] > 0x7fff : rs1 = context[rs1] - 0x10000 414 | else : rs1 = context[rs1] 415 | if context[rs2] > 0x7fff : rs2 = context[rs2] - 0x10000 416 | else : rs2 = context[rs2] 417 | else : 418 | if context[rst] > 0x7fff : rs1 = context[rst] - 0x10000 419 | else : rs1 = context[rst] 420 | if immediate > 0x7f : immediate -= 0x100 421 | rs2 = immediate 422 | 423 | if (opc == 10) : 424 | if op2 == 0 : context[rst] = (rs1 & 0xffff) >> 1 425 | elif op2 == 1 : context[rst] = rs1 >> 1 426 | elif op2 == 2 : context[rst] = (carry << 15) | ((rs1 & 0xffff) >> 1) 427 | else : 428 | out.insert(END, ("\nInvalid shift instruction at %04x.\n" % context[8])) 429 | out.see(END) 430 | carry = rs1 & 1 431 | elif ((imm == 0 and (op2 == 0 or op2 == 1)) or imm == 1) : 432 | if opc == 0 : 433 | if (imm == 1) : rs2 &= 0xff 434 | context[rst] = rs1 & rs2 435 | elif opc == 1 : 436 | if (imm == 1) : rs2 &= 0xff 437 | context[rst] = rs1 | rs2 438 | elif opc == 2 : context[rst] = rs1 ^ rs2 439 | elif opc == 3 : 440 | if rs1 < rs2 : context[rst] = 1 441 | else : context[rst] = 0 442 | elif opc == 4 : 443 | if (rs1 & 0xffff) < (rs2 & 0xffff) : context[rst] = 1 444 | else : context[rst] = 0 445 | elif opc == 5 : 446 | if (imm == 0 and op2 == 1) : 447 | context[rst] = (rs1 & 0xffff) + (rs2 & 0xffff) + carry; 448 | else : 449 | context[rst] = (rs1 & 0xffff) + (rs2 & 0xffff) 450 | carry = (context[rst] & 0x10000) >> 16 451 | elif opc == 6 : 452 | if (imm == 0 and op2 == 1) : 453 | context[rst] = (rs1 & 0xffff) - (rs2 & 0xffff) - carry; 454 | else : 455 | context[rst] = (rs1 & 0xffff) - (rs2 & 0xffff) 456 | carry = (context[rst] & 0x10000) >> 16 457 | elif opc == 8 : context[rst] = rs2 458 | elif opc == 9 : context[rst] = (context[rst] << 8) | (rs2 & 0xff) 459 | elif opc == 12 : 460 | if (imm == 1) : 461 | if rs1 == 0 : pc = pc + rs2; 462 | else : 463 | if rs1 == 0 : pc = rs2 - 2 464 | elif opc == 13 : 465 | if (imm == 1) : 466 | if rs1 != 0 : pc = pc + rs2; 467 | else : 468 | if rs1 != 0 : pc = rs2 - 2 469 | else : 470 | out.insert(END, ("\nInvalid computation / branch instruction at %04x.\n" % context[8])) 471 | out.see(END) 472 | elif (imm == 0 and op2 == 2) : 473 | if opc == 0 : 474 | if (rs2 & 0x1) : 475 | byte = memory[(rs2 & 0xffff) >> 1] & 0xff 476 | else : 477 | byte = memory[(rs2 & 0xffff) >> 1] >> 8 478 | 479 | if byte > 0x7f : context[rst] = byte - 0x100 480 | else : context[rst] = byte 481 | elif opc == 1 : 482 | if (rs2 & 0x1) : 483 | memory[(rs2 & 0xffff) >> 1] = (memory[(rs2 & 0xffff) >> 1] & 0xff00) | (rs1 & 0xff) 484 | else : 485 | memory[(rs2 & 0xffff) >> 1] = (memory[(rs2 & 0xffff) >> 1] & 0x00ff) | ((rs1 & 0xff) << 8) 486 | elif opc == 4 : 487 | if (rs2 & 0xffff) == 0xf004 : # emulate an input character device (address: 61444) 488 | if len(terminput) == 0 : 489 | terminput = simpledialog.askstring("Input", "string val:") + '\0'; 490 | result = int(ord(terminput[0])) 491 | terminput = terminput[1:] 492 | context[rst] = result 493 | elif (rs2 & 0xffff) == 0xf006 : # emulate an input integer device (address: 61446) 494 | result = simpledialog.askstring("Input", "int val:") 495 | if result : 496 | context[rst] = int(result) 497 | else : 498 | context[rst] = memory[(rs2 & 0xffff) >> 1] 499 | elif opc == 5 : 500 | if (rs2 & 0xffff) == 0xf000 : # emulate an output character device (address: 61440) 501 | out.insert(END, chr(rs1 & 0xff)) 502 | out.see(END) 503 | elif (rs2 & 0xffff) == 0xf002 : # emulate an output integer device (address: 61442) 504 | out.insert(END, str(rs1)) 505 | out.see(END) 506 | else : 507 | memory[(rs2 & 0xffff) >> 1] = rs1 508 | else : 509 | out.insert(END, ("\nInvalid load/store instruction at %04x.\n" % context[8])) 510 | out.see(END) 511 | else : 512 | out.insert(END, ("\nInvalid instruction at %04x.\n" % context[8])) 513 | out.see(END) 514 | 515 | # increment the program counter 516 | pc = pc + 2 517 | context[8] = pc 518 | # fix the stored word to the matching hardware size 519 | context[rst] &= 0xffff 520 | 521 | cycles += 1 522 | # update register labels 523 | refresh_regs() 524 | 525 | return 1 526 | 527 | 528 | def newprogram() : 529 | textasm.delete('1.0', END) 530 | textasm.delete('1.0', END) 531 | 532 | def openprogram() : 533 | name = filedialog.askopenfilename(defaultextension=".asm", filetypes=(("Assembly file", "*.asm"),("All Files", "*.*"))) 534 | 535 | if (name) : 536 | program = open(name, "r") 537 | if program : 538 | program.seek(0) 539 | textasm.delete('1.0', END) 540 | for lin in program : 541 | textasm.insert(END, lin) 542 | program.close() 543 | 544 | def openadditionalprogram() : 545 | name = filedialog.askopenfilename(defaultextension=".asm", filetypes=(("Assembly file", "*.asm"),("All Files", "*.*"))) 546 | if (name) : 547 | program = open(name, "r") 548 | if program : 549 | program.seek(0) 550 | textasm.insert(END, "\n") 551 | for lin in program : 552 | textasm.insert(END, lin) 553 | program.close() 554 | 555 | def saveprogram() : 556 | name = filedialog.asksaveasfilename(defaultextension=".asm", filetypes=(("Assembly file", "*.asm"),("All Files", "*.*"))) 557 | if (name) : 558 | program = open(name, "w") 559 | if program : 560 | program.write(textasm.get('1.0', 'end')) 561 | program.close() 562 | 563 | def reset() : 564 | global cycles, machine 565 | # clear GPRs 566 | for i in range(8) : 567 | context[i] = 0 568 | # set the stack pointer to the last memory position 569 | context[7] = len(memory) * 2 - 2 570 | # set pc to zero 571 | context[8] = 0 572 | # reset breakpoint 573 | machine = STOPPED 574 | 575 | cycles = 0 576 | refresh_regs() 577 | textdump.focus() 578 | textdump.activate(0) 579 | textdump.see(0) 580 | 581 | def run() : 582 | global machine 583 | 584 | if len(memory) > 0 : 585 | if machine == STOPPED : 586 | machine = RUNNING 587 | run_step() 588 | else : 589 | showerror("Error", "No program in memory.") 590 | 591 | def run_step() : 592 | inst = memory[context[8] >> 1] 593 | last_pc = context[8] 594 | 595 | if cycle() : 596 | textdump.focus() 597 | textdump.activate(context[8] >> 1) 598 | textdump.see(context[8] >> 1) 599 | 600 | if context[8] == context[10] : 601 | out.insert(END, ("\nBreakpoint at %04x.\n" % context[8])) 602 | out.see(END) 603 | else: 604 | if context[7] < context[9] : 605 | out.insert(END, ("\nStack overflow detected at %04x.\n" % context[8])) 606 | out.see(END) 607 | else : 608 | if machine != STOPPED : 609 | root.after(cycle_delay, run_step) 610 | else : 611 | out.insert(END, ("\nProgram halted at %04x.\n" % context[8])) 612 | out.see(END) 613 | 614 | def stop() : 615 | global machine 616 | machine = STOPPED 617 | 618 | def step() : 619 | if len(memory) > 0 : 620 | stop() 621 | inst = memory[context[8] >> 1] 622 | last_pc = context[8] 623 | 624 | if cycle() : 625 | textdump.focus() 626 | textdump.activate(context[8] >> 1) 627 | textdump.see(context[8] >> 1) 628 | 629 | if context[7] < context[9] : 630 | out.insert(END, ("\nStack overflow detected at %04x.\n" % context[8])) 631 | out.see(END) 632 | else : 633 | out.insert(END, ("\nProgram halted at %04x.\n" % context[8])) 634 | out.see(END) 635 | else : 636 | showerror("Error", "No program in memory.") 637 | 638 | def refresh_regs() : 639 | for i in range(9) : 640 | root.reg_label[i].set(reg_names[i] + tohex(context[i])) 641 | root.cycle.set("Cycle: " + str(cycles) + "\n") 642 | 643 | def set_breakpoint() : 644 | result = simpledialog.askstring("Set breakpoint", "Program address (hex):") 645 | if result : 646 | context[10] = int(result, 16) 647 | 648 | def set_cycledelay() : 649 | global cycle_delay 650 | result = simpledialog.askstring("Set machine cycle delay", "Delay (ms):") 651 | if int(result) > 0 : 652 | cycle_delay = int(result) 653 | 654 | def clear_term() : 655 | out.delete('1.0', END) 656 | 657 | def memdump() : 658 | memwindow = Toplevel(root) 659 | memwindow.title("Memory dump") 660 | memwindow.geometry("600x652+50+50") 661 | memwindow.resizable(0,0) 662 | mem_dump = Listbox(memwindow, height=24, width=65, font=('Courier', 11)) 663 | mem_dumpscroll = Scrollbar(memwindow, command=mem_dump.yview) 664 | mem_dump.configure(yscrollcommand=mem_dumpscroll.set) 665 | mem_dump.pack(side=LEFT, fill=BOTH) 666 | mem_dumpscroll.pack(side=LEFT, fill=Y) 667 | 668 | k = 0 669 | while k < len(memory) * 2 : 670 | dump_line = str(tohex(k)) + ': ' 671 | l = 0 672 | while l < 8 : 673 | dump_line = dump_line + tohex(memory[(k >> 1) + l]) + ' ' 674 | l += 1 675 | dump_line += '|' 676 | l = 0 677 | while l < 8 : 678 | ch1 = memory[(k >> 1) + l] >> 8 679 | ch2 = memory[(k >> 1) + l] & 0xff 680 | if ((ch1 >= 32) and (ch1 <= 126)) : 681 | dump_line += chr(ch1) 682 | else : 683 | dump_line += '.' 684 | if ((ch2 >= 32) and (ch2 <= 126)) : 685 | dump_line += chr(ch2) 686 | else : 687 | dump_line += '.' 688 | l += 1 689 | dump_line += '|' 690 | mem_dump.insert(END, dump_line) 691 | k += 16 692 | 693 | root = tkinter.Tk() 694 | menu = Menu(root) 695 | root.geometry("1000x692+30+30") 696 | root.resizable(0,0) 697 | root.config(menu=menu) 698 | 699 | programmenu = Menu(menu) 700 | menu.add_cascade(label="Program", menu=programmenu) 701 | programmenu.add_command(label="New", command=newprogram) 702 | programmenu.add_command(label="Load", command=openprogram) 703 | programmenu.add_command(label="Load additional file", command=openadditionalprogram) 704 | programmenu.add_command(label="Save as", command=saveprogram) 705 | programmenu.add_separator() 706 | programmenu.add_command(label="Assemble", command=assembler) 707 | programmenu.add_separator() 708 | programmenu.add_command(label="Exit", command=root.quit) 709 | 710 | machinemenu = Menu(menu) 711 | menu.add_cascade(label="Machine", menu=machinemenu) 712 | machinemenu.add_command(label="Reset", command=reset) 713 | machinemenu.add_command(label="Stop", command=stop) 714 | machinemenu.add_command(label="Run", command=run) 715 | machinemenu.add_command(label="Step", command=step) 716 | machinemenu.add_separator() 717 | machinemenu.add_command(label="Set breakpoint", command=set_breakpoint) 718 | machinemenu.add_command(label="Set machine cycle delay", command=set_cycledelay) 719 | machinemenu.add_command(label="Clear terminal", command=clear_term) 720 | machinemenu.add_command(label="Memory dump", command=memdump) 721 | 722 | topframe = Frame(root) 723 | topframe.pack() 724 | middleframe = Frame(root) 725 | middleframe.pack() 726 | bottomframe = Frame(root) 727 | bottomframe.pack() 728 | 729 | Label(topframe, text="Program:", width=46, font=('Courier', 11, 'bold'), anchor=W).pack(side=LEFT) 730 | Label(topframe, text="Object code / disassembly:", width=28, font=('Courier', 11, 'bold'), anchor=W).pack(side=LEFT) 731 | Label(topframe, text="Symbol table:", width=22, font=('Courier', 11, 'bold'), anchor=W).pack(side=LEFT) 732 | Label(topframe, text="Registers:", width=16, font=('Courier', 11, 'bold'), anchor=W).pack(side=LEFT) 733 | 734 | asmxscrollbar = Scrollbar(middleframe, orient=HORIZONTAL) 735 | asmyscrollbar = Scrollbar(middleframe) 736 | textasm = Text(middleframe, wrap=NONE, xscrollcommand=asmxscrollbar.set, yscrollcommand=asmyscrollbar.set, height=24, width=44, font=('Courier', 11)) 737 | asmxscrollbar.pack(side=BOTTOM, fill=X) 738 | textasm.pack(side=LEFT, fill=BOTH) 739 | asmyscrollbar.pack(side=LEFT, fill=Y) 740 | asmxscrollbar.config(command=textasm.xview) 741 | asmyscrollbar.config(command=textasm.yview) 742 | 743 | textdump = Listbox(middleframe, height=24, width=26, font=('Courier', 11)) 744 | textdumpscroll = Scrollbar(middleframe, command=textdump.yview) 745 | textdump.configure(yscrollcommand=textdumpscroll.set) 746 | textdump.pack(side=LEFT, fill=BOTH) 747 | textdumpscroll.pack(side=LEFT, fill=Y) 748 | 749 | textsym = Listbox(middleframe, height=24, width=18, font=('Courier', 11)) 750 | textsymscroll = Scrollbar(middleframe, command=textsym.yview) 751 | textsym.configure(yscrollcommand=textsymscroll.set) 752 | textsym.pack(side=LEFT, fill=BOTH) 753 | textsymscroll.pack(side=LEFT, fill=Y) 754 | 755 | root.reg_label = [] 756 | for i in range(9) : 757 | root.reg_label.append(StringVar()) 758 | 759 | for i in range(9) : 760 | Label(middleframe, textvariable=root.reg_label[i], width=25, font=('Courier', 11)).pack() 761 | 762 | Label(middleframe, text="\nControl:\n", width=25, font=('Courier', 11, 'bold')).pack() 763 | 764 | root.cycle = StringVar() 765 | Label(middleframe, textvariable=root.cycle, width=25, font=('Courier', 11)).pack() 766 | 767 | refresh_regs() 768 | 769 | Button(middleframe, text='Reset', width=14, command=reset).pack() 770 | Button(middleframe, text='Stop', width=14, command=stop).pack() 771 | Button(middleframe, text='Run', width=14, command=run).pack() 772 | Button(middleframe, text='Step', width=14, command=step).pack() 773 | 774 | out = Text(bottomframe, height=14, width=122, font=('Courier', 10)) 775 | outscroll = Scrollbar(bottomframe, command=out.yview) 776 | out.configure(yscrollcommand=outscroll.set) 777 | out.pack(side=LEFT, fill=BOTH) 778 | outscroll.pack(side=LEFT, fill=Y) 779 | 780 | mainloop() 781 | 782 | -------------------------------------------------------------------------------- /manual/viking_manual_pt.log: -------------------------------------------------------------------------------- 1 | This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016/Debian) (preloaded format=pdflatex 2018.10.22) 31 DEC 2018 12:54 2 | entering extended mode 3 | restricted \write18 enabled. 4 | %&-line parsing enabled. 5 | **viking_manual_pt.tex 6 | (./viking_manual_pt.tex 7 | LaTeX2e <2017/01/01> patch level 3 8 | Babel <3.9r> and hyphenation patterns for 83 language(s) loaded. 9 | (/usr/share/texlive/texmf-dist/tex/latex/extsizes/extreport.cls 10 | Document Class: extreport 1996/10/08 v1.0 Non Standard LaTeX document class 11 | (/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo 12 | File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option) 13 | ) 14 | (/usr/share/texlive/texmf-dist/tex/latex/base/exscale.sty 15 | Package: exscale 2014/09/29 v2.1h Standard LaTeX package exscale 16 | LaTeX Font Info: Redeclaring symbol font `largesymbols' on input line 57. 17 | LaTeX Font Info: Overwriting symbol font `largesymbols' in version `normal' 18 | (Font) OMX/cmex/m/n --> OMX/cmex/m/n on input line 57. 19 | LaTeX Font Info: Overwriting symbol font `largesymbols' in version `bold' 20 | (Font) OMX/cmex/m/n --> OMX/cmex/m/n on input line 57. 21 | \big@size=\dimen102 22 | ) 23 | \c@part=\count79 24 | \c@chapter=\count80 25 | \c@section=\count81 26 | \c@subsection=\count82 27 | \c@subsubsection=\count83 28 | \c@paragraph=\count84 29 | \c@subparagraph=\count85 30 | \c@figure=\count86 31 | \c@table=\count87 32 | \abovecaptionskip=\skip41 33 | \belowcaptionskip=\skip42 34 | \bibindent=\dimen103 35 | ) 36 | (/usr/share/texlive/texmf-dist/tex/latex/geometry/geometry.sty 37 | Package: geometry 2010/09/12 v5.6 Page Geometry 38 | 39 | (/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty 40 | Package: keyval 2014/10/28 v1.15 key=value parser (DPC) 41 | \KV@toks@=\toks14 42 | ) 43 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifpdf.sty 44 | Package: ifpdf 2016/05/14 v3.1 Provides the ifpdf switch 45 | ) 46 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifvtex.sty 47 | Package: ifvtex 2016/05/16 v1.6 Detect VTeX and its facilities (HO) 48 | Package ifvtex Info: VTeX not detected. 49 | ) 50 | (/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty 51 | Package: ifxetex 2010/09/12 v0.6 Provides ifxetex conditional 52 | ) 53 | \Gm@cnth=\count88 54 | \Gm@cntv=\count89 55 | \c@Gm@tempcnt=\count90 56 | \Gm@bindingoffset=\dimen104 57 | \Gm@wd@mp=\dimen105 58 | \Gm@odd@mp=\dimen106 59 | \Gm@even@mp=\dimen107 60 | \Gm@layoutwidth=\dimen108 61 | \Gm@layoutheight=\dimen109 62 | \Gm@layouthoffset=\dimen110 63 | \Gm@layoutvoffset=\dimen111 64 | \Gm@dimlist=\toks15 65 | ) 66 | (/usr/share/texlive/texmf-dist/tex/latex/setspace/setspace.sty 67 | Package: setspace 2011/12/19 v6.7a set line spacing 68 | ) 69 | (/usr/share/texlive/texmf-dist/tex/latex/fancyhdr/fancyhdr.sty 70 | Package: fancyhdr 2016/09/06 3.8 Extensive control of page headers and footers 71 | \fancy@headwidth=\skip43 72 | \f@ncyO@elh=\skip44 73 | \f@ncyO@erh=\skip45 74 | \f@ncyO@olh=\skip46 75 | \f@ncyO@orh=\skip47 76 | \f@ncyO@elf=\skip48 77 | \f@ncyO@erf=\skip49 78 | \f@ncyO@olf=\skip50 79 | \f@ncyO@orf=\skip51 80 | ) 81 | (/usr/share/texlive/texmf-dist/tex/latex/tocloft/tocloft.sty 82 | Package: tocloft 2013/05/02 v2.3f parameterised ToC, etc., typesetting 83 | Package tocloft Info: The document has chapter divisions on input line 44. 84 | \cftparskip=\skip52 85 | \cftbeforetoctitleskip=\skip53 86 | \cftaftertoctitleskip=\skip54 87 | \cftbeforepartskip=\skip55 88 | \cftpartnumwidth=\skip56 89 | \cftpartindent=\skip57 90 | \cftbeforechapskip=\skip58 91 | \cftchapindent=\skip59 92 | \cftchapnumwidth=\skip60 93 | \cftbeforesecskip=\skip61 94 | \cftsecindent=\skip62 95 | \cftsecnumwidth=\skip63 96 | \cftbeforesubsecskip=\skip64 97 | \cftsubsecindent=\skip65 98 | \cftsubsecnumwidth=\skip66 99 | \cftbeforesubsubsecskip=\skip67 100 | \cftsubsubsecindent=\skip68 101 | \cftsubsubsecnumwidth=\skip69 102 | \cftbeforeparaskip=\skip70 103 | \cftparaindent=\skip71 104 | \cftparanumwidth=\skip72 105 | \cftbeforesubparaskip=\skip73 106 | \cftsubparaindent=\skip74 107 | \cftsubparanumwidth=\skip75 108 | \cftbeforeloftitleskip=\skip76 109 | \cftafterloftitleskip=\skip77 110 | \cftbeforefigskip=\skip78 111 | \cftfigindent=\skip79 112 | \cftfignumwidth=\skip80 113 | \c@lofdepth=\count91 114 | \c@lotdepth=\count92 115 | \cftbeforelottitleskip=\skip81 116 | \cftafterlottitleskip=\skip82 117 | \cftbeforetabskip=\skip83 118 | \cfttabindent=\skip84 119 | \cfttabnumwidth=\skip85 120 | ) 121 | (/usr/share/texlive/texmf-dist/tex/latex/base/fixltx2e.sty 122 | Package: fixltx2e 2016/12/29 v2.1a fixes to LaTeX (obsolete) 123 | Applying: [2015/01/01] Old fixltx2e package on input line 46. 124 | 125 | 126 | Package fixltx2e Warning: fixltx2e is not required with releases after 2015 127 | (fixltx2e) All fixes are now in the LaTeX kernel. 128 | (fixltx2e) See the latexrelease package for details. 129 | 130 | Already applied: [0000/00/00] Old fixltx2e package on input line 53. 131 | ) (/usr/share/texlive/texmf-dist/tex/latex/enumitem/enumitem.sty 132 | Package: enumitem 2011/09/28 v3.5.2 Customized lists 133 | \labelindent=\skip86 134 | \enit@outerparindent=\dimen112 135 | \enit@toks=\toks16 136 | \enit@inbox=\box26 137 | \enitdp@description=\count93 138 | ) 139 | (/usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty 140 | Package: babel 2016/04/23 3.9r The Babel package 141 | 142 | (/usr/share/texlive/texmf-dist/tex/generic/babel-portuges/portuges.ldf 143 | Language: portuges 2008/03/18 v1.2q Portuguese support from the babel system 144 | 145 | (/usr/share/texlive/texmf-dist/tex/generic/babel/babel.def 146 | File: babel.def 2016/04/23 3.9r Babel common definitions 147 | \babel@savecnt=\count94 148 | \U@D=\dimen113 149 | ) 150 | \l@brazilian = a dialect from \language\l@portuges 151 | Package babel Info: Making " an active character on input line 145. 152 | )) 153 | (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty 154 | Package: inputenc 2015/03/17 v1.2c Input encoding file 155 | \inpenc@prehook=\toks17 156 | \inpenc@posthook=\toks18 157 | 158 | (/usr/share/texlive/texmf-dist/tex/latex/base/utf8.def 159 | File: utf8.def 2017/01/28 v1.1t UTF-8 support for inputenc 160 | Now handling font encoding OML ... 161 | ... no UTF-8 mapping file for font encoding OML 162 | Now handling font encoding T1 ... 163 | ... processing UTF-8 mapping file for font encoding T1 164 | 165 | (/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.dfu 166 | File: t1enc.dfu 2017/01/28 v1.1t UTF-8 support for inputenc 167 | defining Unicode char U+00A0 (decimal 160) 168 | defining Unicode char U+00A1 (decimal 161) 169 | defining Unicode char U+00A3 (decimal 163) 170 | defining Unicode char U+00AB (decimal 171) 171 | defining Unicode char U+00AD (decimal 173) 172 | defining Unicode char U+00BB (decimal 187) 173 | defining Unicode char U+00BF (decimal 191) 174 | defining Unicode char U+00C0 (decimal 192) 175 | defining Unicode char U+00C1 (decimal 193) 176 | defining Unicode char U+00C2 (decimal 194) 177 | defining Unicode char U+00C3 (decimal 195) 178 | defining Unicode char U+00C4 (decimal 196) 179 | defining Unicode char U+00C5 (decimal 197) 180 | defining Unicode char U+00C6 (decimal 198) 181 | defining Unicode char U+00C7 (decimal 199) 182 | defining Unicode char U+00C8 (decimal 200) 183 | defining Unicode char U+00C9 (decimal 201) 184 | defining Unicode char U+00CA (decimal 202) 185 | defining Unicode char U+00CB (decimal 203) 186 | defining Unicode char U+00CC (decimal 204) 187 | defining Unicode char U+00CD (decimal 205) 188 | defining Unicode char U+00CE (decimal 206) 189 | defining Unicode char U+00CF (decimal 207) 190 | defining Unicode char U+00D0 (decimal 208) 191 | defining Unicode char U+00D1 (decimal 209) 192 | defining Unicode char U+00D2 (decimal 210) 193 | defining Unicode char U+00D3 (decimal 211) 194 | defining Unicode char U+00D4 (decimal 212) 195 | defining Unicode char U+00D5 (decimal 213) 196 | defining Unicode char U+00D6 (decimal 214) 197 | defining Unicode char U+00D8 (decimal 216) 198 | defining Unicode char U+00D9 (decimal 217) 199 | defining Unicode char U+00DA (decimal 218) 200 | defining Unicode char U+00DB (decimal 219) 201 | defining Unicode char U+00DC (decimal 220) 202 | defining Unicode char U+00DD (decimal 221) 203 | defining Unicode char U+00DE (decimal 222) 204 | defining Unicode char U+00DF (decimal 223) 205 | defining Unicode char U+00E0 (decimal 224) 206 | defining Unicode char U+00E1 (decimal 225) 207 | defining Unicode char U+00E2 (decimal 226) 208 | defining Unicode char U+00E3 (decimal 227) 209 | defining Unicode char U+00E4 (decimal 228) 210 | defining Unicode char U+00E5 (decimal 229) 211 | defining Unicode char U+00E6 (decimal 230) 212 | defining Unicode char U+00E7 (decimal 231) 213 | defining Unicode char U+00E8 (decimal 232) 214 | defining Unicode char U+00E9 (decimal 233) 215 | defining Unicode char U+00EA (decimal 234) 216 | defining Unicode char U+00EB (decimal 235) 217 | defining Unicode char U+00EC (decimal 236) 218 | defining Unicode char U+00ED (decimal 237) 219 | defining Unicode char U+00EE (decimal 238) 220 | defining Unicode char U+00EF (decimal 239) 221 | defining Unicode char U+00F0 (decimal 240) 222 | defining Unicode char U+00F1 (decimal 241) 223 | defining Unicode char U+00F2 (decimal 242) 224 | defining Unicode char U+00F3 (decimal 243) 225 | defining Unicode char U+00F4 (decimal 244) 226 | defining Unicode char U+00F5 (decimal 245) 227 | defining Unicode char U+00F6 (decimal 246) 228 | defining Unicode char U+00F8 (decimal 248) 229 | defining Unicode char U+00F9 (decimal 249) 230 | defining Unicode char U+00FA (decimal 250) 231 | defining Unicode char U+00FB (decimal 251) 232 | defining Unicode char U+00FC (decimal 252) 233 | defining Unicode char U+00FD (decimal 253) 234 | defining Unicode char U+00FE (decimal 254) 235 | defining Unicode char U+00FF (decimal 255) 236 | defining Unicode char U+0100 (decimal 256) 237 | defining Unicode char U+0101 (decimal 257) 238 | defining Unicode char U+0102 (decimal 258) 239 | defining Unicode char U+0103 (decimal 259) 240 | defining Unicode char U+0104 (decimal 260) 241 | defining Unicode char U+0105 (decimal 261) 242 | defining Unicode char U+0106 (decimal 262) 243 | defining Unicode char U+0107 (decimal 263) 244 | defining Unicode char U+0108 (decimal 264) 245 | defining Unicode char U+0109 (decimal 265) 246 | defining Unicode char U+010A (decimal 266) 247 | defining Unicode char U+010B (decimal 267) 248 | defining Unicode char U+010C (decimal 268) 249 | defining Unicode char U+010D (decimal 269) 250 | defining Unicode char U+010E (decimal 270) 251 | defining Unicode char U+010F (decimal 271) 252 | defining Unicode char U+0110 (decimal 272) 253 | defining Unicode char U+0111 (decimal 273) 254 | defining Unicode char U+0112 (decimal 274) 255 | defining Unicode char U+0113 (decimal 275) 256 | defining Unicode char U+0114 (decimal 276) 257 | defining Unicode char U+0115 (decimal 277) 258 | defining Unicode char U+0116 (decimal 278) 259 | defining Unicode char U+0117 (decimal 279) 260 | defining Unicode char U+0118 (decimal 280) 261 | defining Unicode char U+0119 (decimal 281) 262 | defining Unicode char U+011A (decimal 282) 263 | defining Unicode char U+011B (decimal 283) 264 | defining Unicode char U+011C (decimal 284) 265 | defining Unicode char U+011D (decimal 285) 266 | defining Unicode char U+011E (decimal 286) 267 | defining Unicode char U+011F (decimal 287) 268 | defining Unicode char U+0120 (decimal 288) 269 | defining Unicode char U+0121 (decimal 289) 270 | defining Unicode char U+0122 (decimal 290) 271 | defining Unicode char U+0123 (decimal 291) 272 | defining Unicode char U+0124 (decimal 292) 273 | defining Unicode char U+0125 (decimal 293) 274 | defining Unicode char U+0128 (decimal 296) 275 | defining Unicode char U+0129 (decimal 297) 276 | defining Unicode char U+012A (decimal 298) 277 | defining Unicode char U+012B (decimal 299) 278 | defining Unicode char U+012C (decimal 300) 279 | defining Unicode char U+012D (decimal 301) 280 | defining Unicode char U+012E (decimal 302) 281 | defining Unicode char U+012F (decimal 303) 282 | defining Unicode char U+0130 (decimal 304) 283 | defining Unicode char U+0131 (decimal 305) 284 | defining Unicode char U+0132 (decimal 306) 285 | defining Unicode char U+0133 (decimal 307) 286 | defining Unicode char U+0134 (decimal 308) 287 | defining Unicode char U+0135 (decimal 309) 288 | defining Unicode char U+0136 (decimal 310) 289 | defining Unicode char U+0137 (decimal 311) 290 | defining Unicode char U+0139 (decimal 313) 291 | defining Unicode char U+013A (decimal 314) 292 | defining Unicode char U+013B (decimal 315) 293 | defining Unicode char U+013C (decimal 316) 294 | defining Unicode char U+013D (decimal 317) 295 | defining Unicode char U+013E (decimal 318) 296 | defining Unicode char U+0141 (decimal 321) 297 | defining Unicode char U+0142 (decimal 322) 298 | defining Unicode char U+0143 (decimal 323) 299 | defining Unicode char U+0144 (decimal 324) 300 | defining Unicode char U+0145 (decimal 325) 301 | defining Unicode char U+0146 (decimal 326) 302 | defining Unicode char U+0147 (decimal 327) 303 | defining Unicode char U+0148 (decimal 328) 304 | defining Unicode char U+014A (decimal 330) 305 | defining Unicode char U+014B (decimal 331) 306 | defining Unicode char U+014C (decimal 332) 307 | defining Unicode char U+014D (decimal 333) 308 | defining Unicode char U+014E (decimal 334) 309 | defining Unicode char U+014F (decimal 335) 310 | defining Unicode char U+0150 (decimal 336) 311 | defining Unicode char U+0151 (decimal 337) 312 | defining Unicode char U+0152 (decimal 338) 313 | defining Unicode char U+0153 (decimal 339) 314 | defining Unicode char U+0154 (decimal 340) 315 | defining Unicode char U+0155 (decimal 341) 316 | defining Unicode char U+0156 (decimal 342) 317 | defining Unicode char U+0157 (decimal 343) 318 | defining Unicode char U+0158 (decimal 344) 319 | defining Unicode char U+0159 (decimal 345) 320 | defining Unicode char U+015A (decimal 346) 321 | defining Unicode char U+015B (decimal 347) 322 | defining Unicode char U+015C (decimal 348) 323 | defining Unicode char U+015D (decimal 349) 324 | defining Unicode char U+015E (decimal 350) 325 | defining Unicode char U+015F (decimal 351) 326 | defining Unicode char U+0160 (decimal 352) 327 | defining Unicode char U+0161 (decimal 353) 328 | defining Unicode char U+0162 (decimal 354) 329 | defining Unicode char U+0163 (decimal 355) 330 | defining Unicode char U+0164 (decimal 356) 331 | defining Unicode char U+0165 (decimal 357) 332 | defining Unicode char U+0168 (decimal 360) 333 | defining Unicode char U+0169 (decimal 361) 334 | defining Unicode char U+016A (decimal 362) 335 | defining Unicode char U+016B (decimal 363) 336 | defining Unicode char U+016C (decimal 364) 337 | defining Unicode char U+016D (decimal 365) 338 | defining Unicode char U+016E (decimal 366) 339 | defining Unicode char U+016F (decimal 367) 340 | defining Unicode char U+0170 (decimal 368) 341 | defining Unicode char U+0171 (decimal 369) 342 | defining Unicode char U+0172 (decimal 370) 343 | defining Unicode char U+0173 (decimal 371) 344 | defining Unicode char U+0174 (decimal 372) 345 | defining Unicode char U+0175 (decimal 373) 346 | defining Unicode char U+0176 (decimal 374) 347 | defining Unicode char U+0177 (decimal 375) 348 | defining Unicode char U+0178 (decimal 376) 349 | defining Unicode char U+0179 (decimal 377) 350 | defining Unicode char U+017A (decimal 378) 351 | defining Unicode char U+017B (decimal 379) 352 | defining Unicode char U+017C (decimal 380) 353 | defining Unicode char U+017D (decimal 381) 354 | defining Unicode char U+017E (decimal 382) 355 | defining Unicode char U+01CD (decimal 461) 356 | defining Unicode char U+01CE (decimal 462) 357 | defining Unicode char U+01CF (decimal 463) 358 | defining Unicode char U+01D0 (decimal 464) 359 | defining Unicode char U+01D1 (decimal 465) 360 | defining Unicode char U+01D2 (decimal 466) 361 | defining Unicode char U+01D3 (decimal 467) 362 | defining Unicode char U+01D4 (decimal 468) 363 | defining Unicode char U+01E2 (decimal 482) 364 | defining Unicode char U+01E3 (decimal 483) 365 | defining Unicode char U+01E6 (decimal 486) 366 | defining Unicode char U+01E7 (decimal 487) 367 | defining Unicode char U+01E8 (decimal 488) 368 | defining Unicode char U+01E9 (decimal 489) 369 | defining Unicode char U+01EA (decimal 490) 370 | defining Unicode char U+01EB (decimal 491) 371 | defining Unicode char U+01F0 (decimal 496) 372 | defining Unicode char U+01F4 (decimal 500) 373 | defining Unicode char U+01F5 (decimal 501) 374 | defining Unicode char U+0218 (decimal 536) 375 | defining Unicode char U+0219 (decimal 537) 376 | defining Unicode char U+021A (decimal 538) 377 | defining Unicode char U+021B (decimal 539) 378 | defining Unicode char U+0232 (decimal 562) 379 | defining Unicode char U+0233 (decimal 563) 380 | defining Unicode char U+1E02 (decimal 7682) 381 | defining Unicode char U+1E03 (decimal 7683) 382 | defining Unicode char U+200C (decimal 8204) 383 | defining Unicode char U+2010 (decimal 8208) 384 | defining Unicode char U+2011 (decimal 8209) 385 | defining Unicode char U+2012 (decimal 8210) 386 | defining Unicode char U+2013 (decimal 8211) 387 | defining Unicode char U+2014 (decimal 8212) 388 | defining Unicode char U+2015 (decimal 8213) 389 | defining Unicode char U+2018 (decimal 8216) 390 | defining Unicode char U+2019 (decimal 8217) 391 | defining Unicode char U+201A (decimal 8218) 392 | defining Unicode char U+201C (decimal 8220) 393 | defining Unicode char U+201D (decimal 8221) 394 | defining Unicode char U+201E (decimal 8222) 395 | defining Unicode char U+2030 (decimal 8240) 396 | defining Unicode char U+2031 (decimal 8241) 397 | defining Unicode char U+2039 (decimal 8249) 398 | defining Unicode char U+203A (decimal 8250) 399 | defining Unicode char U+2423 (decimal 9251) 400 | defining Unicode char U+1E20 (decimal 7712) 401 | defining Unicode char U+1E21 (decimal 7713) 402 | ) 403 | Now handling font encoding OT1 ... 404 | ... processing UTF-8 mapping file for font encoding OT1 405 | 406 | (/usr/share/texlive/texmf-dist/tex/latex/base/ot1enc.dfu 407 | File: ot1enc.dfu 2017/01/28 v1.1t UTF-8 support for inputenc 408 | defining Unicode char U+00A0 (decimal 160) 409 | defining Unicode char U+00A1 (decimal 161) 410 | defining Unicode char U+00A3 (decimal 163) 411 | defining Unicode char U+00AD (decimal 173) 412 | defining Unicode char U+00B8 (decimal 184) 413 | defining Unicode char U+00BF (decimal 191) 414 | defining Unicode char U+00C5 (decimal 197) 415 | defining Unicode char U+00C6 (decimal 198) 416 | defining Unicode char U+00D8 (decimal 216) 417 | defining Unicode char U+00DF (decimal 223) 418 | defining Unicode char U+00E6 (decimal 230) 419 | defining Unicode char U+00EC (decimal 236) 420 | defining Unicode char U+00ED (decimal 237) 421 | defining Unicode char U+00EE (decimal 238) 422 | defining Unicode char U+00EF (decimal 239) 423 | defining Unicode char U+00F8 (decimal 248) 424 | defining Unicode char U+0131 (decimal 305) 425 | defining Unicode char U+0141 (decimal 321) 426 | defining Unicode char U+0142 (decimal 322) 427 | defining Unicode char U+0152 (decimal 338) 428 | defining Unicode char U+0153 (decimal 339) 429 | defining Unicode char U+0174 (decimal 372) 430 | defining Unicode char U+0175 (decimal 373) 431 | defining Unicode char U+0176 (decimal 374) 432 | defining Unicode char U+0177 (decimal 375) 433 | defining Unicode char U+0218 (decimal 536) 434 | defining Unicode char U+0219 (decimal 537) 435 | defining Unicode char U+021A (decimal 538) 436 | defining Unicode char U+021B (decimal 539) 437 | defining Unicode char U+2013 (decimal 8211) 438 | defining Unicode char U+2014 (decimal 8212) 439 | defining Unicode char U+2018 (decimal 8216) 440 | defining Unicode char U+2019 (decimal 8217) 441 | defining Unicode char U+201C (decimal 8220) 442 | defining Unicode char U+201D (decimal 8221) 443 | ) 444 | Now handling font encoding OMS ... 445 | ... processing UTF-8 mapping file for font encoding OMS 446 | 447 | (/usr/share/texlive/texmf-dist/tex/latex/base/omsenc.dfu 448 | File: omsenc.dfu 2017/01/28 v1.1t UTF-8 support for inputenc 449 | defining Unicode char U+00A7 (decimal 167) 450 | defining Unicode char U+00B6 (decimal 182) 451 | defining Unicode char U+00B7 (decimal 183) 452 | defining Unicode char U+2020 (decimal 8224) 453 | defining Unicode char U+2021 (decimal 8225) 454 | defining Unicode char U+2022 (decimal 8226) 455 | ) 456 | Now handling font encoding OMX ... 457 | ... no UTF-8 mapping file for font encoding OMX 458 | Now handling font encoding U ... 459 | ... no UTF-8 mapping file for font encoding U 460 | defining Unicode char U+00A9 (decimal 169) 461 | defining Unicode char U+00AA (decimal 170) 462 | defining Unicode char U+00AE (decimal 174) 463 | defining Unicode char U+00BA (decimal 186) 464 | defining Unicode char U+02C6 (decimal 710) 465 | defining Unicode char U+02DC (decimal 732) 466 | defining Unicode char U+200C (decimal 8204) 467 | defining Unicode char U+2026 (decimal 8230) 468 | defining Unicode char U+2122 (decimal 8482) 469 | defining Unicode char U+2423 (decimal 9251) 470 | )) 471 | (/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty 472 | Package: fontenc 2017/02/22 v2.0g Standard LaTeX package 473 | 474 | (/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.def 475 | File: t1enc.def 2017/02/22 v2.0g Standard LaTeX file 476 | LaTeX Font Info: Redeclaring font encoding T1 on input line 48. 477 | )) 478 | (/usr/share/texlive/texmf-dist/tex/latex/listings/listings.sty 479 | \lst@mode=\count95 480 | \lst@gtempboxa=\box27 481 | \lst@token=\toks19 482 | \lst@length=\count96 483 | \lst@currlwidth=\dimen114 484 | \lst@column=\count97 485 | \lst@pos=\count98 486 | \lst@lostspace=\dimen115 487 | \lst@width=\dimen116 488 | \lst@newlines=\count99 489 | \lst@lineno=\count100 490 | \lst@maxwidth=\dimen117 491 | 492 | (/usr/share/texlive/texmf-dist/tex/latex/listings/lstmisc.sty 493 | File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz) 494 | \c@lstnumber=\count101 495 | \lst@skipnumbers=\count102 496 | \lst@framebox=\box28 497 | ) 498 | (/usr/share/texlive/texmf-dist/tex/latex/listings/listings.cfg 499 | File: listings.cfg 2015/06/04 1.6 listings configuration 500 | )) 501 | Package: listings 2015/06/04 1.6 (Carsten Heinz) 502 | 503 | (/usr/share/texlive/texmf-dist/tex/latex/tools/multicol.sty 504 | Package: multicol 2016/04/07 v1.8p multicolumn formatting (FMi) 505 | \c@tracingmulticols=\count103 506 | \mult@box=\box29 507 | \multicol@leftmargin=\dimen118 508 | \c@unbalance=\count104 509 | \c@collectmore=\count105 510 | \doublecol@number=\count106 511 | \multicoltolerance=\count107 512 | \multicolpretolerance=\count108 513 | \full@width=\dimen119 514 | \page@free=\dimen120 515 | \premulticols=\dimen121 516 | \postmulticols=\dimen122 517 | \multicolsep=\skip87 518 | \multicolbaselineskip=\skip88 519 | \partial@page=\box30 520 | \last@line=\box31 521 | \maxbalancingoverflow=\dimen123 522 | \mult@rightbox=\box32 523 | \mult@grightbox=\box33 524 | \mult@gfirstbox=\box34 525 | \mult@firstbox=\box35 526 | \@tempa=\box36 527 | \@tempa=\box37 528 | \@tempa=\box38 529 | \@tempa=\box39 530 | \@tempa=\box40 531 | \@tempa=\box41 532 | \@tempa=\box42 533 | \@tempa=\box43 534 | \@tempa=\box44 535 | \@tempa=\box45 536 | \@tempa=\box46 537 | \@tempa=\box47 538 | \@tempa=\box48 539 | \@tempa=\box49 540 | \@tempa=\box50 541 | \@tempa=\box51 542 | \@tempa=\box52 543 | \c@columnbadness=\count109 544 | \c@finalcolumnbadness=\count110 545 | \last@try=\dimen124 546 | \multicolovershoot=\dimen125 547 | \multicolundershoot=\dimen126 548 | \mult@nat@firstbox=\box53 549 | \colbreak@box=\box54 550 | \mc@col@check@num=\count111 551 | ) (./viking_asm.sty 552 | Package: viking_asm 553 | ) (/usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty 554 | Package: color 2016/07/10 v1.1e Standard LaTeX Color (DPC) 555 | 556 | (/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg 557 | File: color.cfg 2016/01/02 v1.6 sample color configuration 558 | ) 559 | Package color Info: Driver file: pdftex.def on input line 147. 560 | 561 | (/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def 562 | File: pdftex.def 2017/01/12 v0.06k Graphics/color for pdfTeX 563 | 564 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/infwarerr.sty 565 | Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO) 566 | ) 567 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ltxcmds.sty 568 | Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO) 569 | ) 570 | \Gread@gobject=\count112 571 | )) 572 | (/usr/share/texlive/texmf-dist/tex/latex/xcolor/xcolor.sty 573 | Package: xcolor 2016/05/11 v2.12 LaTeX color extensions (UK) 574 | 575 | (/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg 576 | File: color.cfg 2016/01/02 v1.6 sample color configuration 577 | ) 578 | Package xcolor Info: Driver file: pdftex.def on input line 225. 579 | LaTeX Info: Redefining \color on input line 709. 580 | Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1348. 581 | Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1352. 582 | Package xcolor Info: Model `RGB' extended on input line 1364. 583 | Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1366. 584 | Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1367. 585 | Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1368. 586 | Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1369. 587 | Package xcolor Info: Model `Gray' substituted by `gray' on input line 1370. 588 | Package xcolor Info: Model `wave' substituted by `hsb' on input line 1371. 589 | ) 590 | (/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty 591 | Package: hyperref 2016/06/24 v6.83q Hypertext links for LaTeX 592 | 593 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty 594 | Package: hobsub-hyperref 2016/05/16 v1.14 Bundle oberdiek, subset hyperref (HO) 595 | 596 | 597 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty 598 | Package: hobsub-generic 2016/05/16 v1.14 Bundle oberdiek, subset generic (HO) 599 | Package: hobsub 2016/05/16 v1.14 Construct package bundles (HO) 600 | Package hobsub Info: Skipping package `infwarerr' (already loaded). 601 | Package hobsub Info: Skipping package `ltxcmds' (already loaded). 602 | Package: ifluatex 2016/05/16 v1.4 Provides the ifluatex switch (HO) 603 | Package ifluatex Info: LuaTeX not detected. 604 | Package hobsub Info: Skipping package `ifvtex' (already loaded). 605 | Package: intcalc 2016/05/16 v1.2 Expandable calculations with integers (HO) 606 | Package hobsub Info: Skipping package `ifpdf' (already loaded). 607 | Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO) 608 | Package etexcmds Info: Could not find \expanded. 609 | (etexcmds) That can mean that you are not using pdfTeX 1.50 or 610 | (etexcmds) that some package has redefined \expanded. 611 | (etexcmds) In the latter case, load this package earlier. 612 | Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO) 613 | Package: kvdefinekeys 2016/05/16 v1.4 Define keys (HO) 614 | Package: pdftexcmds 2016/05/21 v0.22 Utility functions of pdfTeX for LuaTeX (HO 615 | ) 616 | Package pdftexcmds Info: LuaTeX not detected. 617 | Package pdftexcmds Info: \pdf@primitive is available. 618 | Package pdftexcmds Info: \pdf@ifprimitive is available. 619 | Package pdftexcmds Info: \pdfdraftmode found. 620 | Package: pdfescape 2016/05/16 v1.14 Implements pdfTeX's escape features (HO) 621 | Package: bigintcalc 2016/05/16 v1.4 Expandable calculations on big integers (HO 622 | ) 623 | Package: bitset 2016/05/16 v1.2 Handle bit-vector datatype (HO) 624 | Package: uniquecounter 2016/05/16 v1.3 Provide unlimited unique counter (HO) 625 | ) 626 | Package hobsub Info: Skipping package `hobsub' (already loaded). 627 | Package: letltxmacro 2016/05/16 v1.5 Let assignment for LaTeX macros (HO) 628 | Package: hopatch 2016/05/16 v1.3 Wrapper for package hooks (HO) 629 | Package: xcolor-patch 2016/05/16 xcolor patch 630 | Package: atveryend 2016/05/16 v1.9 Hooks at the very end of document (HO) 631 | Package atveryend Info: \enddocument detected (standard20110627). 632 | Package: atbegshi 2016/06/09 v1.18 At begin shipout hook (HO) 633 | Package: refcount 2016/05/16 v3.5 Data extraction from label references (HO) 634 | Package: hycolor 2016/05/16 v1.8 Color options for hyperref/bookmark (HO) 635 | ) 636 | (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/auxhook.sty 637 | Package: auxhook 2016/05/16 v1.4 Hooks for auxiliary files (HO) 638 | ) 639 | (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty 640 | Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO) 641 | ) 642 | \@linkdim=\dimen127 643 | \Hy@linkcounter=\count113 644 | \Hy@pagecounter=\count114 645 | 646 | (/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def 647 | File: pd1enc.def 2016/06/24 v6.83q Hyperref: PDFDocEncoding definition (HO) 648 | Now handling font encoding PD1 ... 649 | ... no UTF-8 mapping file for font encoding PD1 650 | ) 651 | \Hy@SavedSpaceFactor=\count115 652 | 653 | (/usr/share/texlive/texmf-dist/tex/latex/latexconfig/hyperref.cfg 654 | File: hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive 655 | ) 656 | Package hyperref Info: Hyper figures OFF on input line 4486. 657 | Package hyperref Info: Link nesting OFF on input line 4491. 658 | Package hyperref Info: Hyper index ON on input line 4494. 659 | Package hyperref Info: Plain pages OFF on input line 4501. 660 | Package hyperref Info: Backreferencing OFF on input line 4506. 661 | Package hyperref Info: Implicit mode ON; LaTeX internals redefined. 662 | Package hyperref Info: Bookmarks ON on input line 4735. 663 | \c@Hy@tempcnt=\count116 664 | 665 | (/usr/share/texlive/texmf-dist/tex/latex/url/url.sty 666 | \Urlmuskip=\muskip10 667 | Package: url 2013/09/16 ver 3.4 Verb mode for urls, etc. 668 | ) 669 | LaTeX Info: Redefining \url on input line 5088. 670 | \XeTeXLinkMargin=\dimen128 671 | \Fld@menulength=\count117 672 | \Field@Width=\dimen129 673 | \Fld@charsize=\dimen130 674 | Package hyperref Info: Hyper figures OFF on input line 6342. 675 | Package hyperref Info: Link nesting OFF on input line 6347. 676 | Package hyperref Info: Hyper index ON on input line 6350. 677 | Package hyperref Info: backreferencing OFF on input line 6357. 678 | Package hyperref Info: Link coloring OFF on input line 6362. 679 | Package hyperref Info: Link coloring with OCG OFF on input line 6367. 680 | Package hyperref Info: PDF/A mode OFF on input line 6372. 681 | LaTeX Info: Redefining \ref on input line 6412. 682 | LaTeX Info: Redefining \pageref on input line 6416. 683 | \Hy@abspage=\count118 684 | \c@Item=\count119 685 | \c@Hfootnote=\count120 686 | ) 687 | 688 | Package hyperref Message: Driver (autodetected): hpdftex. 689 | 690 | (/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def 691 | File: hpdftex.def 2016/06/24 v6.83q Hyperref driver for pdfTeX 692 | \Fld@listcount=\count121 693 | \c@bookmark@seq@number=\count122 694 | 695 | (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty 696 | Package: rerunfilecheck 2016/05/16 v1.8 Rerun checks for auxiliary files (HO) 697 | Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2 698 | 82. 699 | ) 700 | \Hy@SectionHShift=\skip89 701 | ) 702 | Package hyperref Info: Option `colorlinks' set `true' on input line 27. 703 | 704 | (./viking_manual_pt.aux) 705 | \openout1 = `viking_manual_pt.aux'. 706 | 707 | LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 59. 708 | LaTeX Font Info: ... okay on input line 59. 709 | LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 59. 710 | LaTeX Font Info: ... okay on input line 59. 711 | LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 59. 712 | LaTeX Font Info: ... okay on input line 59. 713 | LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 59. 714 | LaTeX Font Info: ... okay on input line 59. 715 | LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 59. 716 | LaTeX Font Info: ... okay on input line 59. 717 | LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 59. 718 | LaTeX Font Info: ... okay on input line 59. 719 | LaTeX Font Info: Checking defaults for PD1/pdf/m/n on input line 59. 720 | LaTeX Font Info: ... okay on input line 59. 721 | 722 | *geometry* driver: auto-detecting 723 | *geometry* detected driver: pdftex 724 | *geometry* verbose mode - [ preamble ] result: 725 | * driver: pdftex 726 | * paper: a4paper 727 | * layout: 728 | * layoutoffset:(h,v)=(0.0pt,0.0pt) 729 | * modes: 730 | * h-part:(L,W,R)=(89.62709pt, 418.25368pt, 89.6271pt) 731 | * v-part:(T,H,B)=(85.35826pt, 674.33032pt, 85.35826pt) 732 | * \paperwidth=597.50787pt 733 | * \paperheight=845.04684pt 734 | * \textwidth=418.25368pt 735 | * \textheight=674.33032pt 736 | * \oddsidemargin=17.3571pt 737 | * \evensidemargin=17.3571pt 738 | * \topmargin=-23.91173pt 739 | * \headheight=12.0pt 740 | * \headsep=25.0pt 741 | * \topskip=10.0pt 742 | * \footskip=30.0pt 743 | * \marginparwidth=65.0pt 744 | * \marginparsep=11.0pt 745 | * \columnsep=10.0pt 746 | * \skip\footins=9.0pt plus 4.0pt minus 2.0pt 747 | * \hoffset=0.0pt 748 | * \voffset=0.0pt 749 | * \mag=1000 750 | * \@twocolumnfalse 751 | * \@twosidefalse 752 | * \@mparswitchfalse 753 | * \@reversemarginfalse 754 | * (1in=72.27pt=25.4mm, 1cm=28.453pt) 755 | 756 | \c@lstlisting=\count123 757 | (/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii 758 | [Loading MPS to PDF converter (version 2006.09.02).] 759 | \scratchcounter=\count124 760 | \scratchdimen=\dimen131 761 | \scratchbox=\box55 762 | \nofMPsegments=\count125 763 | \nofMParguments=\count126 764 | \everyMPshowfont=\toks20 765 | \MPscratchCnt=\count127 766 | \MPscratchDim=\dimen132 767 | \MPnumerator=\count128 768 | \makeMPintoPDFobject=\count129 769 | \everyMPtoPDFconversion=\toks21 770 | ) 771 | \AtBeginShipoutBox=\box56 772 | Package hyperref Info: Link coloring ON on input line 59. 773 | (/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty 774 | Package: nameref 2016/05/21 v2.44 Cross-referencing by name of section 775 | 776 | (/usr/share/texlive/texmf-dist/tex/generic/oberdiek/gettitlestring.sty 777 | Package: gettitlestring 2016/05/16 v1.5 Cleanup title references (HO) 778 | ) 779 | \c@section@level=\count130 780 | ) 781 | LaTeX Info: Redefining \ref on input line 59. 782 | LaTeX Info: Redefining \pageref on input line 59. 783 | LaTeX Info: Redefining \nameref on input line 59. 784 | 785 | (./viking_manual_pt.out) (./viking_manual_pt.out) 786 | \@outlinefile=\write3 787 | \openout3 = `viking_manual_pt.out'. 788 | 789 | LaTeX Font Info: External font `cmex7' loaded for size 790 | (Font) <6> on input line 66. 791 | Package babel Info: Redefining portuges shorthand "| 792 | (babel) in language on input line 66. 793 | Package babel Info: Redefining portuges shorthand "| 794 | (babel) in language on input line 66. 795 | [1 796 | 797 | {/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./viking_manual_pt.toc 798 | LaTeX Font Info: External font `cmex7' loaded for size 799 | (Font) <7> on input line 2. 800 | LaTeX Font Info: External font `cmex7' loaded for size 801 | (Font) <5> on input line 2. 802 | Package babel Info: Redefining portuges shorthand "| 803 | (babel) in language on input line 72. 804 | Package babel Info: Redefining portuges shorthand "| 805 | (babel) in language on input line 72. 806 | pdfTeX warning (ext4): destination with the same identifier (name{page.1}) has 807 | been already used, duplicate ignored 808 | 809 | \relax 810 | l.72 ...de mem\IeC {\'o}ria}{34}{subsection.4.2.1} 811 | [1]) 812 | \tf@toc=\write4 813 | \openout4 = `viking_manual_pt.toc'. 814 | 815 | Package babel Info: Redefining portuges shorthand "| 816 | (babel) in language on input line 84. 817 | Package babel Info: Redefining portuges shorthand "| 818 | (babel) in language on input line 84. 819 | pdfTeX warning (ext4): destination with the same identifier (name{page.1}) has 820 | been already used, duplicate ignored 821 | 822 | \relax 823 | l.84 \newpage 824 | [1] 825 | Cap\'{\i }tulo 1. 826 | Package babel Info: Redefining portuges shorthand "| 827 | (babel) in language on input line 87. 828 | Package babel Info: Redefining portuges shorthand "| 829 | (babel) in language on input line 101. 830 | Package babel Info: Redefining portuges shorthand "| 831 | (babel) in language on input line 103. 832 | Package babel Info: Redefining portuges shorthand "| 833 | (babel) in language on input line 103. 834 | [2 835 | 836 | ] 837 | LaTeX Font Info: Try loading font information for T1+cmtt on input line 111. 838 | 839 | (/usr/share/texlive/texmf-dist/tex/latex/base/t1cmtt.fd 840 | File: t1cmtt.fd 2014/09/29 v2.5h Standard LaTeX font definitions 841 | ) 842 | Package babel Info: Redefining portuges shorthand "| 843 | (babel) in language on input line 124. 844 | Package babel Info: Redefining portuges shorthand "| 845 | (babel) in language on input line 127. 846 | Package babel Info: Redefining portuges shorthand "| 847 | (babel) in language on input line 138. 848 | Package babel Info: Redefining portuges shorthand "| 849 | (babel) in language on input line 138. 850 | [3] 851 | LaTeX Font Info: Try loading font information for OMS+cmr on input line 143. 852 | 853 | 854 | (/usr/share/texlive/texmf-dist/tex/latex/base/omscmr.fd 855 | File: omscmr.fd 2014/09/29 v2.5h Standard LaTeX font definitions 856 | ) 857 | LaTeX Font Info: Font shape `OMS/cmr/m/n' in size <10> not available 858 | (Font) Font shape `OMS/cmsy/m/n' tried instead on input line 143. 859 | Package babel Info: Redefining portuges shorthand "| 860 | (babel) in language on input line 167. 861 | Package babel Info: Redefining portuges shorthand "| 862 | (babel) in language on input line 186. 863 | Package babel Info: Redefining portuges shorthand "| 864 | (babel) in language on input line 186. 865 | [4] 866 | Package babel Info: Redefining portuges shorthand "| 867 | (babel) in language on input line 206. 868 | Package babel Info: Redefining portuges shorthand "| 869 | (babel) in language on input line 220. 870 | Package babel Info: Redefining portuges shorthand "| 871 | (babel) in language on input line 223. 872 | Package babel Info: Redefining portuges shorthand "| 873 | (babel) in language on input line 223. 874 | [5] 875 | Package babel Info: Redefining portuges shorthand "| 876 | (babel) in language on input line 226. 877 | Package babel Info: Redefining portuges shorthand "| 878 | (babel) in language on input line 290. 879 | Package babel Info: Redefining portuges shorthand "| 880 | (babel) in language on input line 290. 881 | [6] 882 | Package babel Info: Redefining portuges shorthand "| 883 | (babel) in language on input line 348. 884 | Package babel Info: Redefining portuges shorthand "| 885 | (babel) in language on input line 348. 886 | [7] 887 | Package babel Info: Redefining portuges shorthand "| 888 | (babel) in language on input line 421. 889 | Package babel Info: Redefining portuges shorthand "| 890 | (babel) in language on input line 421. 891 | 892 | [8] 893 | Package babel Info: Redefining portuges shorthand "| 894 | (babel) in language on input line 484. 895 | Package babel Info: Redefining portuges shorthand "| 896 | (babel) in language on input line 484. 897 | [9] 898 | Package babel Info: Redefining portuges shorthand "| 899 | (babel) in language on input line 503. 900 | Package babel Info: Redefining portuges shorthand "| 901 | (babel) in language on input line 540. 902 | Package babel Info: Redefining portuges shorthand "| 903 | (babel) in language on input line 540. 904 | [10] 905 | Package babel Info: Redefining portuges shorthand "| 906 | (babel) in language on input line 555. 907 | Package babel Info: Redefining portuges shorthand "| 908 | (babel) in language on input line 609. 909 | Package babel Info: Redefining portuges shorthand "| 910 | (babel) in language on input line 609. 911 | [11] 912 | Package babel Info: Redefining portuges shorthand "| 913 | (babel) in language on input line 624. 914 | Package babel Info: Redefining portuges shorthand "| 915 | (babel) in language on input line 684. 916 | Package babel Info: Redefining portuges shorthand "| 917 | (babel) in language on input line 684. 918 | [12] 919 | Package babel Info: Redefining portuges shorthand "| 920 | (babel) in language on input line 713. 921 | Package babel Info: Redefining portuges shorthand "| 922 | (babel) in language on input line 722. 923 | Package babel Info: Redefining portuges shorthand "| 924 | (babel) in language on input line 722. 925 | [13] 926 | Package babel Info: Redefining portuges shorthand "| 927 | (babel) in language on input line 743. 928 | Package babel Info: Redefining portuges shorthand "| 929 | (babel) in language on input line 744. 930 | Package babel Info: Redefining portuges shorthand "| 931 | (babel) in language on input line 766. 932 | Package babel Info: Redefining portuges shorthand "| 933 | (babel) in language on input line 766. 934 | [14] 935 | Package babel Info: Redefining portuges shorthand "| 936 | (babel) in language on input line 793. 937 | Package babel Info: Redefining portuges shorthand "| 938 | (babel) in language on input line 797. 939 | Package babel Info: Redefining portuges shorthand "| 940 | (babel) in language on input line 799. 941 | Package babel Info: Redefining portuges shorthand "| 942 | (babel) in language on input line 799. 943 | [15] 944 | Package babel Info: Redefining portuges shorthand "| 945 | (babel) in language on input line 801. 946 | Package babel Info: Redefining portuges shorthand "| 947 | (babel) in language on input line 814. 948 | Package babel Info: Redefining portuges shorthand "| 949 | (babel) in language on input line 825. 950 | Package babel Info: Redefining portuges shorthand "| 951 | (babel) in language on input line 825. 952 | [16] 953 | Package babel Info: Redefining portuges shorthand "| 954 | (babel) in language on input line 831. 955 | Package babel Info: Redefining portuges shorthand "| 956 | (babel) in language on input line 867. 957 | Package babel Info: Redefining portuges shorthand "| 958 | (babel) in language on input line 872. 959 | Package babel Info: Redefining portuges shorthand "| 960 | (babel) in language on input line 875. 961 | Package babel Info: Redefining portuges shorthand "| 962 | (babel) in language on input line 875. 963 | [17] 964 | Package babel Info: Redefining portuges shorthand "| 965 | (babel) in language on input line 881. 966 | Package babel Info: Redefining portuges shorthand "| 967 | (babel) in language on input line 881. 968 | [18] 969 | Cap\'{\i }tulo 2. 970 | Package babel Info: Redefining portuges shorthand "| 971 | (babel) in language on input line 881. 972 | Package babel Info: Redefining portuges shorthand "| 973 | (babel) in language on input line 888. 974 | 975 | Underfull \hbox (badness 10000) in paragraph at lines 907--907 976 | []\T1/cmr/m/n/10 Rotate right th-rough 977 | [] 978 | 979 | Package babel Info: Redefining portuges shorthand "| 980 | (babel) in language on input line 927. 981 | Package babel Info: Redefining portuges shorthand "| 982 | (babel) in language on input line 930. 983 | Package babel Info: Redefining portuges shorthand "| 984 | (babel) in language on input line 930. 985 | [19 986 | 987 | ] 988 | Underfull \hbox (badness 10000) in paragraph at lines 937--937 989 | []\T1/cmr/m/n/10 Arithmetic shift right 990 | [] 991 | 992 | Package babel Info: Redefining portuges shorthand "| 993 | (babel) in language on input line 942. 994 | Package babel Info: Redefining portuges shorthand "| 995 | (babel) in language on input line 944. 996 | 997 | Underfull \hbox (badness 1776) in paragraph at lines 971--971 998 | []\T1/cmr/m/n/10 Branch if gre-a-ter equal 999 | [] 1000 | 1001 | Package babel Info: Redefining portuges shorthand "| 1002 | (babel) in language on input line 975. 1003 | Package babel Info: Redefining portuges shorthand "| 1004 | (babel) in language on input line 978. 1005 | Package babel Info: Redefining portuges shorthand "| 1006 | (babel) in language on input line 978. 1007 | [20] 1008 | Underfull \hbox (badness 3343) in paragraph at lines 990--990 1009 | []\T1/cmr/m/n/10 Branch if gre-a-ter than 1010 | [] 1011 | 1012 | Package babel Info: Redefining portuges shorthand "| 1013 | (babel) in language on input line 995. 1014 | Package babel Info: Redefining portuges shorthand "| 1015 | (babel) in language on input line 1010. 1016 | Package babel Info: Redefining portuges shorthand "| 1017 | (babel) in language on input line 1010. 1018 | [21] 1019 | Package babel Info: Redefining portuges shorthand "| 1020 | (babel) in language on input line 1012. 1021 | 1022 | Underfull \hbox (badness 10000) in paragraph at lines 1021--1021 1023 | []\T1/cmtt/m/n/10 mul r1,r2,r3 1024 | [] 1025 | 1026 | 1027 | Underfull \hbox (badness 10000) in paragraph at lines 1021--1021 1028 | \T1/cmtt/m/n/10 (\T1/cmtt/m/it/10 mulsi3\T1/cmtt/m/n/10 ) / div 1029 | [] 1030 | 1031 | 1032 | Underfull \hbox (badness 10000) in paragraph at lines 1021--1021 1033 | \T1/cmtt/m/n/10 r1,r2,r3 (\T1/cmtt/m/it/10 divsi3\T1/cmtt/m/n/10 ) 1034 | [] 1035 | 1036 | 1037 | Underfull \hbox (badness 10000) in paragraph at lines 1021--1021 1038 | \T1/cmtt/m/n/10 / rem r1,r2,r3 1039 | [] 1040 | 1041 | Package babel Info: Redefining portuges shorthand "| 1042 | (babel) in language on input line 1025. 1043 | Package babel Info: Redefining portuges shorthand "| 1044 | (babel) in language on input line 1025. 1045 | [22] 1046 | Cap\'{\i }tulo 3. 1047 | Package babel Info: Redefining portuges shorthand "| 1048 | (babel) in language on input line 1025. 1049 | Package babel Info: Redefining portuges shorthand "| 1050 | (babel) in language on input line 1029. 1051 | Package babel Info: Redefining portuges shorthand "| 1052 | (babel) in language on input line 1033. 1053 | Package babel Info: Redefining portuges shorthand "| 1054 | (babel) in language on input line 1057. 1055 | Package babel Info: Redefining portuges shorthand "| 1056 | (babel) in language on input line 1057. 1057 | [23 1058 | 1059 | ] 1060 | Package babel Info: Redefining portuges shorthand "| 1061 | (babel) in language on input line 1098. 1062 | Package babel Info: Redefining portuges shorthand "| 1063 | (babel) in language on input line 1098. 1064 | [24] 1065 | Package babel Info: Redefining portuges shorthand "| 1066 | (babel) in language on input line 1124. 1067 | Package babel Info: Redefining portuges shorthand "| 1068 | (babel) in language on input line 1137. 1069 | Package babel Info: Redefining portuges shorthand "| 1070 | (babel) in language on input line 1137. 1071 | [25] 1072 | Package babel Info: Redefining portuges shorthand "| 1073 | (babel) in language on input line 1164. 1074 | Package babel Info: Redefining portuges shorthand "| 1075 | (babel) in language on input line 1179. 1076 | Package babel Info: Redefining portuges shorthand "| 1077 | (babel) in language on input line 1179. 1078 | [26] 1079 | Package babel Info: Redefining portuges shorthand "| 1080 | (babel) in language on input line 1183. 1081 | Package babel Info: Redefining portuges shorthand "| 1082 | (babel) in language on input line 1214. 1083 | Package babel Info: Redefining portuges shorthand "| 1084 | (babel) in language on input line 1214. 1085 | [27] 1086 | Package babel Info: Redefining portuges shorthand "| 1087 | (babel) in language on input line 1216. 1088 | Package babel Info: Redefining portuges shorthand "| 1089 | (babel) in language on input line 1219. 1090 | Package babel Info: Redefining portuges shorthand "| 1091 | (babel) in language on input line 1233. 1092 | Package babel Info: Redefining portuges shorthand "| 1093 | (babel) in language on input line 1254. 1094 | Package babel Info: Redefining portuges shorthand "| 1095 | (babel) in language on input line 1254. 1096 | [28] 1097 | Package babel Info: Redefining portuges shorthand "| 1098 | (babel) in language on input line 1257. 1099 | Package babel Info: Redefining portuges shorthand "| 1100 | (babel) in language on input line 1285. 1101 | Package babel Info: Redefining portuges shorthand "| 1102 | (babel) in language on input line 1285. 1103 | [29] 1104 | Package babel Info: Redefining portuges shorthand "| 1105 | (babel) in language on input line 1289. 1106 | Package babel Info: Redefining portuges shorthand "| 1107 | (babel) in language on input line 1289. 1108 | [30] 1109 | Cap\'{\i }tulo 4. 1110 | Package babel Info: Redefining portuges shorthand "| 1111 | (babel) in language on input line 1289. 1112 | Package babel Info: Redefining portuges shorthand "| 1113 | (babel) in language on input line 1292. 1114 | Package babel Info: Redefining portuges shorthand "| 1115 | (babel) in language on input line 1295. 1116 | Package babel Info: Redefining portuges shorthand "| 1117 | (babel) in language on input line 1308. 1118 | Package babel Info: Redefining portuges shorthand "| 1119 | (babel) in language on input line 1308. 1120 | [31 1121 | 1122 | ] 1123 | Package babel Info: Redefining portuges shorthand "| 1124 | (babel) in language on input line 1322. 1125 | (../examples/ninetoone.asm) 1126 | Package babel Info: Redefining portuges shorthand "| 1127 | (babel) in language on input line 1334. 1128 | Package babel Info: Redefining portuges shorthand "| 1129 | (babel) in language on input line 1334. 1130 | [32] (../examples/ninetoone.out) 1131 | (../examples/ninetoone_debug.out) 1132 | Package babel Info: Redefining portuges shorthand "| 1133 | (babel) in language on input line 1356. 1134 | Package babel Info: Redefining portuges shorthand "| 1135 | (babel) in language on input line 1359. 1136 | Package babel Info: Redefining portuges shorthand "| 1137 | (babel) in language on input line 1359. 1138 | [33] 1139 | Package babel Info: Redefining portuges shorthand "| 1140 | (babel) in language on input line 1360. 1141 | Package babel Info: Redefining portuges shorthand "| 1142 | (babel) in language on input line 1380. 1143 | Package babel Info: Redefining portuges shorthand "| 1144 | (babel) in language on input line 1408. 1145 | Package babel Info: Redefining portuges shorthand "| 1146 | (babel) in language on input line 1408. 1147 | [34] 1148 | Ap\^endice A. 1149 | Package babel Info: Redefining portuges shorthand "| 1150 | (babel) in language on input line 1408. 1151 | (../examples/hello_world.asm) (../examples/fibonacci.asm) 1152 | (../examples/function_call.asm 1153 | Package babel Info: Redefining portuges shorthand "| 1154 | (babel) in language on input line 44. 1155 | Package babel Info: Redefining portuges shorthand "| 1156 | (babel) in language on input line 44. 1157 | [35 1158 | 1159 | ]) (../examples/mult.asm) 1160 | (../examples/bubble_sort.asm 1161 | Package babel Info: Redefining portuges shorthand "| 1162 | (babel) in language on input line 68. 1163 | Package babel Info: Redefining portuges shorthand "| 1164 | (babel) in language on input line 68. 1165 | [36]) 1166 | Package babel Info: Redefining portuges shorthand "| 1167 | (babel) in language on input line 1416. 1168 | Package babel Info: Redefining portuges shorthand "| 1169 | (babel) in language on input line 1416. 1170 | [37] 1171 | Ap\^endice B. 1172 | Package babel Info: Redefining portuges shorthand "| 1173 | (babel) in language on input line 1416. 1174 | (../examples/mulsi3.asm) (../examples/divsi3.asm 1175 | Package babel Info: Redefining portuges shorthand "| 1176 | (babel) in language on input line 39. 1177 | Package babel Info: Redefining portuges shorthand "| 1178 | (babel) in language on input line 39. 1179 | [38 1180 | 1181 | ]) (../examples/modsi3.asm) (../examples/udivmodsi4.asm 1182 | Package babel Info: Redefining portuges shorthand "| 1183 | (babel) in language on input line 40. 1184 | Package babel Info: Redefining portuges shorthand "| 1185 | (babel) in language on input line 40. 1186 | [39]) 1187 | Package atveryend Info: Empty hook `BeforeClearDocument' on input line 1424. 1188 | Package babel Info: Redefining portuges shorthand "| 1189 | (babel) in language on input line 1424. 1190 | Package babel Info: Redefining portuges shorthand "| 1191 | (babel) in language on input line 1424. 1192 | [40] 1193 | Package atveryend Info: Empty hook `AfterLastShipout' on input line 1424. 1194 | (./viking_manual_pt.aux) 1195 | Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 1424. 1196 | Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 1424. 1197 | 1198 | Package rerunfilecheck Info: File `viking_manual_pt.out' has not changed. 1199 | (rerunfilecheck) Checksum: AE6533C5C276F8D10904D4A50A40EF31;3703. 1200 | Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 1424. 1201 | ) 1202 | Here is how much of TeX's memory you used: 1203 | 9999 strings out of 493013 1204 | 141410 string characters out of 6135681 1205 | 492583 words of memory out of 5000000 1206 | 12789 multiletter control sequences out of 15000+600000 1207 | 23092 words of font info for 49 fonts, out of 8000000 for 9000 1208 | 1141 hyphenation exceptions out of 8191 1209 | 33i,13n,43p,1346b,1942s stack positions out of 5000i,500n,10000p,200000b,80000s 1210 | {/usr/share/texmf/fonts/enc/dvips/cm-super/cm-super-t1.enc} 1217 | < 1220 | /usr/share/texmf/fonts/type1/public/cm-super/sfbx1728.pfb> 1231 | Output written on viking_manual_pt.pdf (42 pages, 601419 bytes). 1232 | PDF statistics: 1233 | 1186 PDF objects out of 1200 (max. 8388607) 1234 | 1105 compressed objects within 12 object streams 1235 | 599 named destinations out of 1000 (max. 500000) 1236 | 385 words of extra memory for PDF output out of 10000 (max. 10000000) 1237 | 1238 | --------------------------------------------------------------------------------