assembly emu8086组件中的金字塔

92vpleto  于 2023-06-06  发布在  其他
关注(0)|答案(1)|浏览(161)

我需要怎样修改程序,才能得到下面的结果

1
22
333
4444
55555

这是我的程序:

.model small
.stack 100h
.data
    nl db 0dh, 0ah, '$' ; nl = next line
.code
    main proc
    mov ax, @data
    mov ds, ax
    mov cx, 5
    mov bx, 1 
    
    for_1:    
  
    push cx             
    mov dl, 20h ; 20h is ascii code for space   
    mov ah, 02h  
            
    for_2:     
           
    loop for_2      
    mov cx, bx         
    mov dl, '1'     
    mov ah, 02h 
                                               
    for_3: 
   
    int 21h ; printing stars   
             
    loop for_3            
    lea dx, nl           
    mov ah, 09h
    int 21h ; move cursor to the start of next line
    inc bx          
    pop cx          
    loop for_1 
    
    mov ah, 4ch
    int 21h
    main endp
end main

我尝试了我所知道的一切,我管理其他输出,但不能完成这一个。

qvsjd97n

qvsjd97n1#

EuroAssembler这样的现代独立汇编器允许您编写比模拟器更优雅的程序。我在MS Windows的命令提示符下尝试了您的任务:

R:\>type Zeke.asm
Zeke PROGRAM Format=COM
i     %FOR 1..5   ; Repeat the block with increasing i.
        MOV CX,%i
        CALL Line ; Call the Line procedure five times with increasing CX.
      %ENDFOR
      RET         ; Terminate program Zeke.com

Line  PROC        ; Write decimal digit CX times.
      MOV DL,CL
      ADD DL,'0'  ; Convert the binary to decimal digit.
      MOV AH,2    ; DOS function "Write character from DL".
Digit:INT 21h
      LOOP Digit  ; Repeat CX times.
      MOV DL,0Dh
      INT 21h     ; Write Carriage Return.
      MOV DL,0Ah
      INT 21h     ; Write Line Feed.
      RET
     ENDPROC Line
    ENDPROGRAM Zeke

R:\>euroasm.exe Zeke.asm
I0010 EuroAssembler version 20191104 started.
I0020 Current directory is "R:\".
I0180 Assembling source file "Zeke.asm".
I0660 16bit TINY COM file "Zeke.com" created, size=51.
I0650 Program "Zeke" assembled in 3 passes with errorlevel 0.
I0860 Listing file "Zeke.asm.lst" created, size=1597.
I0980 Memory allocation 448 KB. 142 statements assembled in 1 s.
I0990 EuroAssembler terminated with errorlevel 0.

R:\>

当我在模拟器DOSBox中运行程序时:

R:\> Zeke.com
1 
22
333
4444
55555

R:\>

相关问题