Assembly 使用一个寄存器的正弦波

Assembly 使用一个寄存器的正弦波,assembly,8051,Assembly,8051,所以我的任务是创建一个正弦波我想出了这个,它使用两个寄存器和作品 DAC EQU 0600h ;DAC memory mapped at address 600h tbl_len EQU 24 ;length of sine wave table ORG 8100H ;start of program sine: mov R7, #tbl_len ;initialise table counter mov R6, #0 ;initiali

所以我的任务是创建一个正弦波我想出了这个,它使用两个寄存器和作品

 DAC    EQU 0600h   ;DAC memory mapped at address 600h
tbl_len EQU 24  ;length of sine wave table

    ORG 8100H       ;start of program

sine:   mov R7, #tbl_len    ;initialise table counter
    mov R6, #0  ;initialise table pointer

sloop:  mov dptr, #table    ;load dptr with address of table
    mov a, R6   ;load acc with table pointer
    movc    a, @a+dptr  ;read from table + table pointer

    mov dptr, #DAC  ;load dptr with 0600 DAC base address
    movx    @dptr, a    ;Output table value from DAC
    acall   delay
    inc R6  ;inc table pointer
    djnz    R7, sloop   ;dec table counter until zero
    sjmp  sine  ;Repeat loop

delay:  mov R0, #11
loop:   djnz    R0, dloop   ;go around this loop 11 times
    ret

table:  DB  1,5,18,38,65,95,128,161,192,218,238,251
    DB  255,251,238,218,192,161,128,95,65,38,18,5

现在我被要求只使用一个寄存器。我有点困惑,尽管我觉得这可能是一个非常简单的解决方案。任何提示都很好。

您只需使用
R6
,然后将
inc R6
#tbl_len
和分支(例如)进行比较(如果不相等)。在这种情况下,不再需要使用
R7
。谢谢,这很有意义。真不敢相信我没看到。