汇编 ASCII 转换 怎么用汇编语言把字符转化成ascii

\u6c47\u7f16\u7a0b\u5e8f\u8bbe\u8ba1\uff1a\u600e\u4e48\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u6210ASCII\u7801\u503c\uff1f

\u6211\u81ea\u5df1\u7b80\u5355\u7f16\u4e86\u4e00\u4e2a\u3002\u3002\u3002 \u4e0b\u9762\u7684\u7a0b\u5e8f\u662f16\u4f4d\u6c47\u7f16\uff0c\u4ee5\u5341\u8fdb\u5236\u657089158\u4e3a\u4f8b\uff0c\u7f16\u8bd1\u901a\u8fc7\uff0c\u8fd0\u884c\u6b63\u786e\u3002

; Program Name: Dec_ASCII.asm

Dec_ASCII SEGMENT
ASSUME CS:Dec_ASCII,DS:Dec_ASCII
ORG 100H

Start: jmp Begin

ASCII DB 5 dup(' ') ;\u4fdd\u5b58\u5341\u8fdb\u5236\u65e0\u7b26\u53f7\u6570\u7684ASCII
ASCII_End DB '$' ;\u5b57\u7b26\u4e32\u7ed3\u675f\u6807\u5fd7

Decimal DW 89158 ; \u5341\u8fdb\u5236\u65e0\u7b26\u53f7\u6570\uff0c\u6700\u592765535\u3002

Begin: lea di,ASCII_End ; \u5b57\u7b26\u4e32\u5c3e\u5730\u5740
dec di
mov bx,10 ; \u7528\u4e8e\u966410\uff0c\u53d6\u5546\u6570\u548c\u4f59\u6570
std ;\u8bbe\u7f6e\u53d8\u5740\u5bc4\u5b58\u5668\u53d8\u5740\u65b9\u5411
mov ax,Decimal ; \u53d6\u5341\u8fdb\u5236\u65e0\u7b26\u53f7\u6570

ASCII_Ctr: xor dx,dx
div bx ; \u966410\uff0c\u53d6\u5546\u6570\u548c\u4f59\u6570
xchg ax,dx ;\u4ea4\u6362\u5546\u6570\u548c\u4f59\u6570
or al,30h ;\u8f6c\u6362\u6210ASCII\u7801
stosb ;\u4fdd\u5b58ASCII\u7801
mov ax,dx ;\u628a\u5546\u6570\u653e\u5165ax\u4e2d
cmp ax,0
ja ASCII_Ctr ;\u5546\u6570\u5927\u4e8e0\uff0c\u7ee7\u7eed\u53d6\u4f59\u6570

lea dx,ASCII ;\u5b57\u7b26\u4e32\u9996\u5730\u5740
mov ah,9 ; \u663e\u793a\u7ed3\u679c
int 21h

Exit_Proc: mov ax,4c00h ;\u7ed3\u675f\u7a0b\u5e8f
int 21h

Dec_ASCII ENDS
END Start

code segment assume cs:code org 100hstart: push cs pop ds push cs pop es mov ah,1 int 21h push ax mov ah,2 mov dl,13 int 21h mov dl,10 int 21h pop ax call dispnum mov ah,4ch int 21h dispnum proc near push ax push bx push cx push dx push si push di push bp pushf ; \u5c06\u8981\u663e\u793a\u7684\u6570\u636e\u653e\u5165AL\u4e2d mov ah,0 mov cl,10 div cl mov byte ptr[@@y+4],ah ;\u4fdd\u5b58\u4e2a\u4f4d add byte ptr[@@y+4],30h ;\u4e2a\u4f4d\u8f6cASC2 mov ah,0 div cl mov byte ptr[@@y+3],ah ;\u4fdd\u5b58\u5341\u4f4d add byte ptr[@@y+3],30h ;\u5341\u4f4d\u8f6cASC2 mov ah,0 mov byte ptr[@@y+2],al ;\u4fdd\u5b58\u767e\u4f4d add byte ptr[@@y+2],30h ;\u767e\u4f4d\u8f6cASC2 mov ah,9 lea dx,@@y int 21h popf pop bp pop di pop si pop dx pop cx pop bx pop ax ret@@y db 10,13,0,0,0,'$'dispnum endpcode ends end start

用键盘输入字符(包括数字),显示其 ASCII 码。

程序,以及运行截图如下:



;输入A
;输出0041H(十六进制的ASCII)
;核心代码是向十六进制转换的子程序
;另外此程序还具有通用性,不仅可以输出A-Z的ASCII,针对其它可输入字符也可以输出其ASCII

data segment
str1 db 'INPUT:$'
str2 db 'ASCII(16):$'
data ends

code segment
assume cs:code,ds:data
main proc far
start:
mov ax,data
mov ds,ax
;输出提示信息"INPUT:"
lea dx,str1
mov ah,09h
int 21h

mov ah,01h
int 21h;接收字符,存于AL中
cbw;8位扩展为16位
mov bx,ax;将字符的ASCII存入BX
call crlf;回车换行子程序
;输出提示信息"ASCII(16):"
lea dx,str2
mov ah,09h
int 21h
call transform;转换子程序

;输出十六进制的标志H
mov dl,'H'
mov ah,02h
int 21h

mov ah,4ch
int 21h
ret
main endp

transform proc near
;若想很好的理解此子程序,只需实例代入程序,步步分析即可
;如将BX取值为A
mov ch,4
rotate: mov cl,4
rol bx,cl
mov al,bl
and al,0fh
add al,30h
cmp al,3ah
jl printit
add al,7h
printit:mov dl,al
mov ah,02h
int 21h
dec ch
jnz rotate
ret
transform endp

crlf proc near;回车换行子程序
mov dl,0ah
mov ah,02h
int 21h
mov dl,0dh
mov ah,02h
int 21h
ret
crlf endp
code ends
end start

扩展阅读:宫颈asch是几级病变 ... 汉字转ascii码 在线 ... 标准ascii码表图 ... ascii码与bcd码的转换表 ... ascii码对照表 ... 16进制ascii码表图 ... ascii码在线转换器 ... ascii码表 全 完整版 ... bcd码怎样转ascii码 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网