任务是编写一个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
答案 0 :(得分:2)
在打印角色之前,您可以检查角色是A
还是O
,打印,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
...