The task is to write an x86 assembly program that checks all capital latters and prints A and O, but I don't know how to write the program. I tried this:
.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
Before you print the character you can check if the character is A
or O
, print it, INT 21H
, if so or skip over the INT 21H
:
....
LOOP:
if( DL == 'A' )
goto PRINT;
if( DL != 'O' )
goto SKIP;
PRINT:
putc(DL);
SKIP:
...
in assembly:
...
@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
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.