;輸入4位16進位制數,將其以10進位制的形式顯示 CODE SEGMENT ASSUME CS:CODE ORG 100H START: JMP BBB MSG DB 10,13,"please input a number(hex):","$" T1 DB 0,1,2,3,4,5,6,7,8,9,10,10,11,11,12,12,13,13,14,14,15,15 T2 DB "0","1","2","3","4","5","6","7","8","9" DB "a","A","b","B","c","C","d","D","e","E","f","F" BBB: PUSH CS POP DS PUSH CS POP ES LEA DX,MSG MOV AH,9 INT 21H ;---------------------- MOV AX,0 MOV CX,4 PUSH AX @0: MOV AH,1 INT 21H LEA SI,T2 LEA DI,T1 @1: CMP AL,[SI] JE @2 INC SI INC DI JMP @1 @2: MOV AL,[DI] MOV AH,0 MOV SI,AX POP AX MOV BL,16 MOV BH,0 MUL BX ADD AX,SI PUSH AX LOOP @0 LINE0: POP AX CALL DISPNUM ;------------------------- MOV AH,4CH INT 21H; 顯示十進位制整型數值子程式 DISPNUM PROC NEAR ; 將要顯示的資料放入AX中 JMP DISPSUB Y DB 10,13,0,0,0,0,0,"$" DISPSUB: MOV DX,0 MOV BX,10 DIV BX MOV BYTE PTR[Y+6],DL ;儲存個位 MOV DX,0 DIV BX MOV BYTE PTR[Y+5],DL ;儲存十位 MOV DX,0 DIV BX MOV BYTE PTR[Y+4],DL ;儲存百位 MOV DX,0 DIV BX MOV BYTE PTR[Y+3],DL ;儲存千位 MOV BYTE PTR[Y+2],AL ;儲存萬位 ;------------------------ MOV AL,BYTE PTR[Y+2] ADD AL,30H ;萬位轉ASC2 MOV BYTE PTR[Y+2],AL ;--------------------------- MOV AL,BYTE PTR[Y+3] ADD AL,30H ;千位轉ASC2 MOV BYTE PTR[Y+3],AL ;--------------------------- MOV AL,BYTE PTR[Y+4] ADD AL,30H ;百位轉ASC2 MOV BYTE PTR[Y+4],AL ;-------------------------- MOV AL,BYTE PTR[Y+5] ADD AL,30H ;十位轉ASC2 MOV BYTE PTR[Y+5],AL ;--------------------------- MOV AL,BYTE PTR[Y+6] ADD AL,30H ;個位轉ASC2 MOV BYTE PTR[Y+6],AL ;----------------------------- MOV DI,1 DISP1: INC DI CMP DI,6 JE DISPEXIT CMP BYTE PTR[Y+DI],"0" JNE DISPEXIT MOV BYTE PTR[Y+DI]," " JMP DISP1 DISPEXIT: MOV AH,9 LEA DX,Y INT 21H RET DISPNUM ENDP CODE ENDS END START
;輸入4位16進位制數,將其以10進位制的形式顯示 CODE SEGMENT ASSUME CS:CODE ORG 100H START: JMP BBB MSG DB 10,13,"please input a number(hex):","$" T1 DB 0,1,2,3,4,5,6,7,8,9,10,10,11,11,12,12,13,13,14,14,15,15 T2 DB "0","1","2","3","4","5","6","7","8","9" DB "a","A","b","B","c","C","d","D","e","E","f","F" BBB: PUSH CS POP DS PUSH CS POP ES LEA DX,MSG MOV AH,9 INT 21H ;---------------------- MOV AX,0 MOV CX,4 PUSH AX @0: MOV AH,1 INT 21H LEA SI,T2 LEA DI,T1 @1: CMP AL,[SI] JE @2 INC SI INC DI JMP @1 @2: MOV AL,[DI] MOV AH,0 MOV SI,AX POP AX MOV BL,16 MOV BH,0 MUL BX ADD AX,SI PUSH AX LOOP @0 LINE0: POP AX CALL DISPNUM ;------------------------- MOV AH,4CH INT 21H; 顯示十進位制整型數值子程式 DISPNUM PROC NEAR ; 將要顯示的資料放入AX中 JMP DISPSUB Y DB 10,13,0,0,0,0,0,"$" DISPSUB: MOV DX,0 MOV BX,10 DIV BX MOV BYTE PTR[Y+6],DL ;儲存個位 MOV DX,0 DIV BX MOV BYTE PTR[Y+5],DL ;儲存十位 MOV DX,0 DIV BX MOV BYTE PTR[Y+4],DL ;儲存百位 MOV DX,0 DIV BX MOV BYTE PTR[Y+3],DL ;儲存千位 MOV BYTE PTR[Y+2],AL ;儲存萬位 ;------------------------ MOV AL,BYTE PTR[Y+2] ADD AL,30H ;萬位轉ASC2 MOV BYTE PTR[Y+2],AL ;--------------------------- MOV AL,BYTE PTR[Y+3] ADD AL,30H ;千位轉ASC2 MOV BYTE PTR[Y+3],AL ;--------------------------- MOV AL,BYTE PTR[Y+4] ADD AL,30H ;百位轉ASC2 MOV BYTE PTR[Y+4],AL ;-------------------------- MOV AL,BYTE PTR[Y+5] ADD AL,30H ;十位轉ASC2 MOV BYTE PTR[Y+5],AL ;--------------------------- MOV AL,BYTE PTR[Y+6] ADD AL,30H ;個位轉ASC2 MOV BYTE PTR[Y+6],AL ;----------------------------- MOV DI,1 DISP1: INC DI CMP DI,6 JE DISPEXIT CMP BYTE PTR[Y+DI],"0" JNE DISPEXIT MOV BYTE PTR[Y+DI]," " JMP DISP1 DISPEXIT: MOV AH,9 LEA DX,Y INT 21H RET DISPNUM ENDP CODE ENDS END START