⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dectohex.asm

📁 计算二位无符号数平方的程序,将用户从键盘输入的十进制数转换成为十六进制数并显示。对键盘输入的两个字符串进行比较
💻 ASM
字号:
; program convert an integer which is less then 65536 into a hexadecimal number


.model small
.code
.386

start:
		  mov ax, @data
		  mov ds, ax
		  mov es, ax
		  lea dx, prompt
		  mov ah, 09h ; output prompt
		  int 21h
		  lea dx, buff ; input integer
		  mov si, dx
		  mov ah, 0ah
		  int 21h
		  inc si
		  mov cx, [si]
		  and cx, 00ffh
		  jcxz ecall ; exit program is input nothing
		  inc si
		  cld

check: ; check input characters
		  lodsb
		  cmp al, 30h
		  jae next
ecall:call printerror
next: cmp al, 39h
		  jbe next2
		  call printerror
next2:loop check
; end check
		  		  		  		  
		  call dtoh
		  call print
		  
		  mov ah, 4ch
		  int 21h
		  		  
printerror proc ; print error msg and exit the program
		  lea dx, error
		  mov ah, 09h
		  int 21h
		  mov ah, 4ch
		  int 21h
printerror endp

print proc
		  lea dx, result
		  mov ah, 09h
		  int 21h
		  lea dx, hex
		  mov ah, 09h
		  int 21h
		  ret
print endp
; end of procedure print

dtoh proc ; procedure convert decimal ascii string into hexadecimal ascii string
		  xor ax, ax ; ax stores the converted integer
		  mov si, dx ; effective address of buff
		  inc si
		  xor cx, cx
		  mov cl, [si]
		  inc si
		  mov bx, 10
atoi: ; convert ascii to integer		  
		  mul bx
		  mov bl, [si]
		  sub bl, 30h
		  movzx bx, bl
		  add ax, bx
		  inc si
		  mov bx, 10
		  loop atoi
		  
; convert decimal to hexadecimal ascii string
		  mov cx, ax
		  lea di, hex
		  lea bx, table
		  shr ax, 12
		  xlat
		  stosb
		  mov ax, cx
		  shr ax, 8
		  and al, 0fh
		  xlat
		  stosb
		  mov ax, cx
		  shr al, 4
		  xlat
		  stosb
		  and cx, 0fh
		  mov al, cl
		  xlat
		  stosb
		  ret
dtoh endp

.data
		  prompt db 'Enter a decimal number:$'
		  result db 0dh, 0ah, 'The converted hexadecimal number is $'
		  error db 0dh, 0ah, 'Input error!', 0dh, 0ah, '$'
		  buff db 6, ?, 6 dup(?)
		  table db 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70
		  hex db '0000H$'
.stack
end start

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -