print macro msg
lea dx,msg
mov ah,09h
int 21h
endm
read macro n,j1,j2,error
mov cx,08h
j1:mov ah,01h
int 21h
cmp al,0dh
je j2
cmp al,2fh
jc error
cmp al,32h
jnc error
sub al,30h
mov dl,n
xor dh,dh
rcl dx,01
add dl,al
mov n,dl
loop j1
jmp j2
error:mov cl,01h
mov er,cl
j2 :nop
endm
.model small
.stack 100h
.data
msg1 db 10,13,'Enter the number in binary: $'
msg2 db 10,13,'The Number= $'
msg3 db 10,13,'2s compliment= $'
err db 10,13,'Error$'
num1 db 0
er db 0
.code
main proc
mov ax,@data
mov ds,ax
print msg1
;reading 1st multidigit number
read num1,jump1,jump2,errr
mov al,er
cmp al,01h
jne jup
print err
jmp stop
;printing input no in binary
jup:print msg2
mov bl,num1
call binary
;finding 2s compliment
mov bl,num1
xor bl,0ffh
inc bl
;printing 2s compliment in binary
print msg3
call binary
stop:mov ah,4ch
int 21h
main endp
binary proc
mov cx,08h
loop1:rcl bl,01
jc one
mov dl,30h
jmp jump3
one:mov dl,31h
jump3:mov ah,02h
int 21h
loop loop1
ret
binary endp
end
No comments:
Post a Comment