常用码制转换有:BCD码转二进制、二进制转BCD码、ASCⅡ码转BCD码、BCD码转ASCⅡ码、二进制转ASCⅡ码、ASCⅡ码转二进制码。
一、实习题目
ASCⅡ码转二进制码程序实验
二、实习目的
掌握码制转换的基本原理及相应的转换程序的编写方法。
三、实习内容
将ASCⅡ码数据转换成二进制数据。要求从键盘上输入十进制整数(假定范围0~32767),然后转换成二进制格式存储。
DATA SEGMENT
NUM DB 6 DUP("0")
RESULT DB 10 DUP("0")
SUM DB 8 DUP("0")
C10 DB 10
C16 DW 8
STR0 DB 0AH,0DH,"INPUT A NUMBER (0-32767):",0AH,0DH,"$"
STR1 DB 0AH,0DH,"The Number is:",0AH,0DH,"$";
STR2 DB 0AH,0DH,"RESUALT IS ",0AH,0DH,"$";
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA;
MOV DS,AX;
MOV CX,5;
MOV BX,0;
LEA DX,STR0
MOV AH,09H;
INT 21H;
INPUT:
MOV AH,01H;
INT 21H;
CMP AL,0DH;
JE ONE
MOV NUM[BX],AL;
INC BX;
LOOP INPUT
ONE:
MOV NUM[5],BL;
MOV AH,02H;
MOV CL,NUM[5];
MOV CH,0;
MOV BX,0;
LEA DX,STR1
MOV AH,09H;
INT 21H;
SHOWNUM:
MOV DL,NUM[BX]
INC BX;
; LEA DX,NUM;
MOV AH,02H;
INT 21H;
LOOP SHOWNUM;
;START TO TRANSLATE
TRAN:
MOV CL, NUM[5]
MOV CH,0;
MOV BX,0;
MOV AX,0;
DEC CL;
NEXT:
MOV AL,NUM[BX]
SUB AL,'0'
MUL C10;
INC BX;
LOOP NEXT
ADD AL,NUM[BX]
SUB AL,'0'
MOV BX,C16;
MOV CX,BX;
DEC BX;
MOV DX,AX;
PUTOUT:
SHR DX,1;
JNC ADD0
ADD1:
MOV SUM[BX],"1"
JMP ADDOVER
ADD0:
MOV SUM[BX],"0"
ADDOVER:
DEC BX;
LOOP PUTOUT
LEA DX,STR2
MOV AH,09H;
INT 21H;
MOV AH,02H;
MOV CX,C16;
MOV BX,0
GETRESULT:
MOV DL,SUM[BX]
INT 21H
INC BX;
LOOP GETRESULT
MOV AX,4C00H;
CODE ENDS
END START