- ahmad alhayek

 Flag

Assembly Language
Q1: Write an Assembly Language program that allows the user to enter a 3 numbers and prints the maximum number between them.

Show transcribed image text

Expert Answerinformation icon

  • Jinesh V N's Avatar

    Good day!

    Code:

    org 100h


    .DATA

    PROMPT 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 PROGRAM

    ret

    Screenshot:

    SCR emulator screen (80x25 chars) Please enter three integers: 394 9 is the maximum numer!

    SERI emulator screen (80x25 chars) Please enter three integers: 831 8 is the maximum numer!

    Thank you

    View comments (2) 

ليست هناك تعليقات:

إرسال تعليق

ahmad alhayek تصميم ahmad alhayek جميع الحقوق محفوظة 2016

صور المظاهر بواسطة sndr. يتم التشغيل بواسطة Blogger.