给定一个数,输出该数的二进制和十进制数
程序运行:
代码:
datas segmentVAL1 dw 156datas endsstacks segment stackdb 100h dup(?)stacks endscodes segmentassume cs:codes,ds:datas,ss:stacks
BANDO proc far
start:push dsmov ax,0hpush axmov ax,datas ;初始化dsmov ds,axpush VAL1call PAIRSretBANDO endpPAIRS proc near mov bp,spadd bp,2mov ax,[bp]call OUTBIN ;输出二进制数call OUTOCT ;输出十进制数ret 2PAIRS endpcodes endscodes1 segmentassume cs:codes1,ds:datas,ss:stacksOUTBIN proc far uses ax bx cxmov bx,2 ;除数mov cx,0 ;计数器,记录数的位数bin:xor dx,dx div bx push dx ;保存余数inc cx cmp ax,0h ;判断被除数是否为0jnz bin ;若不为0,则循环继续bin1:pop dxadd dl,30h mov ah,2 ;输出各位数字 int 21h loop bin1 push ds ;输出8个空格push cs pop ds lea dx,spacemov ah,9int 21h pop ds retspace db ' $'
OUTBIN endpOUTOCT proc far uses ax bx cx dx mov bx,8 ;除数mov cx,0 ;计数器,记录数的位数oct:xor dx,dx div bx push dx ;保存余数inc cx cmp ax,0h ;判断被除数是否为0jnz oct ;若不为0,则循环继续oct1:pop dxadd dl,30h ;输出各位数字 mov ah,2 int 21h loop oct1 ;输出换行call next_line retOUTOCT endpnext_line proc far uses ax dxmov dl,0dhmov ah,2int 21hmov dl,0ahmov ah,2int 21h next_line endp
codes1 endsend BANDO