给定一个数,求该数的补数
程序运行:
代码:
datas segmentNUM DB 12H,34H,56H,78H,9AH,0BCH,23H,45HDB 67H,89H,0DEH,13H,24H,35H,46H,57HN DB $-NUMoutputNUM db "orignal data NUM=$"outputNUMC db 0dh,0ah,"NUM's complement=$"
datas endsstacks segment stackdb 100h dup(?)stacks endscodes segmentassume cs:codes,ds:datas,ss:stacks
main proc far
start:push dsmov ax,0hpush axmov ax,datas ;初始化dsmov ds,ax;输出原始的NUMlea dx,outputNUMmov ah,9int 21h mov bl,Nxor bh,bhdec bx os:mov al,NUM[bx]call hexidemicaldec bx cmp bx,0 jge osmov dl,'H'mov ah,2int 21h;求补mov cl,N ;将NUM的字节数移至cxxor ch,ch cmp cx,0 ;判断字节数是否为0jz no_operate ;若为0,跳转lea bx,NUM ;取NUM的偏移地址mov ah,0 ;ah清零s:xor al,al ;al设置0sahf ;恢复上一次减法的标志位sbb al,[bx] ;带位减法,求补lahf ;保存标志位mov [bx],al ;求补的值保存在原始的位置inc bx ;移至下一个单元loop s ;输出求补的NUMlea dx,outputNUMCmov ah,9int 21hmov bl,Nxor bh,bhdec bx s1:mov al,NUM[bx]call hexidemicaldec bx cmp bx,0 jge s1mov dl,'H'mov ah,2int 21hno_operate:retmain endphexidemical proc near push axpush cx push bx xor ah,ah mov bl,16div blmov cx,axmov dl,clcmp dl,10jb nextadd dl,7 next:add dl,30h mov ah,2int 21h mov dl,chcmp dl,10jb next1add dl,7 next1:add dl,30h int 21hpop bxpop cx pop ax rethexidemical endpcodes endsend main