基于TEC-8指令系统编写汇编程序

在TEC-8实验系统中,基于TEC-8指令系统编写汇编程序,从1开始,产生255以内的等差数列(差值是3),并保存数列的数据个数N和最后一个数列值S,S,N都存放在双端口存储器中,在实验系统中连线,运行程序,并在数据总线上查看结果S,N;

基于TEC-8指令系统编写汇编程序的代码:


ORG 0
START:  LDA #1           ; Load the first number into the accumulator
        STA N           ; Store the first number in the memory location for N
        LDA #255         ; Load the maximum limit into the accumulator
        STA LIMIT       ; Store the maximum limit in the memory location for LIMIT
        LDA #3           ; Load the difference into the accumulator
        STA D           ; Store the difference in the memory location for D
LOOP:   LDA N           ; Load N into the accumulator
        ADD D           ; Add the difference to the accumulator
        STA N           ; Store the new number in the memory location for N
        LDA N           ; Load the new number into the accumulator
        CMP LIMIT       ; Compare the new number with the maximum limit
        BGT DONE        ; If the new number is greater than the maximum limit, exit the loop
        STA S           ; Store the new number in the memory location for S
        INC COUNT       ; Increment the counter for the number of terms
        JMP LOOP        ; Repeat the loop
DONE:   LDA S           ; Load the final number into the accumulator
        OUT             ; Output the final number
        LDA COUNT       ; Load the count into the accumulator
        OUT             ; Output the count
        HLT             ; Halt the program

N:      DAT             ; Memory location for the first number
LIMIT:  DAT             ; Memory location for the maximum limit
D:      DAT             ; Memory location for the difference
S:      DAT             ; Memory location for the final number
COUNT:  DAT 0           ; Memory location for the count

在实验系统中,将代码烧录到ROM中,并将双端口存储器地址为0的位置连接到数据总线上。然后运行程序即可得到最后一个数列值S和数列数据个数N。