在DOSBox中运行ml program.asm时从8086程序无输出

问题描述

我从Geeks-for-Geeks site获得了这段代码,但是有很多缩进错误,我将代码更改为以下代码,但是,当使用MASM和DOSBox运行代码时,没有任何输出。

我应该得到的输出,根据该站点,我应该得到20,但是我什么也没得到,代码另存为pro.asm,并且我使用的是DOSBox版本0.74。 为了在DOSBox中获得o / p,

mount c c:\8086
c:
ml pro.asm

代码:

;8086 program to convert a 16-bit decimal number to octal 

.MODEL SMALL 
.STACK 100H 
.DATA 
d1 dw 16 
.CODE 
        MAIN PROC FAR 
        MOV ax,@DATA
        MOV ds,ax

;load the value stored in variable d1 
        MOV ax,d1

;convert the value to octal
;print the value 
        CALL PRINT
 
;interrupt to exit
        MOV AH,4CH 
        INT 21H 

        MAIN ENDP 
        PRINT PROC 

;initialize count   
        MOV cx,0 
        MOV dx,0 

label1:          ;if ax is zero 
        cmp ax,0
        je print1 

;initialize bx to 8
        mov bx,8 
  
;divide it by 8 to convert it to octal 
        div bx  

;push it in the stack   
        push dx 

;increment the count
        inc cx 

;set dx to 0 
        xor dx,dx 
        jmp label1 

print1:            ;check if count is greater than zero 
        cmp cx,0 
        je exit

;pop the top of stack 
        pop dx 

;add 48 so that it 
;represents the ASCII 
;value of digits 
        add dx,48 

;interrupt to print a 
;character 
       mov ah,02h 
       int 21h 

;decrease the count 
       dec cx
       jmp print1
 
exit :  ret 
        PRINT ENDP 
        END MAIN 

我得到的输出可以在

output

下看到

解决方法

您的代码看起来还不错。屏幕快照显示您仅汇编并链接了代码,但未实际运行它。要运行它,请输入:

pro.exe

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...