Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

joyWorld University Of Bangladesh

Name : Joy Mondal

Roll : 3343 , Batch : 53A

Subject : Microprocessor & Assembly Language Lab

Topic : Print 1 to 10 in ascending order in assembly code.


joyPrint 1 to 10 in ascending order in assembly code.

How to Done it :

 Changed the type of NUM, from DB to DW (required by number2string, it would hold


bigger numbers).

Added variable numstr, which is NUM converted into string.

Added variable lbk (just a line break after each number).

Added proc number2string, to convert a number in AX to the string pointed by SI (this is


the most important).

Added proc dollars, to fill numstr with dollar signs (necessary to display, and to clear the
string before converting the next number).

Comment :

1. LINE BREAK.

2. STRING FOR 2 DIGITS.

3. Starting Number . (1)

4. IF NUM <= 10

5. we know 10 is not single carecter digit .that couse i convert number to string.

6. Display String

7. On this code Using For print string

8. NUM++.
joy
My Code :

My Code Link Github : CODE OR


ascending-order-in-assembly-code

.MODEL SMALL

.STACK 100H

.DATA

NUM DW ?
https://github.com/codewithjoymondal/Print-1-to-10-in-

Or

;Here i use Comment 1,2,3,4.....n.And Discussion Assignment Section.

; Comment no 1

lbk db 13,10,'$'

; Comment no 2

numstr db '$$'
joy .CODE

MAIN PROC

MOV AX,@DATA

MOV DS,AX

;Comment no 3

MOV NUM, 1

START:

;Comment no 4

CMP NUM, 10

JBE PRINT

JMP close

PRINT:

; MOV AH,2
joy
;

;
MOV DL,NUM

INT 21H

; Comment no 5

mov si, offset numstr

mov ax, num

call number2string

;Comment no 6

mov ah, 9

mov dx, offset numstr

int 21h

;Comment no 7

mov ah, 9

mov dx, offset lbk

int 21h
joy
;Comment no 7

INC NUM

JMP START

close:

MOV Ax,4C00H

int 21h

MAIN ENDP

number2string proc

call dollars

mov bx, 10

mov cx, 0

joymondal1:

mov dx, 0

div bx
joy
push dx

inc cx

cmp ax, 0

jne joymondal1

joymondal2:

pop dx

add dl, 48

mov [ si ], dl

inc si

loop joymondal2

ret

number2string endp

proc dollars

mov cx, 5
joy
mov di, offset numstr

dollars_sign:

mov bl, '$'

mov [ di ], bl

inc di

loop dollars_sign

ret

endp

END MAIN
joy
OutPut
joy

You might also like