非压缩BCD码转压缩BCD码汇编语言

注:原博客账号密码丢失,故将本科期间的笔记搬运至此

DATAS SEGMENT

    ;此处输入数据段代码

    buf dw 0302h,0908h,0705h,0102h

    res db ?

    buf_size db ?

    res_size db ?  

DATAS ENDS

 

STACKS SEGMENT

    ;此处输入堆栈段代码

STACKS ENDS

 

CODES SEGMENT

    ASSUME CS:CODES,DS:DATAS,SS:STACKS

START:

    MOV AX,DATAS

    MOV DS,AX

    ;此处输入代码段代码

     ;宏 显示一个字符

dispchar macro char

         mov ah,2

         mov dl,char

         int 21h

         endm

    ;宏定义完成

 

    ;宏 显示字符串

dispmsg   macro message

          mov ah,9

          lea dx,message

          int 21h

          endm

    ;宏定义完成

 

    ;宏 显示十六进制数的四位

disphex   macro hexdata

          local disphex1

          push ax

          push bx

          push cx

          push dx

          mov bx,hexdata

          mov cx,0404h

disphex1: rol bx,cl

          mov al,bl

          and al,0fh

          call htoasc

          dispchar al

          dec ch

          jnz disphex1

          pop dx

          pop cx

          pop bx

          pop ax

          endm

    ;宏定义完成

    

   

    mov cx, lengthof buf

    

    lea si,buf

    lea di,res

again:

    mov ax,word ptr [si]

    ;disphex ax

    call bcd

    mov byte ptr [di],al

    inc si

    inc si

    inc di

    loop again  

    

     

    ;显示RES的内容

    lea si, res

    ;disphex [si+4]    

    disphex [si+2]

    disphex [si]

    

    MOV AH,4CH

    INT 21H

    

    ;子程序压缩BCD转非压缩BCD

    BCD proc

        push cx

        mov cl,4

        shl al,cl

        shr ax,cl

        pop cx

        ret

    BCD endp

    

    ;子程序十六进制转ASCII

 HTOASC proc

        push bx

        mov bx,offset ASCII

        and al,0fh

        xlat ASCII

        pop bx

        ret

ASCII db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h

      db 41h,42h,43h,44h,45h,46h

HTOASC  endp    

CODES ENDS

    END START
--------------------- 
作者:D??? 
来源:CSDN 
原文:https://blog.csdn.net/qq_31424383/article/details/53180386 
版权声明:本文为博主原创文章,转载请附上博文链接!
发布了32 篇原创文章 · 获赞 7 · 访问量 7585

猜你喜欢

转载自blog.csdn.net/Isaacddx/article/details/85057453
今日推荐