此项目为GXU编译原理课设,适合低要求,混及格同学,内涵完整代码(1k行+)、文件和论文(1w字+)

运行环境:eclipse

词法模块内容

(1)确定源语言C和编写编译程序的语言java;

(2)用正规式描述C的词法规则;

(3)根据正规式构造给出识别单词的DFA M;

(4)根据M,用语言java编写C的词法分析程序。

(5)读入源程序字符串,识别具有独立含义的最小语法单位——单词;

(6)对识别过程中发现的词法问题,则输出有关的错误信息;

语法模块内容

(1)本次实验中采用的设计方法是lr1,首先便是要设计好文法。

(2)能根据文法构造项目集族。

(3)再根据项目集族进行lr1分析表的构造,写成xls文件。

(4)设计程序读取lr1分析表.xls与文法.xls文件。

(5)根据这两个文件完成语法检查。

(6)对不正确的语法不能通过语法检查并要停留在这一步表明出错。

语义模块内容

(1)初设语法制导翻译,缕清语义程序的思路

(2)设计编写语义程序的全局属性

(3)设计编写语义程序的方法

(4)设计编写每个产生式对应的语义程序

(5)将语义程序得到的四元式表打印到文本中

代码结构

image-20220428131310587

input.txt

为需要编译的c语言代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include<stdio.h>
void main(){
	int i=0,max=0;
	int a[6]={1,4,6,2,8,9};
	while(i<6){
		if(max<a[i]){
			max=a[i];
		}
		i++;
	}
}

output.txt

为词法分析后的输出结果

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
1`#include
26`<
8`stdio.h
27`>
6`void
22`main
40`(
41`)
43`{
2`int
22`i
24`=
23`0
46`,
22`max
24`=
23`0
47`;
2`int
22`a
44`[
23`6
45`]
24`=
43`{
23`1
46`,
23`4
46`,
23`6
46`,
23`2
46`,
23`8
46`,
23`9
42`}
47`;
15`while
40`(
22`i
26`<
23`6
41`)
43`{
16`if
40`(
22`max
26`<
22`a
44`[
22`i
45`]
41`)
43`{
22`max
24`=
22`a
44`[
22`i
45`]
47`;
42`}
22`i
38`++
47`;
42`}
42`}

Lexer.java

为词法分析代码

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
package compile3;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

class LexicalError extends Error {

    public LexicalError(String string) {
    }
}


public class Lexer {
	
    static int i = 0;
    static String keywords[] = {"#include","int","float","int26",
                                "double","void","math.h",
                                "stdio.h","stdlib.h","string.h","malloc.h",
                                "return","for","do","while",
                                "if","else","break","printf","%d","%f"};
    //"stdio.h","math.h","stdlib.h"
    static List<Character> sourceCode=new ArrayList<Character>();
    static String filename="src/LexerOutput.txt";

    public static void getTokenLiteral(char c) {
        System.out.println("<"+c + ","+"char"+">");
        i++;
    }

    public static void getTokenNumber(char c)  {
        System.out.println("<"+c + ","+"number"+">");
        i++;
    }

    public static void getTokenOperation(char c)   {
        System.out.println("<"+c + ","+(keywords.length+11)+">");
        i++;
    }
    public static void getTokenKeywords(String c,int i)   {
        System.out.println("<"+c + ","+i+">");

    }
    public static void getTokenSymbol(char c) {
        System.out.println("<"+c + ","+(keywords.length+12)+">");
        i++;
    }
    public static void getTokenIdentifier(String c) {
        System.out.println("<"+c + ","+(keywords.length+1)+">");
    }
    public static void getTokenSelfadding(String c) {//++
        System.out.println("<"+c + ","+(keywords.length+3)+">");
        i++;
    }
    public static void getTokenSelfdecrement(String c) {//--
        System.out.println("<"+c + ","+38+">");
        i++;
    }
    public static void getTokenLogicand(String c) {//&&
        System.out.println("<"+c + ","+(keywords.length+5)+">");
        i++;
    }
    public static void getTokenLogicor(String c) {
        System.out.println("<"+c + ","+(keywords.length+6)+">");
        i++;
    }
    public static void getTokenLogicalnon(String c) {
        System.out.println("<"+c + ","+(keywords.length+7)+">");
        i++;
    }
    public static void getTokenLogicequality(String c) {
        System.out.println("<"+c + ","+(keywords.length+8)+">");
        i++;
    }
    public static void getTokenGreaterequal(String c) {
        System.out.println("<"+c + ","+(keywords.length+9)+">");
        i++;
    }
    public static void getTokenLessequal(String c) {
        System.out.println("<"+c + ","+(keywords.length+10)+">");
        i++;
    }
    public static void getTokenNumber1(String c) {
        System.out.println("<"+c + ","+(keywords.length+2)+">");
        i++;
    }
    public static void getTokenkexuejishu(String c) {
        System.out.println("<"+c + ","+(keywords.length+13)+">");
        i++;
    }
    public static void getArray(String c) {
        System.out.println("<"+c + ","+(keywords.length+14)+">");
        i++;
    }
    public void lexicalAnalysis() throws IOException{
        BufferedWriter writer=new BufferedWriter(new FileWriter(filename));
        String file = "src/input.txt";
        Reader reader = null;
        try {
            reader = new InputStreamReader(new FileInputStream(file));
            int tempchar;
            while ((tempchar = reader.read()) != -1) {
                if (((char) tempchar) != '\r') {
                    sourceCode.add((char) tempchar);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        while (i < sourceCode.size()) {
            char c = sourceCode.get(i);
            String s = String.valueOf(c);
            String string="";
            boolean flag=true;
            boolean kw=false;
            boolean findoneid=false;
            while(true) {
                if (s.matches("[A-Za-z%#]")) {
                    string=string+s;
                    i++;
                    s=String.valueOf(sourceCode.get(i));
                    while(s.matches("[A-Za-z0-9.]")) {
                        flag=false;
                        string=string+s;
                        i++;
                        s=String.valueOf(sourceCode.get(i));
                    }
                    if(flag) {
                        getTokenIdentifier(string);
                        writer.write(keywords.length+1+"`"+string);
                        writer.newLine();
                        findoneid=true;
                        break;
                    }
                    for (int i=0;i<keywords.length;i++) {
                        if(string.equals(keywords[i])) {
                            getTokenKeywords(string,(i+1));
                            writer.write(i+1+"`"+string);
                            writer.newLine();
                            kw=true;
                            break;
                        }
                    }
                    if(!kw) {
                        getTokenIdentifier(string);
                        writer.write(keywords.length+1+"`"+string);
                        writer.newLine();
                        break;
                    }

                }
                else {
                    break;
                }
            }
            flag=true;
            c = sourceCode.get(i);
            string="";//仅仅是点后面无数字
            boolean singlepoint = false;
            boolean findpoint = false;
            while(true) {
                if(s.matches("[0]")) {
                    string=string+s;
                    i++;
                    s=String.valueOf(sourceCode.get(i));
                    if(s.matches("[0-9]")){
                        writer.close();
                        throw new LexicalError("unexpected char ${c}");
                    }
                    if(s.matches("[.]")) {//是0.
                        singlepoint = true;
                        string=string+s;
                        i++;
                        s=String.valueOf(sourceCode.get(i));
                        while(s.matches("[0-9]")){
                            if(s.matches("[0-9]")) {
                                singlepoint = false;
                                string = string + s;
                                i++;
                                s = String.valueOf(sourceCode.get(i));
                            }
                            else{
                                singlepoint = true;
                            }
                        }
                        if(singlepoint) {//小数点后留空直接写数字以外的抛出异常
                            writer.close();
                            throw new LexicalError("unexpected char ${c}");
                        }else {
                            getTokenNumber1(string);//输出0.xxxx
                            writer.write(keywords.length+2+"`"+string);
                            writer.newLine();
                            i--;
                            break;
                        }
                    }else {//仅仅是0
                        getTokenNumber1(string);
                        writer.write(keywords.length+2+"`"+string);
                        writer.newLine();
                        i--;
                        break;
                    }
                }
                if (s.matches("[1-9]")) {//1-9开头的int或double
                    string=string+s;
                    i++;
                    s=String.valueOf(sourceCode.get(i));
                    while(s.matches("[0-9.]")) {//int
                        flag=false;
                        string=string+s;
                        if(s.matches("[.]")) {
                            findpoint = true;
                            singlepoint = true;
                            break;
                        }
                        i++;
                        s=String.valueOf(sourceCode.get(i));
                    }
                    if(findpoint) {
//						string=string+s;
                        i++;
                        s=String.valueOf(sourceCode.get(i));
                        while(s.matches("[0-9]")) {//double
                            if(s.matches("[0-9]")) {
                                singlepoint = false;
                                string = string + s;
                                i++;
                                s = String.valueOf(sourceCode.get(i));
                            }
                            else{
                                singlepoint = true;
                            }
                        }
                        if(singlepoint) {//小数点后留空直接写数字以外的抛出异常
                            throw new LexicalError("unexpected char ${c}");
                        }else if(singlepoint){
                            getTokenNumber1(string);
                            writer.write(keywords.length+2+"`"+string);
                            writer.newLine();
                            i--;
                            break;
                        }
                    }
                    if(flag) {
                        getTokenNumber1(string);//仅仅是1-9单数字
                        writer.write(keywords.length+2+"`"+string);
                        writer.newLine();
                        i--;
                        findoneid=true;
                        break;
                    }
                    else{
                        getTokenNumber1(string);//int多数字
                        writer.write(keywords.length+2+"`"+string);
                        writer.newLine();
                        i--;
                        break;
                    }
                }
                else {
                    break;
                }
            }
            c = sourceCode.get(i);
            string="";
            while(true) {
                if(c=='+') {
                    string=string+s;
                    i++;
                    if(sourceCode.get(i)=='+') {
                        string=string+'+';
                        getTokenSelfadding(string);
                        writer.write(38+"`"+string);
                        writer.newLine();
                        findoneid=true;
                        break;
                    }
                    else {
                        i--;
                        break;
                    }
                }
                else{
                    break;
                }
            }
            string="";
            while(true) {//--38
                if(c=='-') {
                    string=string+s;
                    i++;
                    if(sourceCode.get(i)=='-') {
                        string=string+'-';
                        getTokenSelfdecrement(string);
                        writer.write(39+"`"+string);
                        writer.newLine();
                        findoneid=true;
                        break;
                    }
                    else {
                        i--;
                        break;
                    }
                }
                else{
                    break;
                }
            }
            //------------------------
            string="";
            while(true) {//&&34
                if(c=='&') {
                    string=string+s;
                    i++;
                    if(sourceCode.get(i)=='&') {
                        string=string+'&';
                        getTokenLogicand(string);
                        writer.write(35+"`"+string);
                        writer.newLine();
                        findoneid=true;
                        break;
                    }
                    else {
                        i--;
                        break;
                    }
                }
                else{
                    break;
                }
            }
            string="";
            while(true) {//||35
                if(c=='|') {
                    string=string+s;
                    i++;
                    if(sourceCode.get(i)=='|') {
                        string=string+'|';
                        getTokenLogicor(string);
                        writer.write(36+"`"+string);
                        writer.newLine();
                        findoneid=true;
                        break;
                    }
                    else {
                        i--;
                        break;
                    }
                }
                else{
                    break;
                }
            }
            string="";
            while(true) {//!=29
                if(c=='!') {
                    string=string+s;
                    i++;
                    if(sourceCode.get(i)=='=') {
                        string=string+'=';
                        getTokenLogicalnon(string);
                        writer.write(30+"`"+string);
                        writer.newLine();
                        findoneid=true;
                        break;
                    }
                    else {
                        i--;
                        break;
                    }
                }
                else{
                    break;
                }
            }
            string="";
            while(true) {
                if(c=='=') {//==24
                    string=string+s;
                    i++;
                    if(sourceCode.get(i)=='=') {
                        string=string+'=';
                        getTokenLogicequality(string);
                        writer.write(25+"`"+string);
                        writer.newLine();
                        findoneid=true;
                        break;
                    }
                    else {
                        i--;
                        break;
                    }
                }
                else{
                    break;
                }
            }
            string="";
            while(true) {
                if(c=='>') {//>=27
                    string=string+s;
                    i++;
                    if(sourceCode.get(i)=='=') {
                        string=string+'=';
                        getTokenGreaterequal(string);
                        writer.write(28+"`"+string);
                        writer.newLine();
                        findoneid=true;
                        break;
                    }
                    else {
                        i--;
                        break;
                    }
                }
                else{
                    break;
                }
            }
            string="";
            while(true) {
                if(c=='<') {//<=28
                    string=string+s;
                    i++;
                    if(sourceCode.get(i)=='=') {
                        string=string+'=';
                        getTokenLessequal(string);
                        writer.write(29+"`"+string);
                        writer.newLine();
                        findoneid=true;
                        break;
                    }
                    else {
                        i--;
                        break;
                    }
                }
                else{
                    break;
                }
            }
            //------------------------case语句测试
            string = "";
            while(sourceCode.get(i)=='\'') {
                i++;
                string = string+'\'';
                writer.write('\'');
                writer.newLine();
                c = sourceCode.get(i);
                switch(c) {
                    case 'Z':{
                        string=string+c;
                        i++;
                        writer.write(c);
                        writer.newLine();
                        break;
                    }
                    default:
                        throw new LexicalError("unexpected char ${c}");
                }
                if(sourceCode.get(i)=='\'') {
                    string+='\'';
                    i++;
                    writer.write('\'');
                    writer.newLine();
                    System.out.println("<"+string+"`"+"100>");
                    break;
                }
                else {
                    throw new LexicalError("unexpected char ${c}");
                }
            }
            string="";
            //------------------------------
            c = sourceCode.get(i);
            switch (c) {
                case '$':{
                    writer.write('$');
                    writer.newLine();
                    writer.close();
                    return;}
                case '\n':
                case '\t':
                case ' ': {
                    i++;
                    break;
                }
                case '=':{
                    getTokenOperation(c);
                    writer.write(24+"`"+c);
                    writer.newLine();
                    break;
                }
                case '*':
                {
                    getTokenOperation(c);
                    writer.write(33+"`"+c);
                    writer.newLine();
                    break;
                }
                case '+':
                {
                    getTokenOperation(c);
                    writer.write(31+"`"+c);
                    writer.newLine();
                    break;
                }
                case '-':
                {
                    getTokenOperation(c);
                    writer.write(32+"`"+c);
                    writer.newLine();
                    break;
                }
                case '/':
                {
                    getTokenOperation(c);
                    writer.write(34+"`"+c);
                    writer.newLine();
                    break;
                }
                case '^':
                case ':':{
                    break;
                }
                case '[':
                {
                    getTokenOperation(c);
                    writer.write(44+"`"+c);
                    writer.newLine();
                    break;
                }
                case ']':
                {
                    getTokenOperation(c);
                    writer.write(45+"`"+c);
                    writer.newLine();
                    break;
                }
                case '!':
                {
                    getTokenOperation(c);
                    writer.write(37+"`"+c);
                    writer.newLine();
                    break;
                }
                case '<':
                {
                    getTokenOperation(c);
                    writer.write(26+"`"+c);
                    writer.newLine();
                    break;
                }
                case '>':
                {
                    getTokenOperation(c);
                    writer.write(27+"`"+c);
                    writer.newLine();
                    break;
                }
                case '}':
                {
                    getTokenOperation(c);
                    writer.write(42+"`"+c);
                    writer.newLine();
                    break;
                }
                case '{':
                {
                    getTokenOperation(c);
                    writer.write(43+"`"+c);
                    writer.newLine();
                    break;
                }
                case '"':
                {
                    getTokenOperation(c);
                    writer.write(48+"`"+c);
                    writer.newLine();
                    break;
                }
                case '(':
                {
                    getTokenOperation(c);
                    writer.write(40+"`"+c);
                    writer.newLine();
                    break;
                }
                case ')':
                {
                    getTokenOperation(c);
                    writer.write(41+"`"+c);
                    writer.newLine();
                    break;
                }
                case ';':
                {
                    getTokenOperation(c);
                    writer.write(47+"`"+c);
                    writer.newLine();
                    break;
                }
                case ',':
                {
                    getTokenOperation(c);
                    writer.write(46+"`"+c);
                    writer.newLine();
                    break;
                }

                case '&': {
                    getTokenSymbol(c);
                    writer.write(c);
                    //writer.write("<"+c + ","+(keywords.length+12)+">");
                    writer.newLine();
                    break;
                }
                default:
                    if(!findoneid) {
                        throw new LexicalError("unexpected char ${c}");
                    }
                    else {
                        break;
                    }

            }
        }
        writer.close();
    }
    public static void main(String[] args)throws IOException{
        Lexer lexer=new Lexer();
        lexer.lexicalAnalysis();
    }

    public List<String> getWord(String filename) {
        List<String> words = new ArrayList();
        String line;
        try {
            BufferedReader in = new BufferedReader(new FileReader(filename));
            line = in.readLine();
            words.add(line);
            while(line != null) {
                line = in.readLine();
                if(line == null) {
                    break;
                }
                words.add(line);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return words;
    }
}

lr1.xls

(人工操作)

image-20220428131846554

grammar.xls

(人工操作)

image-20220428131946235

lr1.java

语法分析代码,将词法分析后的txt文件进行语法检验,它需要用到lr1.xls、grammar.xls文件

截取部分运行结果

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
第1步是移进操作	状态栈为:[1, 5]	符号栈为:[#, #include]
<
第2步是移进操作	状态栈为:[1, 5, 15]	符号栈为:[#, #include, <]
stdio.h
第3步是移进操作	状态栈为:[1, 5, 15, 21]	符号栈为:[#, #include, <, stdio.h]
>
第4步是规约操作	状态栈为:[1, 5, 15, 19]	符号栈为:[#, #include, <, L]	产生式为:L -> stdio.h
[]
第5步是移进操作	状态栈为:[1, 5, 15, 19, 27]	符号栈为:[#, #include, <, L, >]
void
第6步是规约操作	状态栈为:[1, 4]	符号栈为:[#, B1]	产生式为:B1 -> #include < L >
[]
第7步是规约操作	状态栈为:[1, 3]	符号栈为:[#, B]	产生式为:B -> B1
[]
第8步是移进操作	状态栈为:[1, 3, 9]	符号栈为:[#, B, void]
id
第9步是规约操作	状态栈为:[1, 3, 8]	符号栈为:[#, B, C]	产生式为:C -> void
[]
第10步是移进操作	状态栈为:[1, 3, 8, 18]	符号栈为:[#, B, C, id]
(
第11步是规约操作	状态栈为:[1, 3, 8, 17]	符号栈为:[#, B, C, D]	产生式为:D -> id
[]
第12步是移进操作	状态栈为:[1, 3, 8, 17, 25]	符号栈为:[#, B, C, D, (]
)
第13步是规约操作	状态栈为:[1, 3, 8, 17, 25, 28]	符号栈为:[#, B, C, D, (, G]	产生式为:G -> ε
[]
第14步是移进操作	状态栈为:[1, 3, 8, 17, 25, 28, 41]	符号栈为:[#, B, C, D, (, G, )]
{
第15步是移进操作	状态栈为:[1, 3, 8, 17, 25, 28, 41, 56]	符号栈为:[#, B, C, D, (, G, ), {]
int
第16步是移进操作	状态栈为:[1, 3, 8, 17, 25, 28, 41, 56, 86]	符号栈为:[#, B, C, D, (, G, ), {, int]
id
第17步是规约操作	状态栈为:[1, 3, 8, 17, 25, 28, 41, 56, 82]	符号栈为:[#, B, C, D, (, G, ), {, I]	产生式为:I -> int
[]
第18步是移进操作	状态栈为:[1, 3, 8, 17, 25, 28, 41, 56, 82, 94]	符号栈为:[#, B, C, D, (, G, ), {, I, id]
=
...

Semantics.java

语义分析代码

out.txt

四元组

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
1 (=,bgs,/,w)
2 (=,adb,/,z)
3 (=,0,/,i)
4 (=,0,/,max)
5 (=,1,/,a[0])
6 (=,4,/,a[1])
7 (=,6,/,a[2])
8 (=,2,/,a[3])
9 (=,8,/,a[4])
10 (=,9,/,a[5])
11 (j<,i,6,13)
12 (j,/,/,19)
13 (j<,max,a[i],15)
14 (j,/,/,16)
15 (=,a[i],/,max)
16 (+,i,1,T1)
17 (=,T1,/,i)
18 (j,/,/,11)
w int26
z int26
bgs int26
adb int26

Complie.java

产生汇编语言

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
1 mov ax,0
2 mov i,ax
3 mov ax,i
4 mov bx,6
5 cmp ax,bx
6 jl 8
7 jmp 14
8 mov ax,i
9 add ax,1
10 mov T1,ax
11 mov ax,T1
12 mov i,ax
13 jmp 3