回 帖 发 新 帖 刷新版面

主题:把在主存中保存的一个32 位二进制数用十六进制的形式在屏!

代码如下..有点混乱,有基本注解,运行时出现错误,会的帮我看下,怎么改下...

prognam segment
    N dw 0a234h, 0b678h, 0ac2dh, 1234h,0a234h, 0b678h, 0ac2dh, 1234h
    endflg dw ?

             assume cs:prognam, DS:prognam
main proc far

     push ds                     ;保存现场     
    sub  ax,ax                    ;
    push ax                        ;
    
    MOV AX,prognam                    ;给DS赋值
    MOV DS,AX                    ;
    
    MOV SI,OFFSET endflag-2    ;将数据的偏移地址置入SI
    MOV DH,8                    ;设置外层循环次数为2,下一次取出的低16位
AGAIN:                            ;外层循环开始标记
    mov bx, [SI]                    ;取得16位的值,保存到Bx寄存器中
    
    mov ch,4                    ;为内层循环准备初始值,共循环4次
    rotate:                        ;内层循环开始标记
        mov cl,4                
        rol bx,CL                ;将BX循环左循环4次
        mov al,bl                ;将bl中的值移入al,便于进行转换成为ASCII
        and al,0fh                ;
        add ax,30h                ;
        cmp al,3ah                ;
        jl printit                ;如果在0~9之间,进行打印
        add al,7h                ;否则,处理为A~f
    printit:    
        mov dl,al                
        mov ah,2                
        int 21h                    ;显示ASCII字符
        
        dec ch                    
        jnz rotate                ;跳转到内层循环标记
    
    SUB SI,2                    ;设置SI为低位字的地址
    DEC DH                        
JNZ AGAIN                        ;跳转到外层循环标记
    ret
main endp
     prognam ends
      end    main

回复列表 (共1个回复)

沙发

给你一个十六位的输出 ,三十二位就是进行复制、粘贴的工作(DX,AX)
data_seg   segment            ;data segment
    DATAX    dw    1CE8H
data_seg   ends

code_seg   segment            ;code segment

main    proc far
        assume cs:code_seg,ds:data_seg    ;set cs to code segment,ds to data segment
start:
        push    ds
        sub     ax,ax
        push    ax

        mov     ax,data_seg        ;store value of data segment to ds
        mov     ds,ax
    
    ;Display the highest 4bit
    mov    ax,DATAX
    and    ah,0F0H            ;clear the low 4 bit of ah
    mov    cl,4
    shr    ah,cl            ;ah shift to right 4
    mov    dl,ah

    cmp    dl,0Ah
    js    dis_num4
    add    dl,37h
    jmp    display4
dis_num4:
    add    dl,30h

display4:
    mov    ah,02
    int    21h

    ;Display the second highest 4bit
    mov    ax,DATAX
    and    ah,0FH            ;clear the high 4 bit of ah
    mov    dl,ah

    cmp    dl,0Ah
    js    dis_num3
    add    dl,37h
    jmp    display3
dis_num3:
    add    dl,30h

display3:
    mov    ah,02
    int    21h

    ;Display the second lowest 4bit
    mov    ax,DATAX
    and    al,0F0H            ;clear the low 4 bit of al
    mov    cl,4
    shr    al,cl            ;al shift to right 4
    mov    dl,al

    cmp    dl,0Ah
    js    dis_num2
    add    dl,37h
    jmp    display2
dis_num2:
    add    dl,30h

display2:
    mov    ah,02
    int    21h

    ;Display the lowest 4bit
    mov    ax,DATAX
    and    al,0FH            ;clear the high 4 bit of ah
    mov    dl,al

    cmp    dl,0Ah
    js    dis_num1
    add    dl,37h
    jmp    display1
dis_num1:
    add    dl,30h

display1:
    mov    ah,02
    int    21h

    mov    ah,07            ;wait a input from keyboard
    int    21h

        ret

main    endp

code_seg   ends

end start

我来回复

您尚未登录,请登录后再回复。点此登录或注册