簡體   English   中英

匯編循環:TASM on 8086 (DosBox) Solve on how to Horizontal and Vertical Number

[英]Loops in Assembly: TASM on 8086 (DosBox) Solve on how to Horizontal and Vertical Number

我的代碼是:

Mov ah,02
Mov cl,0A
Mov dh,30
Mov dl,dh
Int 21

Mov dl,20
Int 21

Add dh,01
Loop 0106

Mov ah,02
Mov cl,09
Mov bl,31
Mov dl,0A
Int 21

Mov dl,0D
Int 21

Mov dl,bl
Int 21

Add bl,01
Loop 0106

在此處輸入圖像描述

與你的標題所說的使用 TASM 相反,屏幕截圖和代碼對應於 DOS DEBUG.EXE。 請參閱有關編寫 TASM 程序的信息

讓我們從注釋代碼開始(您應該在發布之前完成的事情:):

  Mov ah,02     ; DOS.PrintCharacter
  Mov cl,0A     ; Count for the 1st loop
  Mov dh,30     ; '0'
0106 is address of top of the 1st loop.
  Mov dl,dh
  Int 21        ; This prints a digit

  Mov dl,20     ; ' '
  Int 21        ; This interjects a space character

  Add dh,01     ; Next character
  Loop 0106     ; Go to top of the 1st loop

  Mov ah,02     ; DOS.PrintCharacter
  Mov cl,09     ; Count for the 2nd loop
  Mov bl,31     ; '1'
01?? is address of top of the 2nd loop.
  Mov dl,0A     ; Linefeed
  Int 21

  Mov dl,0D     ; Carriage return
  Int 21

  Mov dl,bl     ; Current character
  Int 21

  Add bl,01     ; Next character
  Loop 0106     ; Go to top of the 1st (????????) loop

第一個循環

  • 當您的程序啟動時,您不應依賴預先存在的寄存器內容。 不要假設CX寄存器為 0。您需要使用mov cx, 0A (十進制 10)初始化循環計數器。 loop指令取決於CX ,而不僅僅是CL
  • 屏幕截圖第一行的數字之間沒有任何空格。 您應該刪除插入空格字符的行Mov dl,20 Int 21

第二個循環

  • 這里可以用mov cl, 09 (十進制 9)初始化循環計數器,因為之前的loop指令會將CX寄存器保留為 0。
  • 因為這是一個單獨的循環,所以loop指令必須將 go 發送到另一個目的地。

該程序

  Mov  ah,02     ; DOS.PrintCharacter
  Mov  cx,0A     ; Count for the 1st loop
  Mov  dl,30     ; '0'
0107 is address of top of the 1st loop.
  Int  21        ; This prints a digit
  Add  dl,01     ; Next character
  Loop 0107      ; Go to top of the 1st loop

  Mov  cl,09     ; Count for the 2nd loop
  Mov  bl,31     ; '1'
0112 is address of top of the 2nd loop.
  Mov  dl,0D     ; Carriage return
  Int  21
  Mov  dl,0A     ; Linefeed
  Int  21
  Mov  dl,bl     ; Current character
  Int  21
  Add  bl,01     ; Next character
  Loop 0112      ; Go to top of the 2nd loop

  int  20        ; DOS.Terminate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM