assembly 汇编程序8051如何修复非第一个字符的索引

wi3ka0sx  于 2023-10-19  发布在  其他
关注(0)|答案(1)|浏览(100)

我需要一个帮助来解决我的汇编程序8051的代码中的索引问题,代码如下,所以主要问题,无论我写多少字符到文本中,它们仍然显示为字符A,我不知道如何修复它,所以我希望有人能解释这个问题是什么

Start:
                            mov  R0, #00h          ; Initialize the text index counter
    Morse:
                        mov  DPTR, #Text     ; Point to the beginning of the text
                            mov  A, R0 ;offset to acc
    
    NextChar:
                            cjne R0, #00h, LetterSpaceCALL 
                            jmp Continue0
  Continue0:
                            movc A, @A+DPTR            ; Load a character from the text into register A
                            inc  R0
                            cjne A, #'.', nextTest01   ;check for dot
                            jmp endProgram

  nextTest01: cjne A, #' ', nextTest02
              jmp WordSpace    ;check for space
                            
  nextTest02: jz  EndProgram   ; Check if the character is not null (end of text)

;A is character to decode 
    Char:
                            orl  A, #20h      ;convert to lowercase
                            clr  C            ;clear C flag after orl
                            subb A, #'a'      ;calculate the sequence number of the character
              mov  DPTR, #ASCII_TO_MORSE_TABLE ;set pointer to first char ('a')
;find start morse code for next char
;increasing pointer in loop until separate char '!' is not find
  morseCode:
; DPTR now point to start of morse code sequence
              clr A
              movc A, @A+DPTR
              inc dptr ;move pointer to next morse char
              cjne A, #'!', nextTest03 ; not correct work right here because of compare ! to char, he never jump to test03
              jmp Morse ; if '!' then process next char of message
  nextTest03:
                            call VoidCall
              cjne A, #'-', DotCall ;if dot make somethnig (no others chars as '.' are enabled)
              jmp DashCall ; if '-' make something
                            jmp morseCode

    DotCall:
                          call DOT
                            jmp  morseCode

    DashCall:
                          call DASH
                            jmp  morseCode
  VoidCall:
                            call Void
  ret

    WordSpace:
                        call NEXT_WORD      ; Delay between words
                        jmp  Morse

    LetterSpaceCALL:
                            call LetterSpace
                jmp  Continue0

    EndProgram:
                            clr  GREEN_LED
Text: db 'sos.'

ASCII_TO_MORSE_TABLE:db     '.-!', '-...!', '-.-.!', '-..!',    '.!', '..-.!', '--.!',  '....!', '..!', '.---!', '-.-!', '.-..!',   '--!', '-.!', '---!', '.--.!', '--.-!', '.-.!', '...!', '-!', '..-!', '...-!', '.--!', '-..-!', '-.--!', '--..!' 
                          ; | a  | |  b   | |  c  |  |  d  |     |e|  |  f  |  | g   |  |  h   | | i  | |  j   | |  k  | |  l  |  | m  | | n  | |  o  | |  p  |  |  q  |  |  r |  |  s  | | t | |  u |  |  v  |  |  w  | |  x  |  |  y  |  |  z  |
eimct9ow

eimct9ow1#

您正在计算Char:morseCode:之间的莫尔斯表的索引,但从未使用该值。
相反,你只需莫尔斯的第一个字符,这是“A”。
您需要使用索引来跳过,直到找到实际字符的莫尔斯码。您可以通过查看表并考虑标记('!')来完成此操作。或者,像其他人建议的那样,将每个表条目扩展到例如8个字节,并计算地址。
如果使用搜索方法,则需要将索引保存在ACC以外的其他位置(寄存器A,累加器),因为需要该寄存器通过movc A, @A+DPTR读取代码。

相关问题