2016-04-20 4 views
-1

Ich möchte die LOOP Anweisung verwenden, um diese Zeichenfolge in der Montage drucken:Assembly Schleife char

abcccbcccabcccbccc

Wir haben ab, ccc, b und dann Sicherung ab und dann ccc.

Ich hoffe, ich werde mit Ihrer Hilfe einige Lösungen finden.

Ich benutze Emu, um die Quelle zu kompilieren!

.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 
+0

Was die spezifisch ist Problem, das Sie sehen? Was funktioniert nicht? –

+0

der Ausgang ist: Aa Bb Cc Dd Ee, und ich möchte sein: abcccbcccabcccbccc – user6128930

+0

Versuchen Sie, ein wenig besser zu erklären, welche Art von Algorithmus Sie wollen, weil es viele Möglichkeiten gibt, um Ihr Problem zu lösen. –

Antwort

0

Next 2 kleine Programme sind zwei mögliche Lösungen für Ihr Problem:

LÖSUNG # 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 

LÖSUNG # 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