0

任务是编写一个 x86 汇编程序,检查所有大写的后者并打印 A 和 O,但我不知道如何编写程序。我试过这个:

.MODEL SMALL
 .STACK 100H

 .DATA
    PROMPT  DB  'The Upper Case Letters from A to Z are : $'

 .CODE
   MAIN PROC
     MOV AX, @DATA                ; initialize DS 
     MOV DS, AX

     LEA DX, PROMPT               ; load and print PROMPT 
     MOV AH, 9
     INT 21H

     MOV CX, 26                   ; initialize CX

     MOV AH, 2                    ; set output function  
     MOV DL, 65                   ; set DL with A

     @LOOP:                       ; loop start
       INT 21H                    ; print character

       INC DL                     ; increment DL to next ASCII character
       DEC CX                     ; decrement CX

     JNZ @LOOP                    ; jump to label @LOOP if CXis 0

     MOV AH, 4CH                  ; return control to DOS
     INT 21H
   MAIN ENDP
 END MAIN
4

1 回答 1

2

在打印字符之前,您可以检查字符是否为AO,打印它,INT 21H如果是,或跳过INT 21H

....
LOOP:
    if( DL == 'A' )
        goto PRINT;
    if( DL != 'O' )
        goto SKIP;
PRINT:
    putc(DL);
SKIP:
...

在组装中:

...
     @LOOP:                       ; loop start
       CMP DL, 'A'                ; if( DL == 'A' )
       JE  @PRINT                 ;   goto PRINT
       CMP DL, 'O'                ; else if( DL != 'O' )
       JNE @SKIP                  ;   goto SKIP
     @PRINT:
       INT 21H                    ; print character
     @SKIP:
       INC DL                     ; increment DL to next ASCII character
       DEC CX                     ; decrement CX
       JNZ @LOOP                  ; jump to label @LOOP if CXis 0
...
于 2013-11-07T09:06:24.183 回答