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

Nguyen Dinh Tan Homework 7

The document describes an assembly language program that takes a 5 digit number as input from the user and prints it out. It uses division and modulo operations to separate each digit and push it onto the stack before popping and printing them.

Uploaded by

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

Nguyen Dinh Tan Homework 7

The document describes an assembly language program that takes a 5 digit number as input from the user and prints it out. It uses division and modulo operations to separate each digit and push it onto the stack before popping and printing them.

Uploaded by

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

.

model small

.stack 100h

.data
msg db 'Nhap vao 1 day ky tu, ket thuc bang ENTER: $'
msg_1 db 'Here is your number: $'

.code
Main Proc
mov ax, @data
mov ds, ax
mov ah, 09h ; Print msg
lea dx, msg
int 21h

mov si, 0
INSERT:
mov ah, 01h; Prepare to insert
int 21h
xor ah, ah

; Only between 0 - 9
cmp al, 13
je PRINT
cmp al, '0'
jb INSERT
cmp al, '9'
ja INSERT

CONVERT:
sub al, 48
mov dl, al
xor ah, ah

add bx, ax
cmp si, 4
je HERE
cmp bx, 6553
ja CONVERT_1

; Multiply by 10
mov ax, bx
mov cx, 10
mul cx
mov bx, ax

xor ax, ax
xor cx, cx

cmp bx, 65530


je INSERT_AND_ADD

HERE:
inc si
cmp si, 5
jne INSERT
jmp CONVERT_1
INSERT_AND_ADD:
mov ah, 01h; Prepare to insert
int 21h
xor ah, ah

cmp al, 13
je PRINT
cmp al, '0'
jb INSERT_AND_ADD
cmp al, '5'
ja INSERT_AND_ADD

sub al, 48
add bx, ax
jmp CONVERT_1

PRINT:
mov ax, bx
mov cx, 10
div cx
mov bx, ax

CONVERT_1:
; Newline
mov dl, 10
mov ah, 02h
int 21h
mov dl, 13
mov ah, 02h
int 21h

; Print msg_1
mov ah, 09h
lea dx, msg_1
int 21h
xor dx, dx

xor si, si
mov ax, bx
; Push into stack
REPEAT:
xor dx, dx
mov cx, 10
div cx
push dx
inc si
cmp ax, 0h
ja REPEAT

; Pop from stack


REPEAT_1:
xor dx, dx
pop dx
add dx, 48
mov ah, 2h
int 21h
dec si
cmp si, 0
ja REPEAT_1

mov ah, 4ch


int 21h
Main Endp

You might also like