【问题标题】:The output is not displayed in its entirety [8086 assembly]输出未完整显示 [8086 程序集]
【发布时间】:2016-03-23 16:06:00
【问题描述】:
    ;The number of repetition of each character in the string


    .MODEL       small 
    .STACK       100h              
    .DATA

    msg3         db 13,10,'Enter a string up to 200 characters:$'         
    msg4         db       '      $'
    msg5         db 13,10,'Hit any key to exit',13,10,'$' 
    crlf         db 13,10,'$'           
    char         db 0
    repet        db 0
    mone1        dw 0  
    mone2        dw 0
    dig1         db 0
    dig2         db 0
    dig3         db 0 
    arr          db 256 dup(0)
    str          db 200
    strlen       db 0
    strtxt       db 200 dup(0)

    .CODE 

                 mov AX,@data
                 mov DS,AX

                 call GetString
                 call UpdateArr
                 call Repetitions
                 call EndProject
    GetString:   lea DX,msg3       ;Show msg3 on screen
                 mov AH,09h
                 int 21h

                 lea DX,str        ;Accept a string
                 mov AH,0ah
                 int 21h 

                 lea DX,crlf       ;New line for the output    
                 mov AH,09h
                 int 21h

    UpdateArr:   xor CX,CX         ;Nullify CX register
                 mov CL,strlen     
                 cmp mone1,CX      ;Compare the location of the character in str
                                    string to the full length of str 
                 jb  Below         ;If below, jump Below
                 ret

    Below:       lea SI,strtxt     ;Reach a character in str string
                 add SI,mone1     
                 mov CL,[SI]      
                 mov char,CL       ;Move the character from CL to char operand
                 inc mone1         ;Increase mone1 in one

                 lea BX,arr        ;Nullify CX register
                 mov CL,char
                 add BX,CX
                 inc [BX]          ;Increace the ascii value place of the character
                                    in arr counter array in one

                 jmp UpdateArr         

    Repetitions: lea BX,arr        ;Reach the several iterations of each ascii
                                    character
                 add BX,mone2
                 xor CX,CX
                 mov CL,[BX]
                 mov repet,CL      ;Move the several iterations from CL to repet
                                    operand
                 inc mone2

                 cmp repet,0       ;Compare repet to zero 
                 je Repetitions    ;If there is no repetition at all, jump to
                                    Repetitions

                 xor AX,AX         ;Nullify AX register
                 xor BX,BX         ;Nullify BX register

                 mov AL,repet
                 mov BL,10         ;Divide AL by 10, result in AL, rest in AH
                 div BL

                 mov dig3,AH       ;Move the rest of the devision in AH to dig3
                                    operand
                 mov AH,0          ;Nullify AH

                 mov BL,10         ;Divide the result in AL by 10, new result in AL,
                                    rest in AH
                 div BL

                 mov dig2,AH       ;Move the rest of the devision in AH to dig2
                                    operand
                 mov dig1,AL       ;Move the result of the devision in AL to dig1
                                    operand

                 add dig1,'0'      ;Change digit from binary to ascii
                 add dig2,'0'
                 add dig3,'0' 

                 lea BX,msg4       ;Put address of msg4 in BX
                 dec mone2         ;Decreace mone2 in one
                 mov AX,mone2      
                 mov [BX],AL       ;Put mone2 (the ascii character) in msg4 
                 inc mone2         ;Increace mone2 in one

                 mov AL,'('
                 mov [BX+1],AL     ;Put '(' in msg4

                 mov AL,dig1
                 mov [BX+2],AL     ;Put dig1 in msg4

                 mov AL,dig2
                 mov [BX+3],AL     ;Put dig2 in msg4

                 mov AL,dig3
                 mov [BX+4],AL     ;Put dig3 in msg4

                 mov AL,')'
                 mov [BX+5],AL     ;Put ')' in msg4

                 lea DX,msg4       ;Show output line msg4
                 mov AH,09h
                 int 21h

                 cmp mone2,256     ;Compare mone2 to 256
                 jle Repetitions   ;If not all the ascii characters were checked,
                                    jump to Repetitions

                 ret                  

    EndProject:  lea DX,msg5       ;show msg5 on screen 
                 mov AH,09h
                 int 21h     

                 mov AH,01h        ;read a char
                 int 21h

                 mov AH,4CH        ;end program
                 int 21h
                 ret
    END   

输入是一个最多 200 个字符的字符串(“str”)。它继续字符串并增加计数器数组(“arr”)中字符串中每个字符的ascii值位置。 输出是每个 ascii 字符 [256 个字符(计数器数组的长度)] 的多次迭代。 例如:

a(005)3(016)%(109)

问题是,如果我写了五个以上的字符,它只会显示其中的五个而不是其余的(全部)。 代码中的问题是什么?

重要细节-

mone1 表示 counter1,mone2 表示 counter2

谢谢!

【问题讨论】:

  • 您是否使用过调试器?
  • 是的,我不明白问题的根源是什么。
  • 出于好奇,您发布的这段代码是否真的为您编译?
  • 我知道你说了什么,但我再问一次,你真的能够组装你实际发布在这里的代码而没有错误吗?例如,有些行的 cmets 不以分号 ; 开头,变量 strSTR 指令冲突,并且行 inc [BX] 没有指定宽度,而且我不知道 MASM/TASM 将如何猜测大小。我认为它必须是inc byte ptr [BX]??如果这确实可以编译,我很想知道您使用的是什么汇编程序(和汇编程序版本)。
  • 是的,我认为@WeatherVane(关于 cmets)只是提出来了。我在问题中真正错过的是标签 EMU8086 它将盲目地将inc [bx] 默认为一个字节,并解释了为什么它与STR 标签没有问题。

标签: assembly x86-16 emu8086


【解决方案1】:

您的子程序GetString: 缺少ret 指令。所以它落入UpdateArr:,它确实返回,但随后又被调用,所以谁知道它有什么影响,我不打算去探索它是否满足观察到的行为。

【讨论】:

  • 最后我意识到我完全没有问题,但唯一的问题是当DOS屏幕很小时,它会显示所有输出,但是当我放大屏幕时却没有显示所有输出输出。你知道为什么吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-16
  • 2015-01-05
  • 2012-05-04
  • 2016-04-15
  • 1970-01-01
相关资源
最近更新 更多