【问题标题】:Printing array -- getting strange output (emu8086)打印数组——得到奇怪的输出(emu8086)
【发布时间】:2016-02-29 20:54:15
【问题描述】:

我的问题与以汇编 8086 语言打印数组有关。 我使用“emu8086”程序。

以下部分对我来说似乎很好(我是初学者),但我得到的结果是: *P000,而不是:12345。

  Main:

A DB 1,2,3,4,5 //my array

SUB SI, SI    //SI stands for counter and index here
LEA BX, A  

loop3:
MOV DX, [BX + SI] 

ADD DX, 30h //converting digit into character
MOV Ah, 2h
int 21h    //displaying the character in console window

INC SI
CMP SI, 5
JNE loop3             

end Main 

请您解释一下我的功能有什么问题吗? 提前谢谢你!

【问题讨论】:

    标签: assembly emu8086


    【解决方案1】:

    问题中的程序不完整。缺少两条重要的线:

        MOV AX, @DATA
        MOV DS, AX
    

    Here我找到了这些的目的。


    下面列出了让我改变程序的事情。

    1. 找到了good assembly program on this topic,据此一步步分析每一行代码,理解其中的含义。我认为这个程序说明了一切。

    我发现了一些东西:


    所以我的程序现在看起来是这样的:

        .MODEL SMALL
        .STACK 100H
    
        .DATA
        A DW 1, 2, 3, 4 ; it's my array
    
        .CODE   
    
        MAIN PROC
    
            MOV AX, @DATA
            MOV DS, AX
    
    
            LEA SI, A   ;set SI as offset address of A (of my array)
            MOV BX, 4   ;store the number of digits in BX register
            MOV CX, BX  ;CX is used as a loop counter
    
            LOOP1:
    
                MOV DX, [SI] ; Line 1
                ADD DX, 30h  ;convert digit to char and store in DX
    
                ;Print character stored in DX 
                MOV AH, 2h
                INT 21h
    
                ;Store in DX the ASCII code for 'space' character 
                MOV DX, 20h
                ;Print ' ' = space 
                INT 21h 
    
    
                ADD SI, 2 ;SI = SI + 2
    
            LOOP LOOP1 ; jump to label 'LOOP1' while CX != 0
    
        MAIN ENDP
    
    • 第 1 行的含义我找到了here
    • Here我找到了用于打印字符的说明,以及所有解释。
    • ASCII Table 很有帮助。
    • 关于LOOP指令。

    【讨论】:

    • 学了很多,却忽略了DOS显示功能只对DL寄存器起作用,对DX寄存器不起作用
    • 为什么你的小程序还要费心使用 BX 寄存器?
    • @Fifoernik 谢谢你的评论。我想我应该更多地了解装配。
    【解决方案2】:

    您需要验证DS 寄存器是否加载了正确的值,否则您的内存读取将来自错误的段。

    【讨论】:

    • 嗨。我已经应用了您建议的更改,但没有任何改变。又是同样的输出。
    【解决方案3】:
    .MODEL SMALL
    .DATA
    
        ARRAY DW 1,2,3,4,5
    .CODE
    .STARTUP
    
      MOV CX,5      
    
     MOV SI,OFFSET ARRAY
    
    LOP:
        MOV DX,[SI]  
        ADD DX,30H
    
        MOV AH,2H
        INT 21H  
    
        INC SI 
        INC SI
    
    LOOP LOP
    .EXIT
    END
    

    试试这个

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      相关资源
      最近更新 更多