Program:
.model small
.stack 200H
.data
msg1 DB 10,13,'Enter the limit: $'
msg2 DB 10,13,'Enter no.s: $'
msg3 DB 10,13,'The largest is:$'
newline DB 10,13,' $'
large DW ?
.code
print MACRO msg
PUSH AX
PUSH DX
MOV AH,09H
MOV DX,offset msg
INT 21H
POP DX
POP AX
ENDM
.startup
print msg1
CALL readnumtoAX
mov cx,ax
print newline
print msg2
print newline
CALL readnumtoAX
MOV large,AX
DEC CX
bac:
print newline
CALL readnumtoAX
CMP AX,large
JBE skip1
mov large,ax
skip1:
loop bac
print msg3
mov ax,large
print newline
CALL displayAX
.exit
;Store num to AX procedure definition
readnumtoAX PROC NEAR
PUSH BX
PUSH CX
MOV CX,10
MOV BX,00
back: MOV AH,01H
INT 21H
CMP AL,'0'
JB skip
CMP AL,'9'
JA skip
SUB AL,'0'
PUSH AX
MOV AX,BX
MUL CX
MOV BX,AX
POP AX
MOV AH,00
ADD BX,AX
JMP back
skip:
MOV AX,BX
POP CX
POP BX
RET
readnumtoAX ENDP
;Display procedure
displayAX PROC NEAR
PUSH DX
PUSH CX
PUSH BX
PUSH AX
MOV CX,0
MOV BX,10
back1: MOV DX,0
DIV BX
PUSH DX
INC CX
OR AX,AX
JNZ back1
back2:
POP DX
ADD DL,30H
MOV AH,02H
INT 21H
LOOP back2
POP AX
POP BX
POP CX
POP DX
RET
displayAX ENDP
END
Output:
Enter the limit: 4
Enter no.s: 4
6
8
9
The largest is:
9
.model small
.stack 200H
.data
msg1 DB 10,13,'Enter the limit: $'
msg2 DB 10,13,'Enter no.s: $'
msg3 DB 10,13,'The largest is:$'
newline DB 10,13,' $'
large DW ?
.code
print MACRO msg
PUSH AX
PUSH DX
MOV AH,09H
MOV DX,offset msg
INT 21H
POP DX
POP AX
ENDM
.startup
print msg1
CALL readnumtoAX
mov cx,ax
print newline
print msg2
print newline
CALL readnumtoAX
MOV large,AX
DEC CX
bac:
print newline
CALL readnumtoAX
CMP AX,large
JBE skip1
mov large,ax
skip1:
loop bac
print msg3
mov ax,large
print newline
CALL displayAX
.exit
;Store num to AX procedure definition
readnumtoAX PROC NEAR
PUSH BX
PUSH CX
MOV CX,10
MOV BX,00
back: MOV AH,01H
INT 21H
CMP AL,'0'
JB skip
CMP AL,'9'
JA skip
SUB AL,'0'
PUSH AX
MOV AX,BX
MUL CX
MOV BX,AX
POP AX
MOV AH,00
ADD BX,AX
JMP back
skip:
MOV AX,BX
POP CX
POP BX
RET
readnumtoAX ENDP
;Display procedure
displayAX PROC NEAR
PUSH DX
PUSH CX
PUSH BX
PUSH AX
MOV CX,0
MOV BX,10
back1: MOV DX,0
DIV BX
PUSH DX
INC CX
OR AX,AX
JNZ back1
back2:
POP DX
ADD DL,30H
MOV AH,02H
INT 21H
LOOP back2
POP AX
POP BX
POP CX
POP DX
RET
displayAX ENDP
END
Output:
Enter the limit: 4
Enter no.s: 4
6
8
9
The largest is:
9
0 comments:
Post a Comment