程序集循环字符



我想使用 LOOP 指令在汇编中打印此字符串:

中外经社

我们有 abcccb 然后备份到 ab 然后ccc

我希望我能在你的帮助下找到一些解决方案。

我正在使用 emu 编译源代码!

.model small
.stack 200h
.code
main PROC
  mov ah, 0      
  mov al, 12h   ; Clear screen
  int 10h
  mov ah, 3    
  mov bh, 0     ; get cursor
  int 10h
  mov ah, 2      
  mov bh, 0     ;set cursor
  mov dl,12
  int 10h
  mov cx, 5     ; counter
  mov dl, 65    ; ASCII of 'A'   
t1:
  mov ah, 2h
  int 21h
  add dl, 32    ; 97 - 65 - convert to LC
  mov ah, 2h
  int 21h
  sub dl,31     ;remove the 32 added, but increment
  push dx       ;save DX on stack
  mov dl, 32    ;space character
  mov ah, 2h
  int 21h
  pop dx        ;return DX from stack
  loop t1
  mov ah, 4Ch   ;exit DOS program 
  mov al, 00h   ;return code = 0
  int 21h
ENDP
END main
接下来的

2 个小程序是 2 种可能的解决方案:

解决方案#1

.stack 100h
.data
txt db 'abcccbccc$' ;STRING TO DISPLAY.
.code
mov ax, @data       ;INITIALIZA DATA SEGMENT.
mov ds, ax
mov cx, 3           ;DISPLAY STRING 3 TIMES.
t1:
mov ah, 9
mov dx, offset txt
int 21h
loop t1
mov ax, 4c00h       ;TERMINATE PROGRAM.
int 21h

解决方案#2

.stack 100h
.data
s1 db 'ab$'         ;STRING TO DISPLAY.
s2 db 'ccc$'        ;STRING TO DISPLAY.
s3 db 'b$'          ;STRING TO DISPLAY.
.code
mov ax, @data       ;INITIALIZA DATA SEGMENT.
mov ds, ax
mov cx, 12          ;DISPLAY THE 4 STRING 3 TIMES.
mov bl, 1           ;1 = DISPLAY STRING S1.
                    ;2 = DISPLAY STRING S2.
                    ;3 = DISPLAY STRING S3.
                    ;4 = DISPLAY STRING S2.
mov ah, 9           ;NECESSARY TO DISPLAY STRINGS.
t1:
;BL TELLS WHAT TO DO.
cmp bl, 1
je  string1         ;BL=1 : DISPLAY S1.
cmp bl, 2
je  string2         ;BL=2 : DISPLAY S2.
cmp bl, 3
je  string3         ;BL=3 : DISPLAY S3.
;string4:           ;BL=4 : DISPLAY S2.
mov dx, offset s2   
int 21h
jmp continue        ;SKIP NEXT DISPLAYS.
string1:
mov dx, offset s1
int 21h 
jmp continue        ;SKIP NEXT DISPLAYS.
string2:
mov dx, offset s2
int 21h
jmp continue        ;SKIP NEXT DISPLAYS.
string3:
mov dx, offset s3
int 21h
continue:
inc bl              ;BL TELLS WHAT TO DO.
cmp bl, 4           
jbe nextstring      ;IF BL < 4
mov bl, 1           ;BL STARTS AGAIN.
nextstring:
loop t1
mov ax, 4c00h       ;TERMINATE PROGRAM.
int 21h