admin 管理员组

文章数量: 1184232


2024年12月22日发(作者:matlab中text函数用法)

;十六-十进制转换

;程序设计的要求:通过键盘给一个四位的16进制数,程序把它转换成10进制数,并显示出

来。

;

;把输入的4位16进制数以10十进制的值存放到变量num中,注意num可能会有5位数。所

以下面

;就通过÷,%(10000,1000,100,10)来得到每一位数,即十进制数.

CSEG SEGMENT

mov num, 0

mov cx, 4 ;输入4位16进制数(这里没有处理少于或多于4位的情况)

assume cs:CSEG, ds:DSEG, ss:SSEG

MAIN PROC FAR ;主程序入口

L1: mov ah, 01h

int 21h

push cx

mov cl, 4

shl num, cl ;输入的数以10进制的形式存到num中

pop cx

cmp al, 3ah

jb s1

sub al, 07h

s1: sub al, 30h

mov ah, 0

add num, ax

mov bx, num

loop L1

;******************************************************************************;

输入空格以结束。

mov ah, 01h

int 21h

mov ah, 02h

mov dl, '('

int 21h

mov dl, '1'

int 21h

mov dl, '6'

int 21h

mov dl, ')'

int 21h

mov dl, ' '

int 21h0

;******************************************************************************;

call fun ;调用主函数

;******************************************************************************;

mov ah, 02h

mov dl, '('

int 21h

mov dl, '1'

int 21h

mov dl, '0'

int 21h

mov dl, ')'

int 21h

call change

;******************************************************************************;

call exit ;退出

;******************************************************************************;

MAIN ENDP

fun proc

mov cx, 10000d ;把除数存放到cx中

call dec_div

mov cx, 1000d

call dec_div

mov cx, 100d

call dec_div

mov cx, 10d

call dec_div

mov cx, 1d

call dec_div

ret

;除法实现,除数为cx的值

fun endp

dec_div proc

mov ax, bx

mov dx, 0

div cx

mov bx, dx

mov dl, al

add dl, 30h

mov ah, 02h

int 21h

ret

dec_div endp

;*******************************************************************************

******************

;下面代码仅供测试使用

printb proc

push ax

mov dl, al

mov ah, 02h

int 21h

pop ax

ret

printb endp

printw proc

push ax

push bx

push cx

MOV cx,4

a7: mov di, bx

PUSH cx

MOV cl,4

ROL di,cl

mov bx, di

MOV dl,bl

AND dl,0fh

ADD dl,30h

CMP dl,3ah

JB a8

ADD dl,7

a8: MOV ah,2

INT 21h

POP cx

LOOP a7

pop cx

pop bx

pop ax

ret

printw endp

;*******************************************************************************

******************

;*******************************************************************************

******************

;回车换行

change proc

push ax

mov ah, 02h

mov dl, 0ah

int 21h

mov ah, 02h

mov dl, 0dh

int 21h

pop ax

ret

change endp

;*******************************************************************************

******************

;*******************************************************************************

******************

;退出

exit

proc

;按任意键退出

mov ah,1

int 21h

mov ax, 4c00h ;程序结束,返回到操作系统

int 21h

endp exit

;*******************************************************************************

******************

CSEG ENDS

SSEG SEGMENT PARA STACK 'stack'

dw 100h dup(0) ;初始化堆栈大小为100

SSEG ENDS

DSEG SEGMENT

END MAIN

;数据段:在此处添加程序所需的数据

num dw ?

arr dw 10 dup(?)

DSEG ENDS


本文标签: 进制 要求 函数 结束 除数