汇编刷题:求一到100内的偶数之和(本程序将和按十六进制输出)

DATA SEGMENT

TS DB 0

HD DB 0

TE DB 0

BI DB 0

DATA ENDS

 

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START:

MOV AX,DATA

MOV DS,AX

 

MOV CX,100

MOV AX,0

 

SIGN:

MOV BX,CX

TEST BX,01H

JZ ADD_SUM

NEXT:

LOOP SIGN

 

MOV TS,AH

AND TS,0F0H

MOV HD,AH

AND HD,0FH

MOV TE,AL

AND TE,0F0H

MOV BI,AL

AND BI,0FH

 

MOV DL,TS

CMP DL,09H

JA BIG_TS

ADD DL,30H

SHOW_TS:

MOV AH,02H

INT 21H

 

MOV DL,HD

CMP DL,09H

JA BIG_HD

ADD DL,30H

SHOW_HD:

MOV AH,02H

INT 21H

 

MOV DL,TE

CMP DL,09H

JA BIG_TE

ADD DL,30H

SHOW_TE:

MOV AH,02H

INT 21H

 

MOV DL,BI

CMP DL,09H

JA BIG_BT

ADD DL,30H

SHOW_BT:

MOV AH,02H

INT 21H

 

MOV AH,4CH

INT 21H

 

ADD_SUM:

ADD AX,WORD PTR BX

JMP NEXT

 

BIG_TS:

MOV CL,4

SHR DL,CL

SUB DL,0AH

ADD DL,41H

JMP SHOW_TS

 

BIG_HD:

MOV CL,4

SHR DL,CL

SUB DL,0AH

ADD DL,41H

JMP SHOW_HD

 

BIG_TE:

MOV CL,4

SHR DL,CL

SUB DL,0AH

ADD DL,41H

JMP SHOW_TE

 

BIG_BT:

MOV CL,4

SHR DL,CL

SUB DL,0AH

ADD DL,41H

JMP SHOW_BT

 

CODE ENDS

END START

 

posted @ 2019-03-15 22:21  IT蓝月  阅读(559)  评论(0编辑  收藏  举报
Live2D