0% found this document useful (0 votes)
6 views2 pages

Tinh Binh Phuong

This assembly language program prompts the user to input a single digit number (N) between 0 and 9. If the input is valid, it calculates the square of N and displays the result. If the input is invalid, it prompts the user to enter the number again.

Uploaded by

22a1701d0120
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)
6 views2 pages

Tinh Binh Phuong

This assembly language program prompts the user to input a single digit number (N) between 0 and 9. If the input is valid, it calculates the square of N and displays the result. If the input is invalid, it prompts the user to enter the number again.

Uploaded by

22a1701d0120
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/ 2

.

model small
.stack 100
.data
; khai bao bien, chuoi
nhap_msg db 'Nhap N:$'
nhap_sai_msg db 'Nhap sai!$'
ket_qua_msg db 'Ket qua:$'
.code
main proc
; khoi tao cho DS
mov ax, @data
mov ds, ax

nhap_n:
; in ra thong bao nhap N
lea dx, nhap_msg
mov ah, 9
int 21h

; doc 1 ky tu tu ban phim


mov ah, 1
int 21h
; sau lenh nay: al = ma ASCII vua nhap

; chuyen so dang ASCII sang so


sub al, '0'

; kiem tra dieu kien 0 <= N <= 9


; kiem tra N >= 0?
cmp al, 0
jl nhap_sai
; kiem tra N <= 9
cmp al, 9
jg nhap_sai
; den day thi nhap dung
jmp xu_ly

nhap_sai:
; xu ly nhap sai
; in ra chuoi nhap sai
lea dx, nhap_sai_msg
mov ah, 9
int 21h
jmp nhap_n

xu_ly:
; xu ly yeu cau bai toan
mul al ; sau cau lenh nay: AX = N*N

; in ket qua AX ra man hinh


mov bl, 10
mov cx, 0
tiep_tuc_chia:
div bl ; lay ax / bl -> ket qua: al = thuong, ah = du
push ax
inc cx ; <=> add cx, 1
mov ah, 0
cmp al, 0
je xuat
jmp tiep_tuc_chia

xuat:
lea dx, ket_qua_msg
mov ah, 9
int 21h

in_tung_ky_tu:
pop ax
mov dl, ah
add dl, '0'
mov ah, 2
int 21h
;loop in_tung_ky_tu
dec cx
jne in_tung_ky_tu

; tro ve DOS
mov ah, 4ch
int 21h
main endp
end main

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy