0% found this document useful (0 votes)
7 views3 pages

Code Tru 4 Chu So

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Code Tru 4 Chu So

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

.

model small
.stack 100h
.data
msg1 db "Moi ban nhap so 1 (4 chu so): $"
msg2 db "Moi ban nhap so 2 (4 chu so): $"
msg3 db "Ket qua la: $"

NUM1 dw ?
NUM2 dw ?
RESULT dw ?

.code
start:

mov ax,@data
mov ds,ax

; --- Nhap so 1 ---


mov ah,9
lea dx,msg1
int 21h

xor ax,ax
mov NUM1,ax
mov cx,4
nhap1_loop:
mov ah,1
int 21h
sub al,'0'
mov bl,al
mov ax,NUM1
mov dx,10
mul dx
add ax,bx
mov NUM1,ax
loop nhap1_loop

; --- Xuong dong sau khi nhap so 1 ---


mov dl,13
mov ah,02h
int 21h
mov dl,10
int 21h

; --- Nhap so 2 ---


mov ah,9
lea dx,msg2
int 21h

xor ax,ax
mov NUM2,ax
mov cx,4
nhap2_loop:
mov ah,1
int 21h
sub al,'0'
mov bl,al
mov ax,NUM2
mov dx,10
mul dx
add ax,bx
mov NUM2,ax
loop nhap2_loop

; --- Xuong dong sau khi nhap so 2 ---


mov dl,13
mov ah,02h
int 21h
mov dl,10
int 21h

; --- Tinh hieu ---


mov ax,NUM1
sub ax,NUM2
mov RESULT,ax

; --- Hien thi ket qua ---


mov ah,9
lea dx,msg3
int 21h

mov ax,RESULT
call print_num

; --- Dung man hinh ---


mov ah,0
int 16h

; --- Thoat ---


mov ah,4Ch
int 21h

; --- Ham in so tu AX ra man hinh ---


print_num proc
push ax
push bx
push cx
push dx

mov bx,10
xor cx,cx

convert_loop:
xor dx,dx
div bx
push dx
inc cx
cmp ax,0
jne convert_loop

print_loop:
pop dx
add dl,'0'
mov ah,02h
int 21h
loop print_loop

pop dx
pop cx
pop bx
pop ax
ret
print_num endp

end start

You might also like