TASM Program to subtract Two 16 Bit Numbers

On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.     
TASM Program :
Data Segment
 msg db 0dh,0ah,"Enter a 16-bit number: $"
 result db 0dh,0ah,"The Result is: $"
 newl db 0dh,0ah," $"
Data ends
Code Segment
assume CS:Code,DS:Data
Start:
 mov ax,Data
 mov DS,ax
 
 mov dx,offset msg;sub16
 mov ah,09h
 int 21h
 
 call AcceptNum
 mov bh,bl
 
 call AcceptNum
 mov cx,bx

 mov dx,offset msg
 mov ah,09h
 int 21h
 
 call AcceptNum
 mov bh,bl
 
 call AcceptNum

 sub cx,bx

 mov dx,offset result
 mov ah,09h
 int 21h
 
 mov bl,ch
 call DispNum

 mov bl,cl
 call DispNum

 mov ah,4ch
 int 21h
AcceptNum proc
 mov ah,01h
 int 21h
 
 call HexAccept
 
 mov bl,al
 rol bl,4
 
 mov ah,01h
 int 21h
 
 call HexAccept
 add bl,al
 ret
endp
DispNum proc
 mov al,bl
 and al,0f0h
 ror al,4

 mov dl,al
 call HexDisp
 mov ah,02h
 int 21h

 mov al,bl
 and al,0fh
 
 mov dl,al
 call HexDisp
 mov ah,02h
 int 21h
endp
HexAccept proc
 cmp al,41h
 jc norm
 sub al,07h
 norm: sub al,30h
 ret
endp
HexDisp proc
 cmp dl,0ah
 jc nothex
 add dl,07h
 nothex: add dl,30h
 ret
endp
Code ends
end Start
output:-
C:\TASM\BIN>tasm sub16.asm
Turbo Assembler  Version 4.1  Copyright (c) 1988, 1996 Borland International

Assembling file:   sub16.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  453k

C:\TASM\BIN>tlink sub16.obj
Turbo Link  Version 7.1.30.1. Copyright (c) 1987, 1996 Borland International
Warning: No stack

C:\TASM\BIN>sub16

Enter a 16-bit number: 1312
Enter a 16-bit number: 1205
The Result is: 010D
--------------------------------

0 comments: