汇编语言实现显示16进制数

将内存单元存储的8个两位16进制数:01H, 25H, 38H, 62H, 8DH, 9AH, BAH,  CEH依次显示在屏幕上。

直接转换。

DATA SEGMENT
BUF DB 01H,25H,38H,62H,8DH,9AH,0BAH,0CEH
N DW $-BUF
X DW 0
DATA ENDS
CODE SEGMENT
   ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
       MOV DS,AX
       MOV CX,N
BE:    MOV N,CX
       MOV BX,X

       MOV DL,BUF[BX]
       INC BX
       MOV X,BX
       CALL DELY
       MOV CX,N
       CMP CX,1
       JE FINISH
       MOV DL,','
       MOV AH,2
       INT 21H
       LOOP BE
FINISH:MOV AX,4C00H
       INT 21H

DELY   PROC NEAR
       MOV BL,DL
       MOV CL,4
       SHR DL,CL
       OR DL,30H
       CMP DL,39H
       JBE AD1
       ADD DL,7
AD1:   MOV AH,2
       INT 21H
       MOV DL,BL
       AND DL,0FH
       OR DL,30H
       CMP DL,39H
       JBE AD2
       ADD DL,7
AD2:   MOV AH,2
       INT 21H
       MOV DL,'H'
       MOV AH,2
       INT 21H
       RET
DELY ENDP
CODE ENDS
     END START

打表法:

DATA SEGMENT
BUF DB 01H,25H,38H,62H,8DH,9AH,0BAH,0CEH
N DW $-BUF
ASCII DB 30H,31H,32H,33H,34H,35H,36H,37H,38H,39H
      DB 41H,42H,43H,44H,45H,46H
X DW 0
Y DB 0
DATA ENDS
CODE SEGMENT
   ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
       MOV DS,AX
       MOV CX,N

BE:    MOV N,CX
       MOV BX,X
       MOV DL,BUF[BX]
       INC BX
       MOV X,BX

       MOV CX,N
       CMP CX,1
       JE FINISH
       MOV DL,','
       MOV AH,2
       INT 21H
       LOOP BE

FINISH:MOV AX,4C00H
       INT 21H
DELY   PROC NEAR
       MOV Y,DL
       MOV CL,4
       SHR DL,CL
       MOV BX,OFFSET ASCII
       MOV AL,DL
       AND AL,0FH
       XLAT
       MOV DL,AL
       MOV AH,2
       INT 21H
       MOV AL,Y
       AND AL,0FH
       XLAT
       MOV DL,AL
       MOV AH,2
       INT 21H

       MOV DL,'H'
       MOV AH,2
       INT 21H
       RET
DELY ENDP
CODE ENDS
     END START

 

你可能感兴趣的:(汇编)