Assembly Language
Expert Answer
- View comments (2)
Good day!
Code:
org 100h
.DATAPROMPT DB "Please enter three integers: $"
OUT1 DB " is the maximum numer!$"
NL DB 13,10,"$"
.CODE
MOV AX,@DATA
MOV DS,AX
;DISPLAY PROMPT
MOV DX,OFFSET PROMPT
MOV AH,9
INT 21H
;INITIALIZATION
MOV CX,3 ;LOAD COUNT INTO CX
MOV BH,0 ;BH=0 TO HOLD MAX
MOV AH,1 ;PARAMETER FOR INT 21H
;PROCESSING..
NEXT:INT 21H ;READ NUMBER
MOV BL,AL ;SAVE NUMBER TO BL
CMP BL,BH ;COMPARE NUMBER WITH BH, ASSUMING THAT BH HAS MAX
JLE SKIP ;IF BL IS LESS THAN OR EQUAL TO BH, THEN SKIP
MOV BH,BL ;ELSE BL HAS A BIGGER VALUE AND COPY IT INTO BH
SKIP:LOOP NEXT ;REPEAT TILL CX=0 AND ONCE THE LOOP IS DONE, BH WILL HAVE MAX
;PRINT NEWLINE
MOV DX,OFFSET NL
MOV AH,9
INT 21H
;PRINT MAX VALUE
MOV DL,BH
MOV AH,2
INT 21H
;PRINT THE MESSAGE IS THE MAX VALUE
MOV DX,OFFSET OUT1
MOV AH,9
INT 21H
HLT ;END OF THE PROGRAMret
Screenshot:
Thank you
ليست هناك تعليقات:
إرسال تعليق