按下列要求编程:
(1)从键盘输入两个四位十六进制数。
(2)将这两个数以二进制形式输出,要求输出的0 和1 颜色交替变化。
(3)找出这两个数中的偶数,若有则以十进制输出,若无,输出“NO”。
(4)计算这两个数的平方和。
(5)数据的输入和结果的输出都要有必要的提示,且提示独占一行。
(6)要使用到子程序。
------解决方案--------------------
- Assembly code
data segment stri db 'input a number :',0ah,0dh,'$' max db 5 actlen db ? string db 5 dup(?) num dw 2 dup(?) data ends stack segment dw 256h dup(0) stack ends code segment assume ds:data,ss:stack,cs:code start: mov ax,data mov ds,ax call input mov ax,num mov num+2,ax mov dl,0ah ;换行 mov ah,2 int 21h call input mov ah,4ch int 21h input proc near ;输入一个四位十六进制数,0~F之间的四个字符 push dx push ax push si push cx push bx mov dx,offset stri ;显示字符串 mov ah,9h int 21h lea dx,max mov ah,0ah int 21h ;调用DOS中断输入一个四位十六进制 lea si,string ;取字符串首址 mov cx,4 xor dx,dx get: push cx mov al,[si] ;取一个字符 cmp al,'0' jb return cmp al,'F' ;检查输入的字符是否在0~F之间 ja return ;否,返回 cmp al,'9' ;转换为对应的数字 jle deci sub al,07h deci: sub al,30h cbw or dx,ax mov bx,dx and bx,0f000h jnz nos mov cl,4 shl dx,cl nos: inc si pop cx loop get return: mov num ,dx ;保存结果 pop bx pop cx pop si pop ax pop dx ret input endp code ends end start